Remote Mute/Unmute

You're running a room and decide that someone who's currently talking shouldn't be talking, or perhaps you want their video turned off. You're looking for a remote mute/unmute in this case.

Muting/Unmuting

Use the selectPermissions selector to check whether the local peer has the permission to mute or unmute others and then call one of the APIs below.

  1. Muting Single Track

To mute a single track, call hmsActions.setRemoteTrackEnabled with the trackID of the track you want to mute/unmute and enable(true for unmuting, false for muting).

try { await hmsActions.setRemoteTrackEnabled(peer.audioTrack, true); } catch (error) { // Permission denied or invalid track ID or not connected to room console.error(error); }
  1. Muting Multiple Tracks

You can use this API to mute mute/unmute multiple peers at the same time either by their roles, track source, track type or any combination of the above. Note that this API always excludes the local peer from the operation and applies only to remote peers.

try { const options = { enabled: false, // false to mute, true to unmute roles: ['student', 'parents'], // optional, array of roles to mute, mutes everyone if not passed type: 'audio', // optional, audio/video, mutes both if not passed source: 'regular' // optional, mutes all sources(regular, screen etc.) if not passed }; await hmsActions.setRemoteTracksEnabled(options); } catch (error) { // Permission denied or invalid track ID or not connected to room console.error(error); }

🚧 If the local peer doesn't have the required mute/unmute permission, the actions will throw an HMSException error.

Handling a mute/unmute request

Remote Unmute Request

Once the peer with adequate permissions calls setRemoteTrackEnabled, the local peer will receive a notification. In case of single track mute it will be of type CHANGE_TRACK_STATE_REQUEST with a HMSChangeTrackStateRequest object as the data.

  • Mute requests are automatically applied to the receiver by the SDK. No action is required.

  • For unmute request, use the information in notification.data to show a dialog to the user to ask if they want to accept the change and then apply the settings locally. The same as in a regular user Mute/Unmute.

hmsNotifications.onNotification((notification) => { if (!notification) { return; } switch (notification.type) { // For Single Track Remote Mute case HMSNotificationTypes.CHANGE_TRACK_STATE_REQUEST: const { requestedBy, track, enabled } = notification.data; // Unmute Request if (enabled) { // Ask for consent using dialog or any other appropriate UI await hmsActions.setEnabledTrack(track.id, enabled); } else { // Mute Request // Show toast to user } break; // For bulk remote mute, notification will contain all the tracks which will be impacted by this request case HMSNotificationTypes.CHANGE_MULTI_TRACK_STATE_REQUEST: const { requestedBy, tracks, type, source, enabled } = notification.data; // Unmute Request if (enabled) { // Ask for consent using dialog or any other appropriate UI tracks.forEach( async (track) => await hmsActions.setEnabledTrack(track.id, enabled) ); } else { // Mute Request // Show toast to user } break; } });