This example is a standard WHEPClient subscribe flow, but routes playback to an HTML audio element instead of a video element.
It also includes a basic analyzer UI that visualizes incoming audio level while subscribed.
- standard WHEP subscribe lifecycle with
WHEPClient - assigning subscribed
MediaStreamplayback to anaudioelement (mediaElementId) - receiving streams that may include video tracks while rendering audio-only playback
- basic real-time level meter (fill, peak, dB readout) from the live stream
The key configuration difference is:
await subscriber.init({
endpoint,
streamName,
mediaElementId: 'subscriber-audio',
connectionParams,
})With this setup, playback is attached to the audio element even if the incoming stream includes video tracks.
After subscribe:
- wait for playback readiness (
waitForAudioSrcObject()) - start analyzer with the stream assigned to the audio element (
startAudioLevelAnalyzer()) - update meter UI continuously while subscribed
- stop/dispose analyzer on unsubscribe and page unload
The analyzer prefers tapping the element stream so displayed levels reflect what users actually hear.
const subscriber = new red5prosdk.WHEPClient()
await subscriber.init({
endpoint,
streamName,
mediaElementId: 'subscriber-audio',
connectionParams,
})
await subscriber.subscribe()
// Optional analysis
const audioEl = document.getElementById('subscriber-audio') as HTMLAudioElement
const analyzer = new AudioContext()
const source = analyzer.createMediaElementSource(audioEl)
const meter = analyzer.createAnalyser()
source.connect(meter)
meter.connect(analyzer.destination)- Build a normal WHEP subscribe flow.
- Use an
audioelement and pass its id throughmediaElementId. - Keep event handling for
Subscribe.Start,Subscribe.Fail,Subscribe.Stop. - Start analyzer only after playback stream is present/flowing.
- Stop and dispose analyzer when subscription ends.
Audio-element playback behavior is independent from deployment mode. Endpoint and connection setup follows the same WHEP pattern as other examples.
const endpoint = `https://${host}:443/live/whep/${streamName}`
const connectionParams = {}const endpoint = `https://${host}/as/v1/proxy/whep/${app}/${streamName}`
const connectionParams = {
// e.g. region, nodeGroup, auth metadata
}- subscribe flow:
startSubscribe() - playback readiness gate:
waitForAudioSrcObject() - analyzer startup:
startAudioLevelAnalyzer() - analyzer teardown:
stopAudioLevelAnalyzer()andaudioLevelAnalyzer.dispose() - analyzer helper implementation:
src/lib/audio-level-analyzer.ts
Pair this with whep-basic to compare video-element playback and audio-element playback patterns.