leave method

Future<void> leave(
  1. ChatId chatId, [
  2. ChatCallDeviceId? deviceId
])

Leaves or declines an OngoingCall identified by the given chatId.

Implementation

Future<void> leave(ChatId chatId, [ChatCallDeviceId? deviceId]) async {
  Log.debug('leave($chatId, $deviceId)', '$runtimeType');

  Rx<OngoingCall>? call = _callsRepo[chatId];
  if (call != null) {
    deviceId ??= call.value.deviceId;
    call.value.state.value = OngoingCallState.ended;
    call.value.dispose();
  }

  deviceId ??= WebUtils.getCall(chatId)?.deviceId;

  if (deviceId != null) {
    await _callsRepo.leave(chatId, deviceId);
  } else {
    await _callsRepo.decline(chatId);
  }

  _callsRepo.remove(chatId);
  WebUtils.removeCall(chatId);
}