ConnectionState type represents the current state of a real-time WebRTC connection.
Type Definition
States
connecting
The initial state when establishing a WebRTC connection. This includes:
- Creating the WebSocket connection
- Exchanging SDP offers/answers
- Establishing ICE candidates
- Waiting for the “ready” signal from the server
connected
The connection is fully established and ready to receive prompts or process video. The video stream is active but no generation is currently in progress.
Transitions from: connecting, generating
generating
The model is actively processing a prompt and generating content. The video stream shows the generation progress.
Transitions from: connectedTransitions to:
connected (when generation completes)
disconnected
The connection has been closed, either intentionally via disconnect() or due to an error. No video stream is available.
Transitions from: Any stateFinal state: Cannot transition to other states without calling
connect() again
reconnecting
The connection was lost unexpectedly and the SDK is attempting to reconnect automatically. The previous session state may be restored if reconnection succeeds.
Transitions from: connected, generatingTransitions to:
connected, disconnected
Usage Examples
Listening to State Changes
Building a Status UI
Conditional Actions Based on State
State Transitions
Related APIs
- on(‘connectionStateChange’) - Listen for state changes
- getState() - Get current connection state
- connect() - Initiate connection
- disconnect() - Close connection
Notes
- State changes are emitted via the
connectionStateChangeevent - The
generatingstate is triggered automatically when processing begins - Reconnection attempts are automatic and do not require manual intervention
- Always check the current state before calling state-dependent methods