- WebSocket signaling for session setup, SDP exchange, and ICE candidate exchange
- WebRTC media for bidirectional audio once the connection is established
Prerequisites
- A WebRTC-capable browser
- Microphone permissions enabled
- A PolyAI authentication token
Quick start
- Open a WebSocket connection to the signaling endpoint
- Create a WebRTC peer connection and collect microphone audio
- Send an offer message containing SDP and your auth token
- Receive an answer message containing SDP and a session identifier
- Exchange ICE candidates until the connection is established
- Audio flows bidirectionally
Signaling endpoint
Signaling URL (WebSocket):wss://webrtc-gateway.us-1.platform.polyai.app/api/v1/webrtc/signal
All signaling messages are JSON objects sent over the WebSocket connection.
Message structure
All signaling messages follow the same top-level structure.| Field | Required | Description |
|---|---|---|
| type | Yes | Message type: offer, answer, ice-candidate, error, close |
| sessionId | Yes | Empty string when creating a new session |
| data | No | Message-specific payload |
| authToken | Offer only | Authentication token |
| callSid | No | Optional call identifier |
| caller | No | Optional caller identifier |
| callee | No | Optional callee identifier |
Message types
Offer (client to server)
Starts a new session. Send with an empty sessionId. Example message:Answer (server to client)
Sent in response to an offer. Contains the SDP answer and the assigned sessionId.ICE candidate (bidirectional)
Sent by both client and server to establish network connectivity.Close (client to server)
Terminates the session gracefully.Error (server to client)
Sent when an error occurs.WebRTC configuration
Audio codec
The gateway requires Opus audio.- MIME type: audio/opus
- Sample rate: 48 kHz
- Channels: stereo
ICE servers
Configure your peer connection with a STUN server. TURN is recommended for restrictive networks. Example STUN server:stun.l.google.com:19302
Browser support
- Chrome 72 or newer
- Firefox 60 or newer
- Safari 14.1 or newer
- Edge 79 or newer
Troubleshooting
Unauthorized error
Ensure the authentication token is valid and included in the offer message.No audio
- Confirm microphone permissions are granted
- Verify Opus is negotiated successfully
ICE connection fails
- Corporate firewalls may require TURN
- Ensure UDP traffic is allowed
- Configure TURN over TCP if needed

