Initialization Steps
When you callcreateWebRTCClient(), the SDK performs the following initialization sequence:
- The SDK validates that
endpointUrlis provided. - The SDK checks that the current environment supports WebRTC (via
isWebRTCSupported()). - The SDK creates internal managers (
ConfigManager,SipManager,SessionManager,AudioManager) and wires up event handlers. - The client is returned, ready to call
connect()orconnectAndCall().
No network requests are made during
createWebRTCClient(). The SIP configuration is fetched later when you call connect() or connectAndCall().Authentication
Endpoint-Based Authentication
The SDK authenticates with the Cognigy backend through theendpointUrl. When the SDK fetches the SIP configuration, the Cognigy backend:
- Validates the endpoint configuration.
- Generates short-lived SIP credentials scoped to the session.
- Returns the credentials along with the SIP server address.
User Identification
The optionaluserId parameter is sent to the Cognigy backend as part of the configuration request. It allows the backend to:
- Associate the Click To Call session with a specific user in Cognigy.AI.
- Correlate call data with user sessions in Cognigy Insights.
- Route calls to the correct AI Agent Flow.
The
userId is used for session identification only. Don’t pass sensitive information such as passwords, tokens, or personally identifiable information (PII) as the userId.Connection and Registration
After initialization, callingconnect() triggers the full connection sequence:
- Configuration fetch. The SDK sends an HTTPS
GETrequest to theendpointUrlto retrieve SIP connection parameters (server address, credentials, application SID). The request has a 10-second timeout. - Widget validation. The SDK verifies that the Click To Call widget is active in the endpoint configuration. If it’s not active, an error is thrown.
- SIP User Agent creation. The SDK creates a JsSIP User Agent using the retrieved SIP credentials and WebSocket URI.
- WebSocket connection. The SDK opens a WSS (WebSocket Secure) connection to the SIP server.
- SIP REGISTER. The SDK sends a SIP REGISTER request using the credentials obtained from the endpoint.
- Registration confirmed. Once both the WebSocket connection is established and SIP registration succeeds, the SDK emits the
registeredevent. The entire process has a 15-second timeout.
connectAndCall() convenience method performs the same sequence and immediately starts a call after registration.
Handling Initialization Errors
If initialization or authentication fails, the SDK throws an error fromcreateWebRTCClient() or connect(). Common errors include:
| Error | Error Source | Recommended Action |
|---|---|---|
Missing endpointUrl | createWebRTCClient() | Provide a valid endpoint URL. |
| WebRTC not supported | createWebRTCClient() | Ensure the browser supports WebRTC. Use checkWebRTCSupport() to verify. |
Invalid or unreachable endpointUrl | connect() | Verify the URL is correct and accessible over HTTPS. |
| Backend returns invalid SIP config | connect() | Contact your Cognigy administrator. |
| Click To Call widget not active | connect() | Enable the Click To Call widget in the endpoint configuration. |
| SIP server unreachable | connect() | Check network and firewall settings. |
| SIP registration rejected | connect() | Verify SIP credentials via the Cognigy backend. |
| Connection timeout (15 seconds) | connect() | Check network connectivity and SIP server availability. |
| CORS error on config fetch | connect() | Ensure the backend allows cross-origin requests from your domain. |
Environment Configuration
Production
Production
In production, the
endpointUrl should point to your production Cognigy environment. Ensure HTTPS is used and the network allows WSS and UDP traffic.Development and Testing
Development and Testing
For local development, you can use
localhost without HTTPS. Point the endpointUrl to a development or staging Cognigy environment.Custom ICE Servers
Custom ICE Servers
If your environment requires specific STUN or TURN servers for NAT traversal, configure them via the For more details on ICE or TURN configuration, refer to Security — Network Security.
pcConfig option during initialization:More Information
- createWebRTCClient — factory function reference
- connect — connection method reference
- Security — transport encryption, credential handling, and best practices
- Troubleshooting — resolve connection and authentication errors