Skip to content

Commit 305729c

Browse files
committed
docs
1 parent 317abb8 commit 305729c

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

webrtc/src/lib.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,43 @@
4141
//! This includes the set of ICE servers to use, the ICE transport policy, the bundle policy,
4242
//! the RTCP mux policy, the peer identity, and the set of certificates to use.
4343
//!
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
4545
//! once constructed.
4646
//!
4747
//! ### RTCPeerConnection
4848
//!
4949
//! The [`RTCPeerConnection`] is the primary entry point to the WebRTC API. It represents an
5050
//! individual connection between a local device and a remote peer.
5151
//!
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+
//!
5281
//! ### MediaStream
5382
//!
5483
//! ### DataChannel

0 commit comments

Comments
 (0)