Skip to main content

AppSession

AppSession (also known as TpaSession in older versions) manages an active WebSocket connection (session) between an app instance and MentraOS Cloud. It handles event subscriptions, layout display, and connection management for a single user session.

Constructor

Parameters:

Properties

events

Provides access to the EventManager for subscribing to real-time events.

layouts

Provides access to the LayoutManager for controlling the AR display.

settings

Provides access to the SettingsManager for reading and monitoring app settings.

dashboard

Provides access to the DashboardAPI for sending content to the user’s dashboard.
The dashboard is a persistent UI surface that appears when users look up, allowing your app to display status updates and information even when other apps are active. See the Dashboard Tutorial for a quick start guide and the Dashboard API Reference for complete documentation.

capabilities

Provides access to the device capabilities of the connected smart glasses.
The capabilities object contains information about what hardware features are available on the connected device, allowing your app to adapt its behavior accordingly. See the Device Capabilities Guide for usage examples and the Capabilities Reference for complete type documentation.

logger

Provides access to a pre-configured Pino logger instance for session-specific logging.
The logger is automatically configured with session context including:
  • userId: The current user’s identifier
  • packageName: Your app’s package name
  • sessionId: The current session identifier
  • service: Set to ‘app-session’
Example:
Log Levels:
  • session.logger.debug(): Detailed debugging information
  • session.logger.info(): General information about app operation
  • session.logger.warn(): Warning conditions that don’t stop execution
  • session.logger.error(): Error conditions that should be investigated
Structured Logging:

Event Handling Methods

onTranscription()

Registers a handler for real-time speech transcription events.
Parameters: Returns: An unsubscribe function to remove the handler

onHeadPosition()

Registers a handler for head position change events (e.g., ‘up’, ‘down’).
Parameters: Returns: An unsubscribe function to remove the handler

onButtonPress()

Registers a handler for hardware button press events on the glasses.
Parameters:
  • handler: Callback function to process ButtonPress data
Returns: An unsubscribe function to remove the handler

onPhoneNotifications()

Registers a handler for notifications received from the connected phone.
Parameters: Returns: An unsubscribe function to remove the handler

Subscription Methods

subscribe()

Informs the MentraOS Cloud that this app session wants to receive events of the specified type.
Parameters:

on()

Generic method to subscribe to any data stream type. Use specific on<EventType> methods where available.
Parameters:
  • event: The StreamType to listen for
  • handler: Callback function to process the data associated with the stream type
Returns: An unsubscribe function to remove the handler

Connection Methods

connect()

Establishes the WebSocket connection to MentraOS Cloud for this session.
Parameters:
  • sessionId: The unique identifier for this session (provided by the SESSION_REQUEST webhook)
Returns: A promise that resolves upon successful connection and authentication, or rejects on failure

disconnect()

Gracefully closes the WebSocket connection and cleans up resources for this session.

Settings Methods

getSettings()

Retrieves all current application settings for this user session.
Returns: A copy of the current AppSettings

getSetting()

Retrieves the value of a specific application setting by its key.
Parameters:
  • key: The key of the setting to retrieve
Returns: The value of the setting, or undefined if not found or not set

setSubscriptionSettings()

Configures the app session to automatically manage subscriptions based on changes to specific settings.
Parameters:
  • options: Configuration object
    • options.updateOnChange: An array of setting keys that should trigger a subscription update when their value changes
    • options.handler: A function that takes the current AppSettings and returns an array of StreamType subscriptions that should be active

Configuration