This example is a standard WHEPClient subscriber with a pre-subscribe form that sets renegotiationPolicy in the init() configuration.
It demonstrates how the subscriber can detect unhealthy connection conditions and allow SDK-driven reconnect/renegotiation behavior when configured.
- standard WHEP subscribe lifecycle
- pre-subscribe
renegotiationPolicyselection - connection-health monitoring via WebRTC/statistics events
- reconnect/renegotiation signals during poor network conditions
- health/event visualization in a dedicated connection-health panel
The renegotiationPolicy init attribute is used during health/statistics monitoring to determine when the SDK should treat negotiation as degraded and respond accordingly.
Type shape:
type RenegotiationPolicyType = {
type: 'regression' | 'timeout' | 'disconnect' | 'excessive-rtt'
iceTimeoutInterval: number
}type options:
regression: ICE state regresses from a previously successful statetimeout: ICE negotiation takes too long (usesiceTimeoutInterval)disconnect: peer connection disconnect is observed after negotiation troubleexcessive-rtt: RTT is considered too high (severe levels are highlighted)
iceTimeoutInterval is used with timeout policy type.
Default behavior when renegotiationPolicy is omitted: no policy-driven action.
Before subscribing, the form values are read and passed directly into subscriber.init(...):
const renegotiationPolicy = {
type: policyType,
iceTimeoutInterval: timeoutMs,
}
await subscriber.init({
endpoint,
streamName,
mediaElementId: 'subscriber-video',
connectionParams,
stats,
rtcConfiguration,
renegotiationPolicy,
})The example listens for and surfaces these negotiation-health events:
WebRTC.Connection.StaleStatsWebRTC.Connection.StateRegressionWebRTC.Connection.ExcessiveRTTWebRTC.Connection.IceTimeout
It also listens for reconnect-related subscriber events:
Reconnect.StartReconnect.Failure
These are reflected in:
- status text
- reconnection attempt counter
- health counters/severity badges
- time-stamped event log entries
The page includes a testing section with browser throttling steps. Recommended flow:
- Open Chrome DevTools.
- Open the Network tab.
- Enable network throttling and select
Slow 3G. - Select policy type and timeout interval in the form.
- Start subscribe and observe health events + renegotiation attempts.
- Restore network to normal and confirm recovery behavior.
const subscriber = new red5prosdk.WHEPClient()
subscriber.on('*', (event) => {
if (event.type === red5prosdk.WebRTCConnectionEventTypes.CONNECTION_HEALTH_ICE_TIMEOUT) {
console.log('ICE timeout detected')
}
if (event.type === red5prosdk.SubscriberEventTypes.RECONNECT_START) {
console.log('Renegotiation/reconnect started')
}
})
await subscriber.init({
endpoint,
streamName,
mediaElementId: 'subscriber-video',
renegotiationPolicy: {
type: 'regression',
iceTimeoutInterval: 3000,
},
})
await subscriber.subscribe()Renegotiation policy behavior is independent from deployment mode. Endpoint and connectionParams setup follows the same WHEP patterns 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
}- policy form read/enable state:
readRenegotiationPolicy()andsetRenegotiationFormEnabled() - subscribe init wiring:
startSubscribe() - health event handling:
handleHealthEvent() - health severity/counters/log rendering:
updateHealthDisplay()andrenderHealthLog() - subscriber event router:
onSubscriberEvent()
Use this example as the baseline for policy-driven WHEP renegotiation handling in applications that need explicit responses to degraded ICE/RTT conditions.