changeTrackState method

Future<void> changeTrackState({
  1. required HMSTrack forRemoteTrack,
  2. required bool mute,
  3. HMSActionResultListener? hmsActionResultListener,
})

To change the mute status of a single remote peer's track.

Parameters:

forRemoteTrack - HMSTrack which you want to mute/unmute.

mute - Set mute to true if the track needs to be muted, false otherwise.

hmsActionResultListener - the callback that would be called by SDK in case of success or failure.

Refer changeTrackState guide here

Implementation

Future<void> changeTrackState(
    {required HMSTrack forRemoteTrack,
    required bool mute,
    HMSActionResultListener? hmsActionResultListener}) async {
  var arguments = {
    "track_id": forRemoteTrack.trackId,
    "mute": mute,
  };
  var result = await PlatformService.invokeMethod(
      PlatformMethod.changeTrackState,
      arguments: arguments);

  if (hmsActionResultListener != null) {
    if (result == null) {
      hmsActionResultListener.onSuccess(arguments: {
        "track": forRemoteTrack,
        "mute": mute,
      }, methodType: HMSActionResultListenerMethod.changeTrackState);
    } else {
      hmsActionResultListener.onException(
          arguments: {
            "track": forRemoteTrack,
            "mute": mute,
          },
          methodType: HMSActionResultListenerMethod.changeTrackState,
          hmsException: HMSException.fromMap(result["error"]));
    }
  }
}