Skip to main content
The Cognigy Click To Call SDK handles remote audio playback automatically by creating and managing an internal Audio element. For advanced use cases, set captureAudio: true in the client configuration. The SDK then emits the captureAudio event with the raw MediaStream. The SDK also emits the audioEnded event when playback stops.

Default Behavior

By default, the SDK:
  1. Creates an internal Audio element with autoplay enabled and volume set to 1.0.
  2. When a remote audio stream arrives through the WebRTC peer connection, the SDK attaches it to the Audio element. Playback starts automatically.
  3. When the call ends, the SDK stops playback, releases the stream, and emits the audioEnded event. The SDK also stops playback and emits audioEnded when you call disconnect() or destroy().
No manual audio setup is required for basic call functionality.
Browser autoplay policies might block audio playback if the call doesnโ€™t start from a user gesture, for example, a button click. Always start calls in response to user interaction. If the browser blocks playback, the SDK emits the error event. The message starts with Audio playback failed.

Accessing the Raw Audio Stream

To receive the raw MediaStream for advanced audio processing, enable the captureAudio option and subscribe to the event:
The captureAudio event emits in addition to the SDKโ€™s automatic audio playback. You donโ€™t need to handle playback yourself. The SDK still plays audio through its internal Audio element. The SDK doesnโ€™t provide a volume control or a way to turn off its own playback.

Audio Visualization

Create a real-time audio visualizer using the AnalyserNode:
When you use the captureAudio stream for visualization, avoid connecting it to audioContext.destination, because the SDK already handles playback. Doing so plays the audio twice.

Audio Recording

Record the remote audio stream using the MediaRecorder API:
Recording calls may be subject to legal requirements such as consent laws. Ensure your application complies with applicable regulations before recording audio.

More Information

Last modified on October 23, 2026