This example is a standard WHEPClient subscribe flow with an additional post-subscribe form that requests a stream switch using callServer(...).
It is a single-subscriber switch request: the active subscriber asks to switch its own playback target to another stream path.
- normal WHEP subscribe lifecycle (
init,subscribe,unsubscribe) - invoking server-side stream switching via
subscriber.callServer('switchStreams', ...) - handling
SUBSCRIBE_STREAM_SWITCHconfirmation event on success - keeping the same subscriber connection while playback target changes
After subscribe starts:
- Enter a target stream path (for example
live/stream2). - Submit the switch form.
- Example calls:
await subscriber.callServer('switchStreams', [
{
path: 'live/stream2',
isImmediate: true,
},
])- On successful switch, subscriber receives:
sdk.RTCSubscriberEventTypes.SUBSCRIBE_STREAM_SWITCH
- UI updates status to Stream switched.
Compared with whep-interstitial:
- No additional server configuration required for this switching flow.
- Less expressive control surface:
- no interstitial insert scheduling types/timing window API
- no rich insert/resume payload model
- no global programming-oriented behavior targeting all subscribers
This example is intentionally lightweight and focused on one subscriber request to switch playback target.
const subscriber = new red5prosdk.WHEPClient()
await subscriber.init({
endpoint,
streamName,
mediaElementId: 'subscriber-video',
connectionParams,
})
await subscriber.subscribe()
subscriber.on('*', (event) => {
if (event.type === red5prosdk.RTCSubscriberEventTypes.SUBSCRIBE_STREAM_SWITCH) {
console.log('Stream switch confirmed')
}
})
await subscriber.callServer('switchStreams', [{ path: 'live/stream2', isImmediate: true }])Switch-stream behavior is independent from deployment mode. Endpoint and connectionParams setup follows the same WHEP pattern as other subscriber 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
}- switch request submit handler:
submitSwitchStream() - switch event handling:
onSubscriberEvent()(SUBSCRIBE_STREAM_SWITCH) - form visibility + state:
syncSwitchStreamsSection()andresetSwitchState() - subscribe lifecycle:
startSubscribe()andstopSubscribe()
Use this example as the baseline for per-subscriber stream switching with callServer when you want a simple switch operation without full interstitial programming controls.