1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//! WebRTC connection state types.
//!
//! This module provides enums representing the various states of a WebRTC peer
//! connection, including ICE connectivity, candidate gathering, overall connection
//! status, and SDP signaling progress.
//!
//! # Overview
//!
//! WebRTC connections have multiple independent state machines that track different
//! aspects of the connection lifecycle:
//!
//! - **[`RTCIceConnectionState`]** - ICE transport connectivity (new, checking, connected, etc.)
//! - **[`RTCIceGatheringState`]** - ICE candidate gathering progress (new, gathering, complete)
//! - **[`RTCPeerConnectionState`]** - Overall connection state (new, connecting, connected, etc.)
//! - **[`RTCSignalingState`]** - SDP offer/answer negotiation progress (stable, have-local-offer, etc.)
//!
//! # State Monitoring Pattern
//!
//! In this sans-I/O library, states are monitored by polling events and checking
//! state transitions rather than registering callbacks.
//!
//! # Examples
//!
//! ## Monitoring ICE Connection State
//!
//! ```no_run
//! use rtc::peer_connection::state::RTCIceConnectionState;
//! use rtc::peer_connection::event::RTCPeerConnectionEvent;
//!
//! # fn example(event: RTCPeerConnectionEvent) {
//! // Handle ICE connection state change event
//! match event {
//! RTCPeerConnectionEvent::OnIceConnectionStateChangeEvent(state) => {
//! match state {
//! RTCIceConnectionState::New => println!("ICE starting"),
//! RTCIceConnectionState::Checking => println!("ICE checking connectivity"),
//! RTCIceConnectionState::Connected => println!("ICE connected!"),
//! RTCIceConnectionState::Completed => println!("ICE completed"),
//! RTCIceConnectionState::Disconnected => println!("ICE disconnected"),
//! RTCIceConnectionState::Failed => println!("ICE failed"),
//! RTCIceConnectionState::Closed => println!("ICE closed"),
//! _ => {}
//! }
//! }
//! _ => {}
//! }
//! # }
//! ```
//!
//! ## Monitoring Candidate Gathering
//!
//! ```no_run
//! use rtc::peer_connection::state::RTCIceGatheringState;
//! use rtc::peer_connection::event::RTCPeerConnectionEvent;
//!
//! # fn example(event: RTCPeerConnectionEvent) {
//! match event {
//! RTCPeerConnectionEvent::OnIceGatheringStateChangeEvent(state) => {
//! match state {
//! RTCIceGatheringState::New => println!("Gathering not started"),
//! RTCIceGatheringState::Gathering => println!("Gathering candidates..."),
//! RTCIceGatheringState::Complete => {
//! println!("All candidates gathered - ready to send offer/answer");
//! }
//! _ => {}
//! }
//! }
//! _ => {}
//! }
//! # }
//! ```
//!
//! ## Checking Overall Connection State
//!
//! ```no_run
//! use rtc::peer_connection::state::RTCPeerConnectionState;
//! use rtc::peer_connection::event::RTCPeerConnectionEvent;
//!
//! # fn example(event: RTCPeerConnectionEvent) {
//! match event {
//! RTCPeerConnectionEvent::OnConnectionStateChangeEvent(state) => {
//! match state {
//! RTCPeerConnectionState::New => println!("Connection initializing"),
//! RTCPeerConnectionState::Connecting => println!("Connection in progress"),
//! RTCPeerConnectionState::Connected => {
//! println!("Connection established - media can flow");
//! }
//! RTCPeerConnectionState::Disconnected => {
//! println!("Connection lost - attempting to reconnect");
//! }
//! RTCPeerConnectionState::Failed => println!("Connection failed permanently"),
//! RTCPeerConnectionState::Closed => println!("Connection closed"),
//! _ => {}
//! }
//! }
//! _ => {}
//! }
//! # }
//! ```
//!
//! ## Tracking Signaling State
//!
//! ```no_run
//! use rtc::peer_connection::state::RTCSignalingState;
//! use rtc::peer_connection::event::RTCPeerConnectionEvent;
//!
//! # fn example(event: RTCPeerConnectionEvent) {
//! match event {
//! RTCPeerConnectionEvent::OnSignalingStateChangeEvent(state) => {
//! match state {
//! RTCSignalingState::Stable => println!("Ready for new negotiation"),
//! RTCSignalingState::HaveLocalOffer => {
//! println!("Local offer set - waiting for answer");
//! }
//! RTCSignalingState::HaveRemoteOffer => {
//! println!("Remote offer received - need to send answer");
//! }
//! RTCSignalingState::HaveLocalPranswer => {
//! println!("Provisional answer sent");
//! }
//! RTCSignalingState::HaveRemotePranswer => {
//! println!("Provisional answer received");
//! }
//! RTCSignalingState::Closed => println!("Signaling closed"),
//! _ => {}
//! }
//! }
//! _ => {}
//! }
//! # }
//! ```
//!
//! ## State Transitions and String Conversion
//!
//! ```
//! use rtc::peer_connection::state::{
//! RTCIceConnectionState, RTCPeerConnectionState, RTCSignalingState
//! };
//!
//! // Convert to string
//! let state = RTCIceConnectionState::Connected;
//! assert_eq!(state.to_string(), "connected");
//!
//! // Parse from string
//! let state: RTCPeerConnectionState = "connecting".into();
//! assert_eq!(state, RTCPeerConnectionState::Connecting);
//!
//! // Parse signaling state
//! let state: RTCSignalingState = "have-local-offer".into();
//! assert_eq!(state, RTCSignalingState::HaveLocalOffer);
//! ```
//!
//! # State Machine Details
//!
//! ## ICE Connection States
//!
//! The ICE connection state progresses through these typical transitions:
//!
//! ```text
//! New → Checking → Connected → Completed
//! ↓ ↓ ↓
//! ↓ ↓ ↓
//! ↓ ↓ Disconnected → Failed
//! ↓ ↓ ↓ ↓
//! └───────┴──────────┴───────────┴→ Closed
//! ```
//!
//! ## ICE Gathering States
//!
//! ```text
//! New → Gathering → Complete
//! ```
//!
//! ## Signaling States (Offer/Answer)
//!
//! Successful negotiation (typical flow):
//!
//! ```text
//! Stable → HaveLocalOffer → Stable
//! or
//! Stable → HaveRemoteOffer → Stable
//! ```
//!
//! With provisional answers:
//!
//! ```text
//! Stable → HaveLocalOffer → HaveRemotePranswer → Stable
//! or
//! Stable → HaveRemoteOffer → HaveLocalPranswer → Stable
//! ```
//!
//! # Specifications
//!
//! - [W3C WebRTC Specification]
//! - [RFC 8445] - ICE: Interactive Connectivity Establishment
//! - [RFC 5245] - ICE (obsoleted by RFC 8445)
//!
//! [W3C WebRTC Specification]: https://w3c.github.io/webrtc-pc/
//! [RFC 8445]: https://datatracker.ietf.org/doc/html/rfc8445
//! [RFC 5245]: https://datatracker.ietf.org/doc/html/rfc5245
pub
pub
pub
pub
pub use RTCIceConnectionState;
pub use RTCIceGatheringState;
pub use RTCPeerConnectionState;
pub use RTCSignalingState;