wasm_peers/lib.rs
1/*!
2This crate provides an easy-to-use wrapper around `WebRTC` and `DataChannels` for a peer to peer connections.
3
4# Overview
5
6As creator of [agar.io](https://agar.io) famously stated [`WebRTC` is hard](https://news.ycombinator.com/item?id=13264952).
7This library aims to help, by abstracting away all the setup, and providing a simple way to send
8and receive messages over the data channel.
9
10It's as easy as providing address to a signaling server instance from
11[accompanying crate](https://docs.rs/wasm-peers-signaling-server/latest/wasm_peers_signaling_server/) and specifying two callbacks.
12One for when a connection opens, and one for when a message is received.
13After that you can send messages back and forth without worrying about the implementation details.
14
15Library contains three network , [one-to-one](one_to_one), which creates an equal connection between two peers,
16[one-to-many](one_to_many), which specifies a host and arbitrary number of clients
17and [many-to-many] that creates connection for each pair of peers and allows sending messages to any of them.
18
19*/
20
21#[deny(missing_docs)]
22#[warn(clippy::pedantic)]
23#[cfg(feature = "many-to-many")]
24pub mod many_to_many;
25#[cfg(feature = "one-to-many")]
26pub mod one_to_many;
27#[cfg(feature = "one-to-one")]
28pub mod one_to_one;
29mod utils;
30
31pub use utils::ConnectionType;
32pub use wasm_peers_protocol::{SessionId, UserId};
33
34/// Returns a new `SessionId` instance that can be used to identify a session by signaling server.
35pub fn get_random_session_id() -> SessionId {
36 SessionId::new(uuid::Uuid::new_v4().to_string())
37}