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 sets up its internal components and event handlers.
- The SDK returns the client. Then you can call
connect()orconnectAndCall().
createWebRTCClient() doesn’t make network requests. The SDK fetches the SIP configuration later, when you call connect() or connectAndCall().Authentication
Endpoint-Based Authentication
The SDK authenticates with the Cognigy backend through theendpointUrl. When you call connect(), the SDK sends a request to this URL and receives the SIP server address and the information it needs to connect. The response must contain an active Click To Call widget configuration.
The SDK uses this information internally. Your application code doesn’t handle SIP credentials.
User Identification
The optionaluserId parameter identifies the user in the SIP session. The SDK doesn’t send it with the configuration request. If you don’t provide a userId, the SDK generates one.
The
userId is used to identify the session 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 theendpointUrl. The request retrieves SIP connection parameters such as server address, credentials, and 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, the SDK throws an error.
- 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 WebSocket connection to the SIP server.
- SIP REGISTER. If the endpoint requires registration, the SDK sends a SIP REGISTER request. Some endpoints don’t require registration, and the SDK skips this step for them.
- Connection confirmed.
connect()resolves once the WebSocket connection is established. If the endpoint requires registration, it resolves only after the SIP registration also succeeds. In that case, the SDK emits theregisteredevent. After the configuration fetch, the process has a 15-second timeout.
connectAndCall() convenience method performs the same sequence and immediately starts a call after the connection is established.
Handling Initialization Errors
If initialization or authentication fails, the SDK throws an error fromcreateWebRTCClient() or connect(). Common errors include:
The errors from
connect() start with Failed to connect:, except Client has been destroyed. For example, Failed to connect: Operation timed out after 15000ms.
Environment Configuration
Production
Production
In production, point the
endpointUrl to your production Cognigy environment. Use HTTPS and make sure 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.