Mute & Unmute

Mute is something that applies to both audio and video. When you mute audio, you can't be heard by other people i.e your audio is OFF. When you mute a video, you will not be broadcasting your video to other people i.e your video is OFF.

Check Mute Status

Current Mute Status of any HMSTrack can be checked by calling isMute method on it.

In most of the cases, You would need current mute status to toggle mute and render correct mic and camera icons.

// You can get `HMSTrack` object from `HMSPeer` object // or `HMSUpdateListenerActions.ON_TRACK_UPDATE` event const audioMuted = peer.audioTrack?.isMute(); // audioTrack property can be undefined const videoMuted = peer.videoTrack?.isMute(); // videoTrack property can be undefined

Change Your(Local Peer) Mute Status

To switch your "video" or "audio" on/off, you can call setMute method available on HMSLocalVideoTrack or HMSLocalAudioTrack objects respectively with true or false values.

If you want to toggle mute status of your "video" or "audio", then you can first get the current mute status and then pass opposite value to setMute method.

// instance acquired from build() method const localPeer = await hmsInstance.getLocalPeer(); // Muting Example - localPeer.localAudioTrack().setMute(true); // Muting Local Audio localPeer.localVideoTrack().setMute(true); // Muting Local Video // Toggling Mute Example - const audioMuted = localPeer.audioTrack?.isMute(); // Toggling Local Audio, audio will be unmuted localPeer.localAudioTrack().setMute(!audioMuted); // passing opposite value of audioMuted const videoMuted = localPeer.videoTrack?.isMute(); // Toggling Local Video, video will be unmuted localPeer.localVideoTrack().setMute(!videoMuted); // passing opposite value of videoMuted

For muting remote peer refer to Change Track State docs and for muting remote peers locally refer to Playback Allowed docs.

Switch Camera

The switchCamera API allows you to switch between front and back camera. This can be used to toggle the video captured from front to back & vice versa. This API is available on HMSLocalVideoTrack object.

// a reference to localVideoTrack
// Example const switchCamera = useCallback(async () => { // Redux state const state: ReduxState = store.getState(); // get a reference to localPeer const localPeer = state.hmsStates.localPeer; if (!localPeer) { return Promise.reject('Local Peer Instance is not available!'); } const localVideoTrack = localPeer.localVideoTrack(); if (!localVideoTrack) { return Promise.reject( 'Local Peer Video Track Instance is not available!' ); } // this API switches the current camera from front to back and vice versa
}, []);

Have a suggestion? Recommend changes ->

Was this helpful?