/** * Notification Center for React Native * Mimics the Swift NotificationCenter functionality */ export interface NotificationInfo { [key: string]: any; } export interface NotificationObserver { name: string; callback: (info: NotificationInfo) => void; } export class NotificationCenter { private static instance: NotificationCenter; private observers: Map = new Map(); public static getInstance(): NotificationCenter { if (!NotificationCenter.instance) { NotificationCenter.instance = new NotificationCenter(); } return NotificationCenter.instance; } public addObserver(name: string, callback: (info: NotificationInfo) => void): void { if (!this.observers.has(name)) { this.observers.set(name, []); } this.observers.get(name)!.push({ name, callback }); } public removeObserver(name: string, callback?: (info: NotificationInfo) => void): void { if (!this.observers.has(name)) return; if (callback) { const observers = this.observers.get(name)!; const index = observers.findIndex(obs => obs.callback === callback); if (index !== -1) { observers.splice(index, 1); } } else { this.observers.delete(name); } } public post(name: string, object: any = null, userInfo: NotificationInfo = {}): void { if (!this.observers.has(name)) return; const observers = this.observers.get(name)!; observers.forEach(observer => { try { observer.callback(userInfo); } catch (error) { console.error(`🎯 NotificationCenter: Error in observer for ${name}:`, error); } }); } } // Notification names matching Swift version export const NotificationNames = { toneListenSpectrumDidUpdate: 'toneListenSpectrumDidUpdate', toneListenFullSpectrumDidUpdate: 'toneListenFullSpectrumDidUpdate', toneListenAmplitudeDidUpdate: 'toneListenAmplitudeDidUpdate', toneListenFrequencyDidUpdate: 'toneListenFrequencyDidUpdate', toneListenSequenceDidUpdate: 'toneListenSequenceDidUpdate' } as const;