reinitializeAfterSession method
Re-initializes the Calls SDK after a session ends. Per the V5 SDK sample app: "The SDK's internal state can get cleared after a session, so this ensures subsequent calls work properly."
Implementation
Future<void> reinitializeAfterSession() async {
final settings = CometChatUIKit.authenticationSettings;
if (settings?.appId != null && settings?.region != null) {
_callsSdkReady = false;
_callsSdkLoginReady = false;
_callsSdkCompleter = null;
_callsSdkLoginCompleter = null;
await _initCallsSdk(settings!.appId!, settings.region!);
// Re-login the user — the V5 SDK clears its internal user session
// after a call ends, so generateToken/joinSession will fail with
// "auth token is null" unless we re-authenticate.
_callsSdkLoginCompleter = Completer<void>();
await _loginCallsSdk();
if (_callsSdkLoginReady && !_callsSdkLoginCompleter!.isCompleted) {
_callsSdkLoginCompleter!.complete();
} else if (!_callsSdkLoginCompleter!.isCompleted) {
_callsSdkLoginCompleter!.complete();
}
developer.log(
'CallEventService: SDK re-initialized and re-logged in after session');
}
}