This example demonstrates WHEP subscribe against a Red5 Pro Standalone cluster where the playback edge is resolved dynamically from the cluster round-robin service.
Instead of subscribing directly to the host from Settings, the example first calls /cluster, receives a target host:port, and then initializes WHEPClient against the resolved host.
- standard
WHEPClientsubscribe lifecycle - cluster host discovery before subscribe
- subscribing to the resolved edge host (not the original settings host)
- endpoint/status visibility in
r5-subscriber-stats
To run this example, your Standalone deployment must be configured for clustering and expose the cluster servlet endpoint.
- Add origin IPs under
origins(with optional port) - Ensure all nodes use the same cluster
password - Set public-facing
publicIpandpublicPort - Use
privateInstanceto include/exclude an edge from round-robin
<bean name="clusterConfig" class="com.red5pro.cluster.ClusterConfiguration">
<property name="origins">
<list>
<!-- add origin ips and optional port if not the default -->
<value>0.0.0.0:1935</value>
</list>
</property>
<!-- edge/origin link cluster password -->
<property name="password" value="changeme"/>
<!-- EDGE public ip -->
<property name="publicIp" value="0.0.0.0"/>
<!-- EDGE public port -->
<property name="publicPort" value="1935"/>
<!-- EDGE include in round robin -->
<property name="privateInstance" value="false"/>
</bean>Subscribers use this endpoint (/cluster) to retrieve the playback IP.
<servlet>
<servlet-name>cluster</servlet-name>
<servlet-class>
com.red5pro.cluster.plugin.agent.ClusterWebService
</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cluster</servlet-name>
<url-pattern>/cluster</url-pattern>
</servlet-mapping>The helper src/lib/cluster-host-lookup.ts handles lookup:
- builds
clusterUrlfrom settings asprotocol://host:port/cluster - fetches that URL
- validates:
HTTP 200content-typeincludestext/plain- body contains
host:port
- extracts and returns the host portion for playback init
In src/examples/whep-cluster/index.ts, startSubscribe():
- calls
resolveHostFromCluster(settings) - stores the resolved host for UI display
- initializes
WHEPClientwith:host: <resolved host>protocol: 'http'port: 5080app,streamName, and optionalconnectionParams
- calls
subscribe()
const { host } = await resolveHostFromCluster(settings)
const subscriber = new red5prosdk.WHEPClient()
await subscriber.init({
host,
protocol: 'http',
port: 5080,
app: settings.app,
streamName: settings.streamName,
mediaElementId: 'subscriber-video',
})
await subscriber.subscribe()- This example targets Standalone cluster behavior (not Stream Manager routing).
/clustermust return plain text inhost:portformat.- If lookup fails, subscribe is aborted and the error is surfaced in the example log.
- cluster URL + lookup parsing:
src/lib/cluster-host-lookup.ts - subscribe orchestration:
startSubscribe() - lifecycle teardown:
stopSubscribe() - cluster status UI:
updateConnectionInfo()
Pair this with whep-basic to compare direct host subscribe versus cluster-resolved host subscribe.