waitForCallsSdk method
Waits for the Calls SDK to be initialised and the logged-in user to be logged into it. Returns at once when it already is.
Other components (e.g. CallLogsBloc, VoipCallHandler) should call this instead of initializing the SDK themselves.
Bounded: it returns within 22 seconds whatever the Calls SDK does. When an earlier init or login failed, this runs it once more. Concurrent callers share one attempt. It never throws; the call screen checks readiness itself afterwards.
When call handling has not been started (UIKitSettings.enableCalls
is off and init was never called) but a user is logged in, this
starts it first, as init would.
Implementation
Future<void> waitForCallsSdk() async {
if (!CallsLifecycle.isStarted) {
final user = await _loggedInUser();
// Re-checked: a login may have started it while the user was read.
if (user != null && !CallsLifecycle.isStarted) {
ccLog('CallEventService: waitForCallsSdk starts call handling');
await CallsLifecycle.start(user);
}
}
final session = CallsSdkSession.instance;
final ready = await session.ensureReady();
if (!ready) {
ccLog(
'CallEventService: waitForCallsSdk finished but the Calls SDK is not '
'ready (init=${session.initPhase}, login=${session.loginPhase})',
);
}
}