The UserSession class is the central object that represents an active user connection in MentraOS Cloud. It encapsulates all session-related state, managers, and functionality for a single user, serving as the hub for all user interactions.File: packages/cloud/src/services/session/UserSession.ts
When glasses reconnect, the existing session is updated:
Copy
updateWebSocket(newWebSocket: WebSocket): void { this.logger.info(`Updating WebSocket connection for user ${this.userId}`); // Clear old heartbeat this.clearGlassesHeartbeat(); // Update WebSocket reference this.websocket = newWebSocket; // Set up new heartbeat this.setupGlassesHeartbeat();}
// Get session by user IDstatic getById(userId: string): UserSession | undefined { return SessionStorage.getInstance().get(userId);}// Get all active sessionsstatic getAllSessions(): UserSession[] { return SessionStorage.getInstance().getAllSessions();}