completeTransitionAfterAtomicChange method
Completes session transition after sessionID has been changed atomically This handles timers, timestamps, and events after the atomic ID change
Implementation
Future<void> completeTransitionAfterAtomicChange(String oldSessionId, String newSessionId) async {
if (!_isInitialized || _idManager == null) {
ObslyLogger.warn('SessionController not initialized for transition completion');
return;
}
try {
// Cancel previous timer if it exists
_sessionTimer?.cancel();
// Set timestamp for new session (sessionID was already changed atomically)
final now = DateTime.now().millisecondsSinceEpoch;
if (DefaultConfiguration.persistSessionTimestamp) {
await _idManager!.setSessionTimestamp(now);
}
// Schedule timeout for new session
_scheduleSessionTimeout(Duration(minutes: _sessionMaxLengthMins));
// Emit session transition events
_sessionEventController ??= StreamController<SessionEvent>.broadcast();
_sessionEventController!.add(SessionEvent.sessionEnded(oldSessionId));
_sessionEventController!.add(SessionEvent.sessionCreated(newSessionId));
ObslyLogger.debug('Session transition completed: $oldSessionId → $newSessionId (timeout: ${_sessionMaxLengthMins}min)');
} catch (e) {
ObslyLogger.error('Error completing session transition: $e');
}
}