shareCustomAudio(audioStream)
Share a custom audio stream in the meeting
caution
join() must be called before calling this method
Call this method to share a custom audio stream instead of using the default microphone. This is useful when you want to share audio from the Web Audio API, a processed audio stream, or any other custom audio source.
JavaScript
await meeting.shareCustomAudio(audioStream)
Parameters
| Parameter | Description | Type | Required |
|---|---|---|---|
| audioStream | A MediaStream object containing an audio track | MediaStream | Yes |
Return Value
This method does not return a value.
Events Emitted
localTrackStarted- Emitted when sharing audio for the first time (when no audio producer exists)localTrackStopped- Emitted when the audio track ends
note
When replacing an existing audio track, no events are emitted. If you need to track audio track updates in your application, you should manage this manually.
Example
Sharing Audio from Web Audio API
JavaScript
// Create an audio context
const audioContext = new AudioContext();
// Create an oscillator or process audio
const oscillator = audioContext.createOscillator();
const destination = audioContext.createMediaStreamDestination();
oscillator.connect(destination);
oscillator.start();
// Get the MediaStream
const audioStream = destination.stream;
// Share the custom audio
await meeting.shareCustomAudio(audioStream);
info
If you are already sharing audio, calling this method will replace the current audio track with the new one without stopping and restarting the audio producer. Note that unlike video track replacement, no localTrackUpdated event is emitted when replacing audio.