join method

  1. @override
Future<Rx<OngoingCall>?> join(
  1. ChatId chatId,
  2. ChatCall? call, {
  3. bool withAudio = true,
  4. bool withVideo = false,
  5. bool withScreen = false,
})
override

Joins the current OngoingCall in the specified chatId by the authenticated MyUser.

Implementation

@override
Future<Rx<OngoingCall>?> join(
  ChatId chatId,
  ChatCall? call, {
  bool withAudio = true,
  bool withVideo = false,
  bool withScreen = false,
}) async {
  Log.debug(
    'join($chatId, $call, $withAudio, $withVideo, $withScreen)',
    '$runtimeType',
  );

  Rx<OngoingCall>? ongoing = calls[chatId];

  if (ongoing == null ||
      ongoing.value.state.value == OngoingCallState.ended) {
    // If we're joining an already disposed call, then replace it.
    if (ongoing?.value.state.value == OngoingCallState.ended) {
      remove(chatId);
    }

    ChatCallCredentials? credentials;
    if (call != null) {
      credentials = await getCredentials(call.id);
    }

    ongoing = Rx<OngoingCall>(
      OngoingCall(
        chatId,
        me,
        call: call,
        withAudio: withAudio,
        withVideo: withVideo,
        withScreen: withScreen,
        mediaSettings: media.value,
        creds: credentials ?? await generateCredentials(chatId),
        state: OngoingCallState.joining,
      ),
    );
    calls[chatId] = ongoing;
  } else if (ongoing.value.state.value != OngoingCallState.active) {
    ongoing.value.state.value = OngoingCallState.joining;
    ongoing.value.setAudioEnabled(withAudio);
    ongoing.value.setVideoEnabled(withVideo);
    ongoing.value.setScreenShareEnabled(withScreen);
  } else {
    return null;
  }

  final response = await _graphQlProvider.joinChatCall(
    ongoing.value.chatId.value,
    ongoing.value.creds!,
  );

  ongoing.value.deviceId = response.deviceId;

  final ChatCall? chatCall = _chatCall(response.event);
  if (chatCall != null) {
    ongoing.value.call.value = chatCall;
    transferCredentials(chatCall.chatId, chatCall.id);
  } else {
    throw CallAlreadyJoinedException(response.deviceId);
  }

  return ongoing;
}