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!
Use this file to discover all available pages before exploring further.
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, and make your first call.The code examples in this guide use TypeScript. If you use plain JavaScript, remove the type annotations.
Import the SDK, verify browser support, and create a client instance:
import { createWebRTCClient, checkWebRTCSupport } from '@cognigy/click-to-call-sdk';const support = checkWebRTCSupport();if (!support.supported) { console.error('WebRTC not supported. Missing features:', support.missing); throw new Error('Browser does not support WebRTC');}const client = await createWebRTCClient({ endpointUrl: 'https://your-cognigy-environment.com/endpoint-token', userId: 'user-123',});
For advanced use cases, such as specifying custom STUN or TURN servers, provide a pcConfig object when creating the client.Use pcConfig only if your application requires custom NAT traversal or TURN servers. Otherwise, the SDK uses default servers automatically.
Audio playback is automatic. You don’t need to add an <audio> element to your HTML. For advanced use cases, such as custom audio processing or visualization, refer to Custom Audio.
With the client configured and events registered, start a voice call:
// Connect and start the call in one stepawait client.connectAndCall();
To end the call and clean up:
await client.endCall();await client.disconnect();
Instead of calling endCall() and disconnect() separately, you can call client.destroy() to end the call, disconnect, and release all resources in one step.
Combine the code from the previous sections into a single function and bind it to a button click in your web application. A call must be initiated by a user gesture, for example, a button click, because browsers block audio autoplay without user interaction. Refer to the Complete Example.