call method
Starts an OngoingCall in a Chat with the given chatId
.
Implementation
Future<void> call(
ChatId chatId, {
bool withAudio = true,
bool withVideo = false,
bool withScreen = false,
}) async {
Log.debug(
'call($chatId, $withAudio, $withVideo, $withScreen)',
'$runtimeType',
);
final Rx<OngoingCall>? stored = _callsRepo[chatId];
if (WebUtils.containsCall(chatId)) {
throw CallIsInPopupException();
} else if (stored != null &&
stored.value.state.value != OngoingCallState.ended) {
throw CallAlreadyExistsException();
}
try {
final Rx<OngoingCall> call = await _callsRepo.start(
chatId,
withAudio: withAudio,
withVideo: withVideo,
withScreen: withScreen,
);
if (isClosed) {
call.value.dispose();
} else {
call.value.connect(this);
}
} on CallAlreadyJoinedException catch (e) {
_callsRepo.leave(chatId, e.deviceId);
_callsRepo.remove(chatId);
// TODO: Try joining the [OngoingCall] again, instead of throwing the
// exception here.
rethrow;
} catch (e) {
// If any other error occurs, it's guaranteed that the broken call will be
// removed.
_callsRepo.remove(chatId);
rethrow;
}
}