MentraOS Cloud uses a Manager pattern to organize functionality within UserSessions. Each manager is responsible for a specific domain of functionality, encapsulating related state, logic, and operations. This pattern promotes separation of concerns, maintainability, and testability.
// In AudioManagerprocessAudioData(data: ArrayBuffer) { // Process audio... // Trigger transcription if needed if (this.userSession.transcriptionManager.isActive()) { this.userSession.transcriptionManager.processAudio(data); }}
// In TranscriptionManageronTranscriptionComplete(text: string) { // Emit event that other managers can listen to this.emit('transcription', { text, timestamp: Date.now() });}
Managers are created when UserSession is instantiated:
Copy
// In UserSession constructorthis.appManager = new AppManager(this);this.audioManager = new AudioManager(this);this.displayManager = new DisplayManager(this);// ... other managers