removeUserMediaStream method

Future<void> removeUserMediaStream(
  1. WrappedMediaStream stream
)

Implementation

Future<void> removeUserMediaStream(WrappedMediaStream stream) async {
  final streamIndex =
      userMediaStreams.indexWhere((stream) => stream.userId == stream.userId);

  if (streamIndex == -1) {
    throw Exception('Couldn\'t find user media stream to remove');
  }

  userMediaStreams.removeWhere((element) => element.userId == stream.userId);
  audioLevelsMap.remove(stream.userId);
  onStreamRemoved.add(stream);

  if (stream.isLocal()) {
    await stream.disposeRenderer();
    await stopMediaStream(stream.stream);
  }

  onGroupCallEvent.add(GroupCallEvent.UserMediaStreamsChanged);

  if (activeSpeaker == stream.userId && userMediaStreams.isNotEmpty) {
    activeSpeaker = userMediaStreams[0].userId;
    onGroupCallEvent.add(GroupCallEvent.ActiveSpeakerChanged);
  }
}