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:- Creates an internal
Audioelement withautoplayenabled and volume set to1.0. - When a remote audio stream arrives through the WebRTC peer connection, the SDK attaches it to the
Audioelement. Playback starts automatically. - When the call ends, the SDK stops playback, releases the stream, and emits the
audioEndedevent. The SDK also stops playback and emitsaudioEndedwhen you calldisconnect()ordestroy().
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 rawMediaStream 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 theAnalyserNode:
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 theMediaRecorder API: