Let’s follow a user named Alex as they open the MentraOS mobile app and connect their smart glasses to the cloud. This journey shows how authentication works and how WebSocket connections are established.
Mobile app must send CONNECTION_INIT within 30 seconds:
Copy
// From mobile app (defined in glasses-to-cloud.ts:15-19){ type: "CONNECTION_INIT", userId?: "alex@example.com", // Optional user ID coreToken?: "eyJhbGci..." // Optional auth token}
Cloud responds with CONNECTION_ACK:
Copy
// From cloud (defined in cloud-to-glasses.ts:19-23)// Sent from websocket-glasses.service.ts:558-566{ type: "CONNECTION_ACK", sessionId: "alex-123456", // Unique session ID userSession: { // Partial<UserSession> from transformUserSessionForClient userId: "alex@example.com", startTime: "2024-01-01T00:00:00Z", activeAppSessions: ["com.app1", "com.app2"], loadingApps: [], appSubscriptions: { "com.app1": ["audio", "transcription"], "com.app2": ["notification"] }, requiresAudio: true, minimumTranscriptionLanguages: ["en-US"], isTranscribing: true }, timestamp: "2024-01-01T00:00:00Z"}
Now that Alex is connected, the cloud creates a UserSession for them. This session is their personal command center in the cloud. Let’s explore UserSessions next!