Message Types
This page documents the WebSocket message interfaces used for real-time communication in the MentraOS SDK.BaseMessage
The fundamental structure for all messages exchanged within the MentraOS system.App to Cloud Messages
AppConnectionInit
Message sent by App to initiate connection with cloud.appSession.connect()
is called.
AppSubscriptionUpdate
Message sent by App to update its active event subscriptions.appSession.subscribe()
is called or when subscription settings change.
DisplayRequest
Message sent from a App to request displaying a layout. Covered in detail in the Layout Types section.appSession.layouts
methods.
DashboardContentUpdate
Message sent from a App to update dashboard content.session.dashboard.content
methods.
Cloud to App Messages
AppConnectionAck
Message sent by cloud to App confirming successful connection and providing initial settings/config.onConnected
event handler with the settings.
AppConnectionError
Message sent by cloud to App indicating a connection failure.AppStopped
Message sent by cloud to App indicating the session has been stopped.onDisconnected
event handler.
SettingsUpdate
Message sent by cloud to App when the user updates the App’s settings.onSettingsUpdate
event handler.
DataStream
Wrapper message sent by cloud to App carrying data for a subscribed stream.streamType
.
DashboardModeChanged
Message sent by cloud to App when the dashboard mode changes.onModeChange
callbacks with the new mode.
DashboardAlwaysOnChanged
Message sent by cloud to App when the always-on dashboard state changes.Stream Data Messages
Stream data can either be sent wrapped in aDataStream
message or directly as its own message type.
TranscriptionData
Data for real-time speech transcription. See Event Types for details.TranslationData
Data for real-time speech translation. See Event Types for details.AudioChunk
Raw audio data chunk. See Event Types for details.Error-Related Messages
WebSocketError
Structure for reporting WebSocket-specific errors.onError
event handler with this object.
Message Type Enums
Four enums are used to identify the types of messages exchanged between different components:AppToCloudMessageType
Message types sent FROM App TO cloud.CloudToAppMessageType
Message types sent FROM cloud TO App.GlassesToCloudMessageType
Message types sent FROM glasses TO cloud.CloudToGlassesMessageType
Message types sent FROM cloud TO glasses.Type Guards
The SDK provides type guard functions to identify message types:WebSocket Connection Flow
-
Initialization:
- When
appSession.connect()
is called, the SDK establishes a WebSocket connection to the URL provided - It sends a
AppConnectionInit
message with the App’s credentials
- When
-
Authentication:
- The cloud validates the credentials
- If valid, it sends back a
AppConnectionAck
with the user’s settings - If invalid, it sends back a
AppConnectionError
-
Subscribing to Streams:
- The App can call
appSession.subscribe()
to receive specific event types - The SDK sends a
AppSubscriptionUpdate
message to the cloud
- The App can call
-
Receiving Data:
- The cloud sends data for subscribed streams either directly or wrapped in a
DataStream
message - The SDK dispatches this data to the appropriate event handlers
- The cloud sends data for subscribed streams either directly or wrapped in a
-
Session Termination:
- When a session is stopped, the cloud sends an
AppStopped
message - The SDK handles cleanup and fires the
onDisconnected
event handler
- When a session is stopped, the cloud sends an