Help us improve our product documentation on docs.cognigy.com by sharing your thoughts in a quick survey. Your feedback shapes the future of our content!
Help us improve our product documentation on docs.cognigy.com by sharing your thoughts in a quick survey. Your feedback shapes the future of our content!
Deploy customized, interactive voice AI Agents in minutes.
By the end of this guide, you will have a working web application that uses the Cognigy Click To Call SDK to establish a SIP-based voice call from the browser. You will install the SDK, verify browser compatibility, configure a client, handle audio streams, and make your first call.
Before creating a client, verify that the user’s browser supports Click To Call. Then create a client instance by providing your Endpoint URL and an optional user identifier.
Report incorrect code
Copy
import { createWebRTCClient, checkWebRTCSupport } from '@cognigy/click-to-call-sdk';// Step 1: Verify browser supportconst support = checkWebRTCSupport();if (!support.supported) { console.error('WebRTC not supported. Missing features:', support.missing); throw new Error('Browser does not support WebRTC');}// Step 2: Create the clientconst client = await createWebRTCClient({ endpointUrl: 'https://your-cognigy-environment.com/token', userId: 'user-123',});
The endpointUrl must point to a valid Cognigy Voice Gateway Endpoint:
In the Configration section of the Voice Gateway Endpoint, copy the URL from the Endpoint URL field.
Replace wss:// with https:// and remove /voiceGateway from the path. For example, if your Endpoint URL is:
The SDK fetches SIP credentials and server details from this URL automatically.For advanced configuration, such as specifying custom STUN/TURN servers, pass a pcConfig object:
Set up audio handling. The SDK plays remote audio automatically using an internal Audio element — no manual audio setup is required. If you need access to the raw audio stream for advanced processing such as visualization or recording, set captureAudio: true in the client configuration and listen for the captureAudio event:
Report incorrect code
Copy
const client = await createWebRTCClient({ endpointUrl: 'https://your-cognigy-environment.com/click-to-call-config', userId: 'user-123', captureAudio: true,});client.on('captureAudio', (stream) => { // Optional: process the raw audio stream for visualization, recording, etc. console.log('Received audio stream for processing');});client.on('audioEnded', () => { console.log('Remote audio ended');});
The SDK manages audio playback internally. You don’t need to add an <audio> element to your HTML.
With the client configured and events registered, connect to the SIP server and start a voice call. You can do this in two ways:
Combined (Recommended)
Separate Steps
Use the convenience method to connect and call in one step:
Report incorrect code
Copy
await client.connectAndCall();
Connect first, then start a call when ready:
Report incorrect code
Copy
await client.connect();await client.startCall();
Once the call is answered, you will hear the remote audio automatically (the SDK manages playback internally), and the answered event will fire in your console.To end the call and clean up:
Open the application in a supported browser, for example, http://localhost:3000.
Verify the following in your browser developer console:
Connecting to SIP server... — the SDK is establishing a connection.
SIP client registered — registration succeeded.
Call answered. Session ID: ... — the call is active and audio should be playing.
To end the call, trigger client.endCall() from your UI or console.
If you don’t hear audio, check Troubleshooting — No Audio for common causes such as browser autoplay policies or missing TURN server configuration. Audio is managed automatically by the SDK, but the call must be initiated by a user gesture for autoplay policies to allow playback.