This example shows how to publish with WHIPClient and toggle live audio/video transmission without stopping the publish session.
It is the sender-side pair for whep-mute-api.
- WHIP publish with explicit preview stream via
initWithStream(...) - runtime mute/unmute controls:
publisher.muteAudio()/publisher.unmuteAudio()publisher.muteVideo()/publisher.unmuteVideo()
- preserving session continuity while media delivery state changes
- local preview indicator updates for audio/video on/off state
After publish starts, the Mute Controls section is shown.
Audio button flow:
if (audioMuted) {
publisher.unmuteAudio()
} else {
publisher.muteAudio()
}Video button flow:
if (videoMuted) {
publisher.unmuteVideo()
} else {
publisher.muteVideo()
}The example also mirrors that state to live preview tracks (
track.enabled). This ensures that the media is also not being delivered to the server when mute is request, while just callingmute*signals to the server that it should not deliver media to all subscribing clients while still receiving media.
This example uses initWithStream(...) so the stream is acquired from publish settings first, then passed into the client:
const mediaStream = await publishSettingsEl.refreshStream()
await publisher.initWithStream(
{
endpoint,
streamName,
mediaElementId: 'publisher-video',
connectionParams,
streamMode,
},
mediaStream
)
await publisher.publish()const publisher = new red5prosdk.WHIPClient()
await publisher.initWithStream(
{
endpoint,
streamName,
mediaElementId: 'publisher-video',
},
mediaStream
)
await publisher.publish()
// Toggle audio
publisher.muteAudio()
publisher.unmuteAudio()
// Toggle video
publisher.muteVideo()
publisher.unmuteVideo()Mute API behavior is independent from deployment mode. Endpoint and connection parameter setup follows the same WHIP pattern as other examples.
endpointtargets the server directly (origin).connectionParamsis optional unless your server/plugins require extra values.
const endpoint = `https://${host}:443/live/whip/${streamName}`
const connectionParams = {}endpointtargets Stream Manager proxy routing.connectionParamscommonly includes Stream Manager and auth metadata.
const endpoint = `https://${host}/as/v1/proxy/whip/${app}/${streamName}`
const connectionParams = {
// e.g. region, nodeGroup, auth metadata
}- publish flow:
startPublish() - mute UI section transitions:
showMuteControlsSection()/hideMuteControlsSection() - audio mute handler:
toggleAudioMute() - video mute handler:
toggleVideoMute() - preview sync helpers:
syncPreviewTrackMute()andsyncVideoOverlayIndicators() - status/event handling:
onPublisherEvent()
Pair this with whep-mute-api to see how subscriber-side UI reflects publisher mute state from metadata.