Overview
The Real-time API provides comprehensive event monitoring to track connection health, errors, generation progress, and detailed diagnostics.Event Types
TheRealTimeClient emits the following events:
Connection State Events
Track connection lifecycle changes:Connection States
- connecting - Establishing WebRTC connection
- connected - Connected and ready to stream
- generating - Currently processing/transforming video
- reconnecting - Attempting to reconnect after disruption
- disconnected - Connection closed
Example Handler
Error Events
Handle errors during real-time sessions:Error Object
Common Error Codes
- WEBRTC_CONNECTION_FAILED - WebRTC connection establishment failed
- WEBRTC_ICE_FAILED - ICE connection failed
- WEBRTC_NEGOTIATION_FAILED - SDP negotiation failed
- WEBSOCKET_ERROR - WebSocket connection error
- TIMEOUT - Operation timed out
Error Handler Example
Generation Tick Events
Track generation progress in seconds:Example: Usage Tracker
Diagnostic Events
Receive detailed diagnostic information:Diagnostic Event Types
Phase Timing
Tracks timing for each connection phase:ICE Candidates
Tracks ICE candidate gathering:ICE State Changes
Peer Connection State
Signaling State
Selected Candidate Pair
Shows which ICE candidate pair was selected:Reconnection Events
Video Stall Detection
Detects when video playback stalls (FPS < 0.5):WebRTC Statistics
Receive real-time WebRTC performance statistics:Stats Structure
Example: Performance Monitor
Event Listener Management
Adding Listeners
Removing Listeners
One-time Listeners
Complete Monitoring Example
Debugging Tips
Enable Verbose Logging
Track Connection Timeline
Monitor Network Quality
Next Steps
- Overview - Learn about the Real-time API
- Connection Management - Connection and disconnection
- State Management - Update prompts and parameters