Prerequisites
- A modern web browser with WebRTC support. For more information, refer to Supported Browsers.
- Node.js version 16 or later to install and build your application. The SDK itself runs only in browsers.
- A web application where you can install npm packages.
- The web application must be served over HTTPS or from
localhost. WebSocket and UDP traffic must be allowed for SIP signaling and media transport.
- The web application must be served over HTTPS or from
- A Cognigy Flow with a configured Voice Gateway Endpoint.
Install the SDK
-
Install the SDK in your web application project using npm:
-
Verify the installation:
Configure the Client
Import the SDK, verify browser support, and create a client instance:endpointUrl parameter must point to a valid Cognigy Voice Gateway Endpoint:
- In the Configuration section of the Voice Gateway Endpoint, copy the URL from the Endpoint URL field.
-
Replace
wss://withhttps://and remove/voiceGatewayfrom the path. For example, if your Endpoint URL is:Then yourendpointUrlwill be:
userId parameter is optional. If you donโt provide a userId, the SDK generates one.
Register Event Listeners
Set up event listeners before making any calls: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.Start and End a Call
With the client configured and events registered, start a voice call:You can end a call only after the remote party has answered it. Calling
endCall() while the call is still ringing fails with an error.Run and Verify
- 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.
- Start your application and open it in a supported browser.
- Open the browser developer console.
- Click the button that triggers the call. You should see the following messages in the console:
Connecting to SIP server.... The SDK is establishing a connection.SIP client registered. Registration succeeded. This message appears only for endpoints that require registration.Call answered. Session ID: .... The call is active and audio should be playing.