Skip to main content
This page explains how the Cognigy Click To Call SDK connects to the Cognigy backend. It also covers authentication, credential exchange, and how to configure initialization for different environments.

Initialization Steps

When you call createWebRTCClient(), the SDK performs the following initialization sequence:
  1. The SDK validates that endpointUrl is provided.
  2. The SDK checks that the current environment supports WebRTC (via isWebRTCSupported()).
  3. The SDK sets up its internal components and event handlers.
  4. The SDK returns the client. Then you can call connect() or connectAndCall().
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 the endpointUrl. 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 optional userId 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, calling connect() triggers the full connection sequence:
  1. Configuration fetch. The SDK sends an HTTPS GET request to the endpointUrl. The request retrieves SIP connection parameters such as server address, credentials, and application SID. The request has a 10-second timeout.
  2. 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.
  3. SIP User Agent creation. The SDK creates a JsSIP User Agent using the retrieved SIP credentials and WebSocket URI.
  4. WebSocket connection. The SDK opens a WebSocket connection to the SIP server.
  5. 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.
  6. 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 the registered event. After the configuration fetch, the process has a 15-second timeout.
The 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 from createWebRTCClient() 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

In production, point the endpointUrl to your production Cognigy environment. Use HTTPS and make sure the network allows WSS and UDP traffic.
For local development, you can use localhost without HTTPS. Point the endpointUrl to a development or staging Cognigy environment.

More Information

Last modified on October 23, 2026