Skip to main content

EventManager

The EventManager handles event subscriptions and dispatching within a AppSession. It provides methods for subscribing to various event types from the MentraOS platform. You access the EventManager through the events property of a AppSession instance:

Event Handler Methods

onTranscription()

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

onHeadPosition()

Registers a handler for head position change events.
Parameters:
  • handler: Callback function that receives HeadPosition objects
Returns: An unsubscribe function to remove the handler Example:

onButtonPress()

Registers a handler for hardware button press events on the glasses.
Parameters:
  • handler: Callback function that receives ButtonPress objects
Returns: An unsubscribe function to remove the handler Example:

onPhoneNotifications()

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

onGlassesBattery()

Registers a handler for glasses battery update events.
Parameters: Returns: An unsubscribe function to remove the handler Example:

onPhoneBattery()

Registers a handler for phone battery update events.
Parameters: Returns: An unsubscribe function to remove the handler

onVoiceActivity()

Registers a handler for Voice Activity Detection (VAD) events.
Parameters:
  • handler: Callback function that receives Vad objects
Returns: An unsubscribe function to remove the handler Example:

onLocation()

An event handler for raw location updates. Use the LocationManager to access location data, as it provides a simple interface for both streaming and polling.
Parameters: Returns: An unsubscribe function to remove the handler

onCalendarEvent()

Registers a handler for calendar event notifications.
Parameters: Returns: An unsubscribe function to remove the handler

onAudioChunk()

Registers a handler for raw audio data chunks. Requires explicit subscription.
Parameters:
  • handler: Callback function that receives AudioChunk objects
Returns: An unsubscribe function to remove the handler Note: Audio chunks require an explicit subscription using appSession.subscribe(StreamType.AUDIO_CHUNK).

System Event Handlers

onConnected()

Registers a handler for when the WebSocket connection is successfully established and authenticated.
Parameters:
  • handler: Callback function that receives optional AppSettings upon connection
Returns: An unsubscribe function to remove the handler Example:

onDisconnected()

Registers a handler for when the WebSocket connection is closed or lost.
Parameters:
  • handler: Callback function that receives a reason string
Returns: An unsubscribe function to remove the handler Example:

onError()

Registers a handler for WebSocket or SDK-level errors.
Parameters:
  • handler: Callback function that receives a WebSocketError or standard Error object
Returns: An unsubscribe function to remove the handler Example:

onSettingsUpdate()

Registers a handler for when the application settings are updated by the user via MentraOS Cloud.
Parameters:
  • handler: Callback function that receives the complete updated AppSettings array
Returns: An unsubscribe function to remove the handler Example:

onSettingChange()

Registers a handler that triggers only when a specific setting’s value changes.
Parameters:
  • key: The key of the setting to monitor
  • handler: Callback function that receives the new value and the previous value (or undefined initially)
Returns: An unsubscribe function to remove the handler Example:

Generic Event Handler

on()

Generic event handler for any StreamType. Use specific methods above where possible.
Parameters:
  • type: The StreamType to listen for
  • handler: Callback function that receives data of the appropriate type for the specified StreamType
Returns: An unsubscribe function to remove the handler Example: