|
41 | 41 | //! This includes the set of ICE servers to use, the ICE transport policy, the bundle policy,
|
42 | 42 | //! the RTCP mux policy, the peer identity, and the set of certificates to use.
|
43 | 43 | //!
|
44 |
| -//! Configurations may be reused across multiple connections, and are treated as read-only |
| 44 | +//! Configurations may be reused across multiple [`RTCPeerConnection`]s, and are treated as read-only |
45 | 45 | //! once constructed.
|
46 | 46 | //!
|
47 | 47 | //! ### RTCPeerConnection
|
48 | 48 | //!
|
49 | 49 | //! The [`RTCPeerConnection`] is the primary entry point to the WebRTC API. It represents an
|
50 | 50 | //! individual connection between a local device and a remote peer.
|
51 | 51 | //!
|
| 52 | +//! #### State Machine |
| 53 | +//! |
| 54 | +//! Each [`RTCPeerConnection`] tracks four distinct states as part of its state machine: |
| 55 | +//! |
| 56 | +//! | State Machine | Getter Method | Event Handler Method | Enum | |
| 57 | +//! | ------------- | ------------- | -------------------- | ---- | |
| 58 | +//! | Signaling state | [`signaling_state()`](crate::peer_connection::RTCPeerConnection::signaling_state) | [`on_signaling_state_change()`](crate::peer_connection::RTCPeerConnection::on_signaling_state_change) | [`RTCSignalingState`](crate::peer_connection::signaling_state::RTCSignalingState) | |
| 59 | +//! | ICE connection state | [`ice_connection_state()`](crate::peer_connection::RTCPeerConnection::ice_connection_state) | [`on_ice_connection_state_change()`](crate::peer_connection::RTCPeerConnection::on_ice_connection_state_change) | [`RTCIceConnectionState`](crate::ice_transport::ice_connection_state::RTCIceConnectionState) | |
| 60 | +//! | ICE gathering state | [`ice_gathering_state()`](crate::peer_connection::RTCPeerConnection::ice_gathering_state) | [`on_ice_gathering_state_change()`](crate::peer_connection::RTCPeerConnection::on_ice_gathering_state_change) | [`RTCIceGatheringState`](crate::ice_transport::ice_gathering_state::RTCIceGatheringState) | |
| 61 | +//! | Peer connection state | [`connection_state()`](crate::peer_connection::RTCPeerConnection::connection_state) !! | [`on_peer_connection_state_change()`](crate::peer_connection::RTCPeerConnection::on_peer_connection_state_change) | [`RTCPeerConnectionState`](crate::peer_connection::peer_connection_state::RTCPeerConnectionState) | |
| 62 | +//! |
| 63 | +//! You can define event handlers for each of these states using the corresponding `on_*` methods, |
| 64 | +//! passing a FnMut closure that accepts the corresponding enum type and returns a |
| 65 | +//! `Pin<Box<dyn Future<Output = ()> + Send + 'static>` future to be awaited. |
| 66 | +//! |
| 67 | +//! #### Sync vs. Async |
| 68 | +//! |
| 69 | +//! For clarity, the event handler methods run synchronously and accept a (synchronous) closure |
| 70 | +//! that returns a future. Any async work that you need to do as part of an event handler should |
| 71 | +//! be placed in the future that is returned by the closure, as the returned future will be |
| 72 | +//! immediately awaited. |
| 73 | +//! |
| 74 | +//! In fact, all of the event handler methods within this crate are structured in this way. |
| 75 | +//! While it may feel odd to be forced into returning a future from a synchronous method, |
| 76 | +//! it allows for a mix of synchronous and asynchronous work to be done within the handler, |
| 77 | +//! depending on your specific use case. |
| 78 | +//! |
| 79 | +//! **This will be a common source of confusion for new users of the crate.** |
| 80 | +//! |
52 | 81 | //! ### MediaStream
|
53 | 82 | //!
|
54 | 83 | //! ### DataChannel
|
|
0 commit comments