import { TurboModule } from 'react-native'; import { AudioDevicesInfo, AudioFocusType, PermissionStatus, } from '../system/types'; // copy of spec from NativeAudioAPIModule.ts type OptionsMap = { [key: string]: string | boolean | number | undefined; }; type NotificationOpResponse = { success: boolean; error?: string }; type NotificationType = 'playback' | 'recording' | 'simple'; interface Spec extends TurboModule { install(): boolean; getDevicePreferredSampleRate(): number; // AVAudioSession management setAudioSessionActivity(enabled: boolean): Promise; setAudioSessionOptions( category: string, mode: string, options: Array, allowHaptics: boolean, notifyOthersOnDeactivation: boolean ): void; disableSessionManagement(): void; // Remote commands, system events and interruptions observeAudioInterruptions(focusType: AudioFocusType, enabled: boolean): void; activelyReclaimSession(enabled: boolean): void; observeVolumeChanges(enabled: boolean): void; // Permissions requestRecordingPermissions(): Promise; checkRecordingPermissions(): Promise; requestNotificationPermissions(): Promise; checkNotificationPermissions(): Promise; // Audio devices getDevicesInfo(): Promise; setInputDevice(deviceId: string): Promise; // New notification system showNotification( type: NotificationType, key: string, options: OptionsMap ): Promise; hideNotification(key: string): Promise; isNotificationActive(key: string): Promise; readAndroidReleaseAssetBytesAsBase64(assetPath: string): Promise; } const mockAsync = (value: T) => () => Promise.resolve(value); const mockSync = (value: T) => () => value; const NativeAudioAPIModule: Spec = { install: mockSync(true), getDevicePreferredSampleRate: mockSync(0), setAudioSessionActivity: mockAsync(true), setAudioSessionOptions: mockSync({}), disableSessionManagement: mockSync({}), observeAudioInterruptions: mockSync({}), activelyReclaimSession: mockSync({}), observeVolumeChanges: mockSync({}), requestRecordingPermissions: mockAsync('Granted' as PermissionStatus), checkRecordingPermissions: mockAsync('Granted' as PermissionStatus), requestNotificationPermissions: mockAsync('Granted' as PermissionStatus), checkNotificationPermissions: mockAsync('Granted' as PermissionStatus), getDevicesInfo: mockAsync({ availableInputs: [], availableOutputs: [], currentInputs: [], currentOutputs: [], }), setInputDevice: mockAsync(true), showNotification: mockAsync({ success: true }), hideNotification: mockAsync({ success: true }), isNotificationActive: mockAsync(false), readAndroidReleaseAssetBytesAsBase64: () => Promise.reject( new Error('readAndroidReleaseAssetBytesAsBase64 is not supported on web') ), }; export { NativeAudioAPIModule };