changeTrackStateForRole method

Future<void> changeTrackStateForRole({
  1. required bool mute,
  2. required HMSTrackKind? kind,
  3. required String? source,
  4. required List<HMSRole>? roles,
  5. HMSActionResultListener? hmsActionResultListener,
})

To change the mute status of one or many remote HMSTrack for all peers of a particular role, or all tracks of a particular source, type or source AND type.

Parameters:

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

kind - kind is the HMSTrackKind that should be affected. If this and the source are specified, it is considered an AND operation. If not specified, all track sources are affected.

source - source is the HMSTrackSource that should be affected. If this and type are specified, it is considered an AND operation. If not specified, all track types are affected.

roles - roles is a list of roles, that may have a single item in a list, whose tracks should be affected. If not specified, all roles are affected.

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

Refer changeTrackStateForRole guide here

Implementation

Future<void> changeTrackStateForRole(
    {required bool mute,
    required HMSTrackKind? kind,
    required String? source,
    required List<HMSRole>? roles,
    HMSActionResultListener? hmsActionResultListener}) async {
  List<String> rolesMap = [];

  if (roles != null) {
    roles.forEach((role) => rolesMap.add(role.name));
  }

  var arguments = {
    "mute": mute,
    "type": HMSTrackKindValue.getValueFromHMSTrackKind(
        kind ?? HMSTrackKind.unknown),
    "source": source,
    "roles": roles == null ? roles : rolesMap
  };
  var result = await PlatformService.invokeMethod(
      PlatformMethod.changeTrackStateForRole,
      arguments: arguments);

  if (hmsActionResultListener != null) {
    if (result == null) {
      hmsActionResultListener.onSuccess(arguments: {
        "mute": mute,
        "type": HMSTrackKindValue.getValueFromHMSTrackKind(
            kind ?? HMSTrackKind.unknown),
        "source": source,
        "roles": roles
      }, methodType: HMSActionResultListenerMethod.changeTrackStateForRole);
    } else {
      hmsActionResultListener.onException(
          arguments: {
            "mute": mute,
            "type": HMSTrackKindValue.getValueFromHMSTrackKind(
                kind ?? HMSTrackKind.unknown),
            "source": source,
            "roles": roles
          },
          methodType: HMSActionResultListenerMethod.changeTrackStateForRole,
          hmsException: HMSException.fromMap(result["error"]));
    }
  }
}