setRemoteAudioEnabled method

Future<void> setRemoteAudioEnabled(
  1. bool enabled
)

Sets inbound audio in this OngoingCall as enabled or not.

No-op if isRemoteAudioEnabled is already enabled.

Implementation

Future<void> setRemoteAudioEnabled(bool enabled) async {
  Log.debug('setRemoteAudioEnabled($enabled)', '$runtimeType');

  try {
    final List<Future> futures = [];

    if (enabled && isRemoteAudioEnabled.isFalse) {
      for (CallMember m in members.values.where((e) => e.id != _me)) {
        futures.add(m.setAudioEnabled(true));
      }

      isRemoteAudioEnabled.toggle();
    } else if (!enabled && isRemoteAudioEnabled.isTrue) {
      for (CallMember m in members.values.where((e) => e.id != _me)) {
        if (m.tracks.any((e) => e.kind == MediaKind.audio)) {
          futures.add(m.setAudioEnabled(false));
        }
      }

      isRemoteAudioEnabled.toggle();
    }

    await Future.wait(futures);
  } on MediaStateTransitionException catch (_) {
    // No-op.
  }
}