Connecting to Real-time API
Theconnect() method establishes a WebRTC connection to the real-time video transformation service.
Method Signature
Connection Options
Basic Connection Example
Getting Media Stream
You need to provide aMediaStream for most models. Use the browser’s getUserMedia API:
Webcam Input
Screen Capture
Canvas Stream
Live Avatar Connection
Thelive_avatar model has special requirements:
Connection with Reference Image
For models likelucy_2_rt that support reference images:
Monitoring Connection State
Track the connection lifecycle:Disconnecting
Always disconnect when done to clean up resources:Error Handling
Handle connection errors gracefully:Custom WebRTC Offer
For advanced use cases, customize the WebRTC offer:Session Information
Access session details for debugging or subscribe functionality:Next Steps
- State Management - Update prompts and parameters during connection
- Events & Diagnostics - Monitor connection health and performance