AudioStream interface
Common shape for audio streams. Extended by LocalAudioStream (adds device + processor control + silence detection) and RemoteAudioStream (adds setVolume + audioLevel + server-driven state).
Blueprint
Full surface at a glance. Subtypes (Local / Remote / ScreenAudio) add to this. No events on the base.
<audio> element and plays remote audio without any attach call. Local audio is not auto-played (feedback prevention). The attach method below is an escape hatch for custom routing.Properties
id
Server-assigned stream id.
codec
Audio codec in use.
isPlaying / isMuted / isEnded
Sync booleans reflecting current state.
Methods
attach / detach
Render this audio stream into a custom <audio> element. Escape hatch only โ by default the SDK auto-plays remote audio in an internal element, and local audio doesn't auto-play. Use this when you need custom output device routing per element, custom playback UI, or a Web Audio integration via the audio element.
Auto-detach on stream end. The SDK tracks every element passed to attach() and clears their srcObject when the stream ends (publisher unpublished, unsubscribed, etc.). You only need detach() for re-routing.
const audioEl = document.createElement('audio');
audioEl.autoplay = true;
document.body.appendChild(audioEl);
p.audio.attach(audioEl);
await audioEl.setSinkId(headsetDeviceId); // route this participant to a headset
getStats async
One-shot stats snapshot โ bitrate, packet loss, jitter, codec.
getMediaStreamTrack escape hatch
Returns the underlying MediaStreamTrack. Same contract as VideoStream.getMediaStreamTrack โ read-only / forward-only consumption; do not call lifecycle methods.
const track = p.audio.getMediaStreamTrack();
const ctx = new AudioContext();
const source = ctx.createMediaStreamSource(new MediaStream([track]));
const analyser = ctx.createAnalyser();
source.connect(analyser);
// ...drive a canvas waveform from analyser data
Events
The base interface defines no events. Operational events live on the subtypes:
- RemoteAudioStream โ single
state-changedevent covers routing transitions (paused / ended). - LocalAudioStream โ
silent-detected,ended(mic gone silent, device disconnected, permission revoked).
Lifecycle events (audio-published, audio-subscribed, etc.) fire on the participant.
See also: LocalAudioStream RemoteAudioStream VideoStream
Related open questions: Q13 โ Stream object abstraction across platforms