dispose method

Future<void> dispose()

Implementation

Future<void> dispose() async {
  if (localUserMediaStream != null) {
    await removeUserMediaStream(localUserMediaStream!);
    localUserMediaStream = null;
  }

  if (localScreenshareStream != null) {
    await stopMediaStream(localScreenshareStream!.stream);
    await removeScreenshareStream(localScreenshareStream!);
    localScreenshareStream = null;
    localDesktopCapturerSourceId = null;
  }

  await _removeParticipant(client.userID!);

  await removeMemberStateEvent();

  final callsCopy = calls.toList();

  for (final call in callsCopy) {
    await removeCall(call, CallErrorCode.UserHangup);
  }

  activeSpeaker = null;
  activeSpeakerLoopTimeout?.cancel();
  await _callSubscription?.cancel();
}