@siteed/expo-audio-studio 2.12.3 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -1
- package/android/build.gradle +11 -0
- package/android/src/main/AndroidManifest.xml +8 -0
- package/android/src/main/java/net/siteed/audiostream/AudioDeviceManager.kt +266 -42
- package/android/src/main/java/net/siteed/audiostream/ExpoAudioStreamModule.kt +55 -1
- package/app.plugin.js +3 -1
- package/build/cjs/AudioDeviceManager.js +225 -40
- package/build/cjs/AudioDeviceManager.js.map +1 -1
- package/build/cjs/hooks/useAudioDevices.js +30 -5
- package/build/cjs/hooks/useAudioDevices.js.map +1 -1
- package/build/cjs/useAudioRecorder.js +52 -8
- package/build/cjs/useAudioRecorder.js.map +1 -1
- package/build/esm/AudioDeviceManager.js +225 -40
- package/build/esm/AudioDeviceManager.js.map +1 -1
- package/build/esm/hooks/useAudioDevices.js +31 -6
- package/build/esm/hooks/useAudioDevices.js.map +1 -1
- package/build/esm/useAudioRecorder.js +53 -9
- package/build/esm/useAudioRecorder.js.map +1 -1
- package/build/types/AudioDeviceManager.d.ts +78 -2
- package/build/types/AudioDeviceManager.d.ts.map +1 -1
- package/build/types/hooks/useAudioDevices.d.ts +1 -0
- package/build/types/hooks/useAudioDevices.d.ts.map +1 -1
- package/build/types/useAudioRecorder.d.ts.map +1 -1
- package/ios/AudioDeviceManager.swift +21 -9
- package/ios/ExpoAudioStreamModule.swift +33 -1
- package/package.json +8 -6
- package/plugin/build/index.cjs +194 -0
- package/plugin/build/index.d.cts +1 -0
- package/plugin/build/index.js +7 -6
- package/plugin/src/index.ts +8 -8
- package/src/AudioDeviceManager.ts +286 -59
- package/src/hooks/useAudioDevices.ts +39 -6
- package/src/useAudioRecorder.tsx +102 -9
|
@@ -47,48 +47,88 @@ function mapRawDeviceToAudioDevice(rawDevice) {
|
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* Class that provides a cross-platform API for managing audio input devices
|
|
50
|
+
*
|
|
51
|
+
* EVENT API SPECIFICATION:
|
|
52
|
+
* ========================
|
|
53
|
+
*
|
|
54
|
+
* Device Events (deviceChangedEvent):
|
|
55
|
+
* {
|
|
56
|
+
* type: "deviceConnected" | "deviceDisconnected",
|
|
57
|
+
* deviceId: string
|
|
58
|
+
* }
|
|
59
|
+
*
|
|
60
|
+
* Recording Interruption Events (recordingInterruptedEvent):
|
|
61
|
+
* {
|
|
62
|
+
* reason: "userPaused" | "userResumed" | "audioFocusLoss" | "audioFocusGain" |
|
|
63
|
+
* "deviceFallback" | "deviceSwitchFailed" | "phoneCall" | "phoneCallEnded",
|
|
64
|
+
* isPaused: boolean,
|
|
65
|
+
* timestamp: number
|
|
66
|
+
* }
|
|
67
|
+
*
|
|
68
|
+
* NOTE: Device events use "type" field, interruption events use "reason" field.
|
|
69
|
+
* This is intentional to distinguish between different event categories.
|
|
50
70
|
*/
|
|
51
71
|
class AudioDeviceManager {
|
|
52
72
|
eventEmitter;
|
|
53
73
|
currentDeviceId = null;
|
|
54
74
|
availableDevices = [];
|
|
55
75
|
deviceChangeListeners = new Set();
|
|
56
|
-
|
|
76
|
+
webDeviceChangeHandler;
|
|
57
77
|
lastRefreshTime = 0;
|
|
58
78
|
refreshInProgress = false;
|
|
59
79
|
refreshDebounceMs = 500; // Minimum 500ms between refreshes
|
|
60
80
|
logger;
|
|
81
|
+
// Track temporarily disconnected devices
|
|
82
|
+
temporarilyDisconnectedDevices = new Set();
|
|
83
|
+
disconnectionTimeouts = new Map();
|
|
84
|
+
DISCONNECTION_TIMEOUT_MS = 5000; // 5 seconds
|
|
61
85
|
constructor(options) {
|
|
62
86
|
this.eventEmitter = new expo_modules_core_1.EventEmitter(ExpoAudioStreamModule_1.default);
|
|
63
87
|
this.logger = options?.logger;
|
|
64
|
-
//
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
// Update the last event tracking
|
|
79
|
-
lastEventType = event.type;
|
|
80
|
-
lastEventTime = now;
|
|
81
|
-
// Only refresh on meaningful events
|
|
82
|
-
if (event.type === 'deviceConnected' ||
|
|
83
|
-
event.type === 'deviceDisconnected' ||
|
|
84
|
-
event.type === 'routeChanged') {
|
|
85
|
-
this.logger?.debug(`Processing device event: ${event.type}`);
|
|
86
|
-
// Refresh devices and notify listeners regardless of the direct return value
|
|
87
|
-
this.refreshDevices();
|
|
88
|
-
}
|
|
89
|
-
});
|
|
88
|
+
// Set up device event listeners for all platforms immediately
|
|
89
|
+
this.setupDeviceEventListeners();
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Set up device event listeners for the current platform
|
|
93
|
+
*/
|
|
94
|
+
setupDeviceEventListeners() {
|
|
95
|
+
if (react_native_1.Platform.OS === 'web') {
|
|
96
|
+
this.setupWebDeviceChangeListener();
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
this.setupNativeDeviceEventListener();
|
|
90
100
|
}
|
|
91
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Set up native device event listener for iOS/Android
|
|
104
|
+
*/
|
|
105
|
+
setupNativeDeviceEventListener() {
|
|
106
|
+
// Store the last event type to avoid duplicates
|
|
107
|
+
let lastEventType = null;
|
|
108
|
+
let lastEventTime = 0;
|
|
109
|
+
this.eventEmitter.addListener('deviceChangedEvent', (event) => {
|
|
110
|
+
// Skip processing duplicate events that occur too close together
|
|
111
|
+
const now = Date.now();
|
|
112
|
+
const isSimilarEvent = lastEventType === event.type &&
|
|
113
|
+
now - lastEventTime < this.refreshDebounceMs;
|
|
114
|
+
if (isSimilarEvent) {
|
|
115
|
+
this.logger?.debug(`Skipping similar device event (${event.type}) received too soon`);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
// Update the last event tracking
|
|
119
|
+
lastEventType = event.type;
|
|
120
|
+
lastEventTime = now;
|
|
121
|
+
// Only refresh on meaningful events
|
|
122
|
+
if (event.type === 'deviceConnected' ||
|
|
123
|
+
event.type === 'deviceDisconnected' ||
|
|
124
|
+
event.type === 'routeChanged') {
|
|
125
|
+
this.logger?.debug(`Processing device event: ${event.type}`);
|
|
126
|
+
// Force refresh for device events to ensure fresh data
|
|
127
|
+
this.forceRefreshDevices();
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
this.logger?.debug('Native device event listener set up');
|
|
131
|
+
}
|
|
92
132
|
/**
|
|
93
133
|
* Initialize the device manager with a logger
|
|
94
134
|
* @param logger A logger instance that implements the ConsoleLike interface
|
|
@@ -105,6 +145,29 @@ class AudioDeviceManager {
|
|
|
105
145
|
setLogger(logger) {
|
|
106
146
|
this.logger = logger;
|
|
107
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Initialize or reinitialize device detection
|
|
150
|
+
* Useful for restarting device detection if initial setup failed
|
|
151
|
+
*/
|
|
152
|
+
initializeDeviceDetection() {
|
|
153
|
+
this.logger?.debug('Initializing device detection...');
|
|
154
|
+
// Clean up existing listeners first
|
|
155
|
+
if (react_native_1.Platform.OS === 'web' && this.webDeviceChangeHandler) {
|
|
156
|
+
if (typeof navigator !== 'undefined' && navigator.mediaDevices) {
|
|
157
|
+
navigator.mediaDevices.removeEventListener('devicechange', this.webDeviceChangeHandler);
|
|
158
|
+
}
|
|
159
|
+
this.webDeviceChangeHandler = undefined;
|
|
160
|
+
}
|
|
161
|
+
// Re-setup device event listeners
|
|
162
|
+
this.setupDeviceEventListeners();
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Get the current logger instance
|
|
166
|
+
* @returns The logger instance or undefined if not set
|
|
167
|
+
*/
|
|
168
|
+
getLogger() {
|
|
169
|
+
return this.logger;
|
|
170
|
+
}
|
|
108
171
|
/**
|
|
109
172
|
* Get all available audio input devices
|
|
110
173
|
* @param options Optional settings to force refresh the device list. Can include a refresh flag.
|
|
@@ -246,6 +309,122 @@ class AudioDeviceManager {
|
|
|
246
309
|
this.deviceChangeListeners.delete(listener);
|
|
247
310
|
};
|
|
248
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* Mark a device as temporarily disconnected (for UI filtering)
|
|
314
|
+
* @param deviceId The ID of the device that was disconnected
|
|
315
|
+
* @param notify Whether to notify listeners immediately (default: true)
|
|
316
|
+
*/
|
|
317
|
+
markDeviceAsDisconnected(deviceId, notify = true) {
|
|
318
|
+
this.logger?.debug(`Marking device ${deviceId} as temporarily disconnected`);
|
|
319
|
+
// Clear any existing timeout for this device
|
|
320
|
+
const existingTimeout = this.disconnectionTimeouts.get(deviceId);
|
|
321
|
+
if (existingTimeout) {
|
|
322
|
+
clearTimeout(existingTimeout);
|
|
323
|
+
}
|
|
324
|
+
// Add to disconnected set
|
|
325
|
+
this.temporarilyDisconnectedDevices.add(deviceId);
|
|
326
|
+
// Set timeout to remove from disconnected set
|
|
327
|
+
const timeout = setTimeout(() => {
|
|
328
|
+
this.logger?.debug(`Reconnection timeout expired for device ${deviceId}`);
|
|
329
|
+
this.temporarilyDisconnectedDevices.delete(deviceId);
|
|
330
|
+
this.disconnectionTimeouts.delete(deviceId);
|
|
331
|
+
// Refresh devices to show the device again if it's still available
|
|
332
|
+
this.forceRefreshDevices();
|
|
333
|
+
}, this.DISCONNECTION_TIMEOUT_MS);
|
|
334
|
+
this.disconnectionTimeouts.set(deviceId, timeout);
|
|
335
|
+
// Only notify listeners if requested
|
|
336
|
+
if (notify) {
|
|
337
|
+
this.notifyListeners();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Mark a device as reconnected (remove from disconnected set)
|
|
342
|
+
* @param deviceId The ID of the device that was reconnected
|
|
343
|
+
*/
|
|
344
|
+
markDeviceAsReconnected(deviceId) {
|
|
345
|
+
this.logger?.debug(`Marking device ${deviceId} as reconnected`);
|
|
346
|
+
// Clear timeout and remove from disconnected set
|
|
347
|
+
const timeout = this.disconnectionTimeouts.get(deviceId);
|
|
348
|
+
if (timeout) {
|
|
349
|
+
clearTimeout(timeout);
|
|
350
|
+
this.disconnectionTimeouts.delete(deviceId);
|
|
351
|
+
}
|
|
352
|
+
this.temporarilyDisconnectedDevices.delete(deviceId);
|
|
353
|
+
// Notify listeners with updated device list
|
|
354
|
+
this.notifyListeners();
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Get filtered device list (excluding temporarily disconnected devices)
|
|
358
|
+
* @returns Array of available devices excluding temporarily disconnected ones
|
|
359
|
+
*/
|
|
360
|
+
getFilteredDevices() {
|
|
361
|
+
if (this.temporarilyDisconnectedDevices.size === 0) {
|
|
362
|
+
return [...this.availableDevices];
|
|
363
|
+
}
|
|
364
|
+
const filtered = this.availableDevices.filter((device) => !this.temporarilyDisconnectedDevices.has(device.id));
|
|
365
|
+
this.logger?.debug(`Filtered ${this.availableDevices.length - filtered.length} temporarily disconnected devices. ` +
|
|
366
|
+
`Showing ${filtered.length} devices.`);
|
|
367
|
+
return filtered;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Get the raw device list (including temporarily disconnected devices)
|
|
371
|
+
* @returns Array of all available devices from native layer
|
|
372
|
+
*/
|
|
373
|
+
getRawDevices() {
|
|
374
|
+
return [...this.availableDevices];
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Get the IDs of temporarily disconnected devices
|
|
378
|
+
* @returns Set of device IDs that are temporarily hidden from UI
|
|
379
|
+
*/
|
|
380
|
+
getTemporarilyDisconnectedDeviceIds() {
|
|
381
|
+
return new Set(this.temporarilyDisconnectedDevices);
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Clean up timeouts and listeners (useful for testing or cleanup)
|
|
385
|
+
*/
|
|
386
|
+
cleanup() {
|
|
387
|
+
// Clear all disconnection timeouts
|
|
388
|
+
this.disconnectionTimeouts.forEach((timeout) => clearTimeout(timeout));
|
|
389
|
+
this.disconnectionTimeouts.clear();
|
|
390
|
+
this.temporarilyDisconnectedDevices.clear();
|
|
391
|
+
// Clear device change listeners
|
|
392
|
+
this.deviceChangeListeners.clear();
|
|
393
|
+
// Clean up web device listener
|
|
394
|
+
if (react_native_1.Platform.OS === 'web' && this.webDeviceChangeHandler) {
|
|
395
|
+
if (typeof navigator !== 'undefined' && navigator.mediaDevices) {
|
|
396
|
+
navigator.mediaDevices.removeEventListener('devicechange', this.webDeviceChangeHandler);
|
|
397
|
+
}
|
|
398
|
+
this.webDeviceChangeHandler = undefined;
|
|
399
|
+
}
|
|
400
|
+
this.logger?.debug('AudioDeviceManager cleanup completed');
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Force refresh devices without debouncing (for device events)
|
|
404
|
+
* @returns Promise resolving to the updated device list (AudioDevice[])
|
|
405
|
+
*/
|
|
406
|
+
async forceRefreshDevices() {
|
|
407
|
+
this.logger?.debug('Force refreshing devices (bypassing debounce)...');
|
|
408
|
+
this.refreshInProgress = true;
|
|
409
|
+
try {
|
|
410
|
+
// Force fetch the latest devices from native layer
|
|
411
|
+
const devices = await this.getAvailableDevices({ refresh: true });
|
|
412
|
+
// Update internal state
|
|
413
|
+
this.availableDevices = devices;
|
|
414
|
+
// Notify listeners with fresh data
|
|
415
|
+
this.notifyListeners();
|
|
416
|
+
this.lastRefreshTime = Date.now();
|
|
417
|
+
return devices;
|
|
418
|
+
}
|
|
419
|
+
catch (error) {
|
|
420
|
+
this.logger?.error('Error during forceRefreshDevices:', error);
|
|
421
|
+
return this.availableDevices;
|
|
422
|
+
}
|
|
423
|
+
finally {
|
|
424
|
+
this.refreshInProgress = false;
|
|
425
|
+
this.logger?.debug('Force refresh finished.');
|
|
426
|
+
}
|
|
427
|
+
}
|
|
249
428
|
/**
|
|
250
429
|
* Refresh the list of available devices with debouncing and notify listeners.
|
|
251
430
|
* @returns Promise resolving to the updated device list (AudioDevice[])
|
|
@@ -332,7 +511,6 @@ class AudioDeviceManager {
|
|
|
332
511
|
if (finalDevices.length === 0) {
|
|
333
512
|
finalDevices = [DEFAULT_DEVICE];
|
|
334
513
|
}
|
|
335
|
-
this.setupWebDeviceChangeListener();
|
|
336
514
|
this.availableDevices = finalDevices; // Update internal state
|
|
337
515
|
return finalDevices;
|
|
338
516
|
}
|
|
@@ -371,18 +549,24 @@ class AudioDeviceManager {
|
|
|
371
549
|
setupWebDeviceChangeListener() {
|
|
372
550
|
if (typeof navigator === 'undefined' ||
|
|
373
551
|
!navigator.mediaDevices ||
|
|
374
|
-
this.
|
|
552
|
+
this.webDeviceChangeHandler // Avoid adding multiple listeners
|
|
375
553
|
) {
|
|
554
|
+
this.logger?.debug('Web device change listener not available or already set up');
|
|
376
555
|
return;
|
|
377
556
|
}
|
|
378
|
-
|
|
379
|
-
this.
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
557
|
+
try {
|
|
558
|
+
this.webDeviceChangeHandler = () => {
|
|
559
|
+
this.logger?.debug('Web device change detected, refreshing device list');
|
|
560
|
+
// Force refresh to get immediate updates
|
|
561
|
+
this.forceRefreshDevices();
|
|
562
|
+
};
|
|
563
|
+
navigator.mediaDevices.addEventListener('devicechange', this.webDeviceChangeHandler);
|
|
564
|
+
this.logger?.debug('Web device change listener successfully set up');
|
|
565
|
+
}
|
|
566
|
+
catch (error) {
|
|
567
|
+
this.logger?.warn('Failed to set up web device change listener:', error);
|
|
568
|
+
this.webDeviceChangeHandler = undefined;
|
|
569
|
+
}
|
|
386
570
|
}
|
|
387
571
|
/**
|
|
388
572
|
* Check if the current browser is Safari or iOS WebKit
|
|
@@ -481,9 +665,10 @@ class AudioDeviceManager {
|
|
|
481
665
|
* Notify all registered listeners about device changes.
|
|
482
666
|
*/
|
|
483
667
|
notifyListeners() {
|
|
484
|
-
// Pass a copy of the
|
|
485
|
-
const devicesCopy =
|
|
486
|
-
this.logger?.debug(`Notifying ${this.deviceChangeListeners.size} listeners with ${devicesCopy.length} devices
|
|
668
|
+
// Pass a copy of the filtered devices array to listeners
|
|
669
|
+
const devicesCopy = this.getFilteredDevices();
|
|
670
|
+
this.logger?.debug(`Notifying ${this.deviceChangeListeners.size} listeners with ${devicesCopy.length} devices ` +
|
|
671
|
+
`(${this.temporarilyDisconnectedDevices.size} temporarily hidden)`);
|
|
487
672
|
this.deviceChangeListeners.forEach((listener) => {
|
|
488
673
|
try {
|
|
489
674
|
listener(devicesCopy);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AudioDeviceManager.js","sourceRoot":"","sources":["../../src/AudioDeviceManager.ts"],"names":[],"mappings":";;;;;;AAAA,yDAAgD;AAChD,+CAAuC;AAEvC,mEAKgC;AAkjBvB,4GApjBL,mDAA2B,OAojBK;AAjjBpC,oFAA2D;AAE3D,4DAA4D;AAC5D,MAAM,cAAc,GAAgB;IAChC,EAAE,EAAE,SAAS;IACb,IAAI,EAAE,oBAAoB;IAC1B,IAAI,EAAE,aAAa;IACnB,SAAS,EAAE,IAAI;IACf,WAAW,EAAE,IAAI;IACjB,YAAY,EAAE;QACV,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC;QAClC,aAAa,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;QACrB,SAAS,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;QACvB,mBAAmB,EAAE,IAAI;QACzB,mBAAmB,EAAE,IAAI;QACzB,uBAAuB,EAAE,IAAI;KAChC;CACJ,CAAA;AAED,6DAA6D;AAC7D,gEAAgE;AAChE,SAAS,yBAAyB,CAAC,SAAc;IAC7C,MAAM,YAAY,GAAG,SAAS,CAAC,YAAY,IAAI,EAAE,CAAA;IACjD,OAAO;QACH,EAAE,EAAE,SAAS,CAAC,EAAE,IAAI,SAAS;QAC7B,IAAI,EAAE,SAAS,CAAC,IAAI,IAAI,gBAAgB;QACxC,IAAI,EAAE,SAAS,CAAC,IAAI,IAAI,SAAS;QACjC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,kBAAkB,CAAA;QACxE,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;YAAE,OAAO,SAAS,CAAA;QAC9C,OAAO,aAAa,CAAA,CAAC,qBAAqB;IAC9C,CAAC;IAED;;OAEG;IACK,eAAe;QACnB,wDAAwD;QACxD,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,CAAC,gBAAgB,CAAC,CAAA;QAC9C,IAAI,CAAC,MAAM,EAAE,KAAK,CACd,aAAa,IAAI,CAAC,qBAAqB,CAAC,IAAI,mBAAmB,WAAW,CAAC,MAAM,WAAW,CAC/F,CAAA;QACD,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC5C,IAAI,CAAC;gBACD,QAAQ,CAAC,WAAW,CAAC,CAAA;YACzB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAA;YACjE,CAAC;QACL,CAAC,CAAC,CAAA;IACN,CAAC;CACJ;AAhgBD,gDAggBC;AAED,2CAA2C;AAC9B,QAAA,kBAAkB,GAAG,IAAI,kBAAkB,EAAE,CAAA","sourcesContent":["import { EventEmitter } from 'expo-modules-core'\nimport { Platform } from 'react-native'\n\nimport {\n AudioDevice,\n AudioDeviceCapabilities,\n DeviceDisconnectionBehavior,\n ConsoleLike,\n} from './ExpoAudioStream.types'\nimport ExpoAudioStreamModule from './ExpoAudioStreamModule'\n\n// Default device fallback for web and unsupported platforms\nconst DEFAULT_DEVICE: AudioDevice = {\n id: 'default',\n name: 'Default Microphone',\n type: 'builtin_mic',\n isDefault: true,\n isAvailable: true,\n capabilities: {\n sampleRates: [16000, 44100, 48000],\n channelCounts: [1, 2],\n bitDepths: [16, 24, 32],\n hasEchoCancellation: true,\n hasNoiseSuppression: true,\n hasAutomaticGainControl: true,\n },\n}\n\n// Helper function to map raw object to AudioDevice interface\n// This handles potential inconsistencies from the native module\nfunction mapRawDeviceToAudioDevice(rawDevice: any): AudioDevice {\n const capabilities = rawDevice.capabilities || {}\n return {\n id: rawDevice.id || 'unknown',\n name: rawDevice.name || 'Unknown Device',\n type: rawDevice.type || 'unknown',\n isDefault: rawDevice.isDefault || false,\n isAvailable:\n rawDevice.isAvailable !== undefined ? rawDevice.isAvailable : true, // Default to true if undefined\n capabilities: {\n sampleRates: capabilities.sampleRates || [16000, 44100, 48000], // Provide defaults\n channelCounts: capabilities.channelCounts || [1, 2],\n bitDepths: capabilities.bitDepths || [16, 24, 32],\n hasEchoCancellation: capabilities.hasEchoCancellation,\n hasNoiseSuppression: capabilities.hasNoiseSuppression,\n hasAutomaticGainControl: capabilities.hasAutomaticGainControl,\n },\n }\n}\n\n/**\n * Class that provides a cross-platform API for managing audio input devices\n */\nexport class AudioDeviceManager {\n private eventEmitter: InstanceType<typeof EventEmitter>\n private currentDeviceId: string | null = null\n private availableDevices: AudioDevice[] = []\n private deviceChangeListeners: Set<(devices: AudioDevice[]) => void> =\n new Set()\n private deviceListeners: Set<() => void> = new Set()\n private lastRefreshTime: number = 0\n private refreshInProgress: boolean = false\n private refreshDebounceMs: number = 500 // Minimum 500ms between refreshes\n private logger?: ConsoleLike\n\n constructor(options?: { logger?: ConsoleLike }) {\n this.eventEmitter = new EventEmitter(ExpoAudioStreamModule)\n this.logger = options?.logger\n\n // Listen for device change events from native modules if not on web\n if (Platform.OS !== 'web') {\n // Store the last event type to avoid duplicates\n let lastEventType: string | null = null\n let lastEventTime = 0\n\n this.eventEmitter.addListener(\n 'deviceChangedEvent',\n (event: any) => {\n // Skip processing duplicate events that occur too close together\n const now = Date.now()\n const isSimilarEvent =\n lastEventType === event.type &&\n now - lastEventTime < this.refreshDebounceMs\n\n if (isSimilarEvent) {\n this.logger?.debug(\n `Skipping similar device event (${event.type}) received too soon`\n )\n return\n }\n\n // Update the last event tracking\n lastEventType = event.type\n lastEventTime = now\n\n // Only refresh on meaningful events\n if (\n event.type === 'deviceConnected' ||\n event.type === 'deviceDisconnected' ||\n event.type === 'routeChanged'\n ) {\n this.logger?.debug(\n `Processing device event: ${event.type}`\n )\n // Refresh devices and notify listeners regardless of the direct return value\n this.refreshDevices()\n }\n }\n )\n }\n }\n\n /**\n * Initialize the device manager with a logger\n * @param logger A logger instance that implements the ConsoleLike interface\n * @returns The manager instance for chaining\n */\n initWithLogger(logger: ConsoleLike): AudioDeviceManager {\n this.setLogger(logger)\n return this\n }\n\n /**\n * Set the logger instance\n * @param logger A logger instance that implements the ConsoleLike interface\n */\n setLogger(logger: ConsoleLike) {\n this.logger = logger\n }\n\n /**\n * Get all available audio input devices\n * @param options Optional settings to force refresh the device list. Can include a refresh flag.\n * @returns Promise resolving to an array of audio devices conforming to AudioDevice interface\n */\n async getAvailableDevices(options?: {\n refresh?: boolean\n }): Promise<AudioDevice[]> {\n try {\n if (Platform.OS === 'web') {\n this.availableDevices = await this.getWebAudioDevices()\n } else if (ExpoAudioStreamModule.getAvailableInputDevices) {\n // Expecting an array of raw device objects from native\n const rawDevices: any[] =\n await ExpoAudioStreamModule.getAvailableInputDevices(\n options\n )\n // Map raw objects to the AudioDevice interface\n this.availableDevices = rawDevices.map(\n mapRawDeviceToAudioDevice\n )\n } else {\n // Fallback for unsupported platforms\n this.availableDevices = [DEFAULT_DEVICE]\n }\n return this.availableDevices\n } catch (error) {\n this.logger?.error('Failed to get available devices:', error)\n this.availableDevices = [DEFAULT_DEVICE] // Ensure state is updated on error\n return this.availableDevices\n }\n }\n\n /**\n * Get the currently selected audio input device\n * @returns Promise resolving to the current device (conforming to AudioDevice) or null\n */\n async getCurrentDevice(): Promise<AudioDevice | null> {\n try {\n if (Platform.OS === 'web') {\n if (!this.currentDeviceId) {\n // On web, return the typed default device if nothing is selected\n return DEFAULT_DEVICE\n }\n // Refresh web devices to ensure the current one is up-to-date\n const webDevices = await this.getWebAudioDevices()\n return (\n webDevices.find((d) => d.id === this.currentDeviceId) ||\n DEFAULT_DEVICE // Fallback to default if current ID not found\n )\n } else if (ExpoAudioStreamModule.getCurrentInputDevice) {\n // Expecting a single raw device object or null from native\n const rawDevice: any | null =\n await ExpoAudioStreamModule.getCurrentInputDevice()\n // Map to AudioDevice interface if not null\n return rawDevice ? mapRawDeviceToAudioDevice(rawDevice) : null\n } else {\n // Fallback for unsupported platforms\n return DEFAULT_DEVICE\n }\n } catch (error) {\n this.logger?.error('Failed to get current device:', error)\n return DEFAULT_DEVICE // Return default on error\n }\n }\n\n /**\n * Select a specific audio input device for recording\n * @param deviceId The ID of the device to select\n * @returns Promise resolving to a boolean indicating success\n */\n async selectDevice(deviceId: string): Promise<boolean> {\n try {\n let success = false\n if (Platform.OS === 'web') {\n // Check if the device exists before setting it\n const devices = await this.getWebAudioDevices()\n if (devices.some((d) => d.id === deviceId)) {\n this.currentDeviceId = deviceId\n success = true\n } else {\n this.logger?.warn(\n `Web: Device with ID ${deviceId} not found.`\n )\n success = false\n }\n } else if (ExpoAudioStreamModule.selectInputDevice) {\n success =\n await ExpoAudioStreamModule.selectInputDevice(deviceId)\n if (success) {\n this.currentDeviceId = deviceId\n }\n }\n // Refresh devices after selection attempt to update state\n await this.refreshDevices()\n return success\n } catch (error) {\n this.logger?.error('Failed to select device:', error)\n await this.refreshDevices() // Refresh even on error\n return false\n }\n }\n\n /**\n * Reset to the default audio input device\n * @returns Promise resolving to a boolean indicating success\n */\n async resetToDefaultDevice(): Promise<boolean> {\n try {\n let success = false\n if (Platform.OS === 'web') {\n this.currentDeviceId = 'default'\n success = true\n } else if (ExpoAudioStreamModule.resetToDefaultDevice) {\n success = await ExpoAudioStreamModule.resetToDefaultDevice()\n if (success) {\n this.currentDeviceId = null\n }\n }\n // Refresh devices after reset attempt\n await this.refreshDevices()\n return success\n } catch (error) {\n this.logger?.error('Failed to reset to default device:', error)\n await this.refreshDevices() // Refresh even on error\n return false\n }\n }\n\n /**\n * Register a listener for device changes\n * @param listener Function to call when devices change (receives AudioDevice[])\n * @returns Function to remove the listener\n */\n addDeviceChangeListener(\n listener: (devices: AudioDevice[]) => void\n ): () => void {\n this.deviceChangeListeners.add(listener)\n\n // Immediately call listener with current devices if available\n if (this.availableDevices.length > 0) {\n listener([...this.availableDevices])\n }\n\n // Return a function to remove the listener\n return () => {\n this.deviceChangeListeners.delete(listener)\n }\n }\n\n /**\n * Refresh the list of available devices with debouncing and notify listeners.\n * @returns Promise resolving to the updated device list (AudioDevice[])\n */\n async refreshDevices(): Promise<AudioDevice[]> {\n const now = Date.now()\n\n if (this.refreshInProgress) {\n this.logger?.debug('Refresh already in progress, skipping')\n return this.availableDevices\n }\n\n // Always allow refresh if forced by native event or longer than 2s debounce\n const timeSinceLastRefresh = now - this.lastRefreshTime\n const shouldDebounce =\n timeSinceLastRefresh < this.refreshDebounceMs &&\n timeSinceLastRefresh < 2000\n\n if (shouldDebounce) {\n this.logger?.debug(\n `Refresh debounced, skipping (last refresh was ${timeSinceLastRefresh}ms ago)`\n )\n return this.availableDevices\n }\n\n this.logger?.debug('Refreshing devices...')\n this.refreshInProgress = true\n try {\n // Fetch the latest devices; getAvailableDevices handles mapping now\n const devices = await this.getAvailableDevices({ refresh: true })\n // availableDevices state is updated within getAvailableDevices\n this.notifyListeners() // Notify listeners with the updated list\n this.lastRefreshTime = Date.now()\n return devices // Return the fetched & mapped list\n } catch (error) {\n this.logger?.error('Error during refreshDevices:', error)\n return this.availableDevices // Return potentially stale list on error\n } finally {\n this.refreshInProgress = false\n this.logger?.debug('Refresh finished.')\n }\n }\n\n /**\n * Get audio input devices using the Web Audio API\n * @returns Promise resolving to an array of AudioDevice objects\n */\n private async getWebAudioDevices(): Promise<AudioDevice[]> {\n if (\n typeof navigator === 'undefined' ||\n !navigator.mediaDevices ||\n !navigator.mediaDevices.enumerateDevices\n ) {\n return [DEFAULT_DEVICE]\n }\n\n try {\n const permissionStatus = await this.checkMicrophonePermission()\n\n if (permissionStatus === 'denied') {\n return [\n {\n ...DEFAULT_DEVICE,\n name: 'Microphone Access Denied',\n isAvailable: false,\n },\n ]\n }\n\n if (permissionStatus !== 'granted') {\n try {\n // Requesting stream often reveals device labels\n await navigator.mediaDevices.getUserMedia({ audio: true })\n } catch (error) {\n this.logger?.warn(\n 'Microphone permission request failed:',\n error\n )\n return [\n {\n ...DEFAULT_DEVICE,\n name: 'Microphone Access Required',\n isAvailable: false,\n },\n ]\n }\n }\n\n const devices = await navigator.mediaDevices.enumerateDevices()\n const audioInputDevices = devices\n .filter((device) => device.kind === 'audioinput')\n .map((device) => this.mapWebDeviceToAudioDevice(device))\n\n const hasUnlabeledDevices = audioInputDevices.some(\n (device) =>\n !device.name || device.name.startsWith('Microphone ')\n )\n\n let finalDevices = audioInputDevices\n if (hasUnlabeledDevices && this.isSafariOrIOS()) {\n finalDevices = this.enhanceDevicesForSafari(audioInputDevices)\n }\n\n if (finalDevices.length === 0) {\n finalDevices = [DEFAULT_DEVICE]\n }\n\n this.setupWebDeviceChangeListener()\n this.availableDevices = finalDevices // Update internal state\n return finalDevices\n } catch (error) {\n this.logger?.error('Failed to enumerate web audio devices:', error)\n this.availableDevices = [DEFAULT_DEVICE] // Update state on error\n return this.availableDevices\n }\n }\n\n /**\n * Check the current microphone permission status\n * @returns Permission state ('prompt', 'granted', or 'denied')\n */\n private async checkMicrophonePermission(): Promise<PermissionState> {\n if (!navigator.permissions || !navigator.permissions.query) {\n return 'prompt'\n }\n try {\n const permissionStatus = await navigator.permissions.query({\n name: 'microphone' as PermissionName,\n })\n permissionStatus.onchange = () => {\n // Refresh devices when permission changes\n this.refreshDevices()\n }\n return permissionStatus.state\n } catch (error) {\n this.logger?.warn('Permission query not supported:', error)\n return 'prompt'\n }\n }\n\n /**\n * Setup listener for device changes in web environment\n */\n private setupWebDeviceChangeListener() {\n if (\n typeof navigator === 'undefined' ||\n !navigator.mediaDevices ||\n this.deviceListeners.size > 0 // Avoid adding multiple listeners\n ) {\n return\n }\n\n const handleDeviceChange = () => {\n this.logger?.debug('Web device change detected.')\n // Refresh devices on change\n this.refreshDevices()\n }\n\n navigator.mediaDevices.addEventListener(\n 'devicechange',\n handleDeviceChange\n )\n this.deviceListeners.add(handleDeviceChange)\n this.logger?.debug('Web device change listener added.')\n }\n\n /**\n * Check if the current browser is Safari or iOS WebKit\n */\n private isSafariOrIOS(): boolean {\n if (typeof navigator === 'undefined') return false\n const ua = navigator.userAgent\n return (\n /^((?!chrome|android).)*safari/i.test(ua) ||\n /iPad|iPhone|iPod/.test(ua) ||\n (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)\n )\n }\n\n /**\n * Create enhanced device information for Safari and privacy-restricted browsers\n * @param devices Array of AudioDevice objects, potentially unlabeled\n * @returns Array of enhanced AudioDevice objects\n */\n private enhanceDevicesForSafari(devices: AudioDevice[]): AudioDevice[] {\n const defaultDevice = devices.find((d) => d.isDefault)\n\n if (devices.length <= 1) {\n // Return a typed default device\n return [\n {\n id: defaultDevice?.id || 'default',\n name: 'Microphone (Browser Managed)',\n type: 'builtin_mic',\n isDefault: true,\n isAvailable: true,\n capabilities:\n defaultDevice?.capabilities ||\n DEFAULT_DEVICE.capabilities,\n },\n ]\n }\n\n // Provide more descriptive names for unlabeled devices\n return devices.map((device, index) => {\n if (!device.name || device.name.startsWith('Microphone ')) {\n const deviceTypes = [\n 'Built-in Microphone',\n 'External Microphone',\n 'Headset Microphone',\n ]\n const typeName = deviceTypes[index % deviceTypes.length]\n return {\n ...device,\n name: device.isDefault ? `${typeName} (Default)` : typeName,\n }\n }\n return device\n })\n }\n\n /**\n * Map a Web MediaDeviceInfo to our AudioDevice format\n * @param device The MediaDeviceInfo object from the browser\n * @returns An object conforming to the AudioDevice interface\n */\n private mapWebDeviceToAudioDevice(device: MediaDeviceInfo): AudioDevice {\n const isDefault = device.deviceId === 'default'\n const deviceType = this.inferDeviceType(device.label || '')\n\n // Provide reasonable default capabilities for web devices\n const defaultWebCapabilities: AudioDeviceCapabilities = {\n sampleRates: [16000, 44100, 48000],\n channelCounts: [1, 2],\n bitDepths: [16, 32], // Web Audio uses float32, common PCM might be 16/32\n hasEchoCancellation: true, // Often handled by browser\n hasNoiseSuppression: true, // Often handled by browser\n hasAutomaticGainControl: true, // Often handled by browser\n }\n\n return {\n id: device.deviceId,\n name:\n device.label || `Microphone ${device.deviceId.substring(0, 8)}`,\n type: deviceType,\n isDefault,\n isAvailable: true, // Assume available if enumerated\n capabilities: defaultWebCapabilities,\n }\n }\n\n /**\n * Try to infer the device type from its name\n * @param deviceName The label of the device\n * @returns A string representing the inferred device type\n */\n private inferDeviceType(deviceName: string): string {\n const name = deviceName.toLowerCase()\n if (name.includes('bluetooth') || name.includes('airpods'))\n return 'bluetooth'\n if (name.includes('usb')) return 'usb'\n if (name.includes('headphone') || name.includes('headset')) {\n return name.includes('wired') ? 'wired_headset' : 'wired_headphones'\n }\n if (name.includes('speaker')) return 'speaker'\n return 'builtin_mic' // Default assumption\n }\n\n /**\n * Notify all registered listeners about device changes.\n */\n private notifyListeners(): void {\n // Pass a copy of the current devices array to listeners\n const devicesCopy = [...this.availableDevices]\n this.logger?.debug(\n `Notifying ${this.deviceChangeListeners.size} listeners with ${devicesCopy.length} devices.`\n )\n this.deviceChangeListeners.forEach((listener) => {\n try {\n listener(devicesCopy)\n } catch (error) {\n this.logger?.error('Error in device change listener:', error)\n }\n })\n }\n}\n\n// Create and export the singleton instance\nexport const audioDeviceManager = new AudioDeviceManager()\n\nexport { DeviceDisconnectionBehavior }\n"]}
|
|
1
|
+
{"version":3,"file":"AudioDeviceManager.js","sourceRoot":"","sources":["../../src/AudioDeviceManager.ts"],"names":[],"mappings":";;;;;;AAAA,yDAAgD;AAChD,+CAAuC;AAEvC,mEAKgC;AAqxBvB,4GAvxBL,mDAA2B,OAuxBK;AApxBpC,oFAA2D;AAE3D,4DAA4D;AAC5D,MAAM,cAAc,GAAgB;IAChC,EAAE,EAAE,SAAS;IACb,IAAI,EAAE,oBAAoB;IAC1B,IAAI,EAAE,aAAa;IACnB,SAAS,EAAE,IAAI;IACf,WAAW,EAAE,IA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AAA","sourcesContent":["import { EventEmitter } from 'expo-modules-core'\nimport { Platform } from 'react-native'\n\nimport {\n AudioDevice,\n AudioDeviceCapabilities,\n DeviceDisconnectionBehavior,\n ConsoleLike,\n} from './ExpoAudioStream.types'\nimport ExpoAudioStreamModule from './ExpoAudioStreamModule'\n\n// Default device fallback for web and unsupported platforms\nconst DEFAULT_DEVICE: AudioDevice = {\n id: 'default',\n name: 'Default Microphone',\n type: 'builtin_mic',\n isDefault: true,\n isAvailable: true,\n capabilities: {\n sampleRates: [16000, 44100, 48000],\n channelCounts: [1, 2],\n bitDepths: [16, 24, 32],\n hasEchoCancellation: true,\n hasNoiseSuppression: true,\n hasAutomaticGainControl: true,\n },\n}\n\n// Helper function to map raw object to AudioDevice interface\n// This handles potential inconsistencies from the native module\nfunction mapRawDeviceToAudioDevice(rawDevice: any): AudioDevice {\n const capabilities = rawDevice.capabilities || {}\n return {\n id: rawDevice.id || 'unknown',\n name: rawDevice.name || 'Unknown Device',\n type: rawDevice.type || 'unknown',\n isDefault: rawDevice.isDefault || false,\n isAvailable:\n rawDevice.isAvailable !== undefined ? rawDevice.isAvailable : true, // Default to true if undefined\n capabilities: {\n sampleRates: capabilities.sampleRates || [16000, 44100, 48000], // Provide defaults\n channelCounts: capabilities.channelCounts || [1, 2],\n bitDepths: capabilities.bitDepths || [16, 24, 32],\n hasEchoCancellation: capabilities.hasEchoCancellation,\n hasNoiseSuppression: capabilities.hasNoiseSuppression,\n hasAutomaticGainControl: capabilities.hasAutomaticGainControl,\n },\n }\n}\n\n/**\n * Class that provides a cross-platform API for managing audio input devices\n *\n * EVENT API SPECIFICATION:\n * ========================\n *\n * Device Events (deviceChangedEvent):\n * {\n * type: \"deviceConnected\" | \"deviceDisconnected\",\n * deviceId: string\n * }\n *\n * Recording Interruption Events (recordingInterruptedEvent):\n * {\n * reason: \"userPaused\" | \"userResumed\" | \"audioFocusLoss\" | \"audioFocusGain\" |\n * \"deviceFallback\" | \"deviceSwitchFailed\" | \"phoneCall\" | \"phoneCallEnded\",\n * isPaused: boolean,\n * timestamp: number\n * }\n *\n * NOTE: Device events use \"type\" field, interruption events use \"reason\" field.\n * This is intentional to distinguish between different event categories.\n */\nexport class AudioDeviceManager {\n private eventEmitter: InstanceType<typeof EventEmitter>\n private currentDeviceId: string | null = null\n private availableDevices: AudioDevice[] = []\n private deviceChangeListeners: Set<(devices: AudioDevice[]) => void> =\n new Set()\n private webDeviceChangeHandler?: () => void\n private lastRefreshTime: number = 0\n private refreshInProgress: boolean = false\n private refreshDebounceMs: number = 500 // Minimum 500ms between refreshes\n private logger?: ConsoleLike\n\n // Track temporarily disconnected devices\n private temporarilyDisconnectedDevices: Set<string> = new Set()\n private disconnectionTimeouts: Map<string, NodeJS.Timeout> = new Map()\n private readonly DISCONNECTION_TIMEOUT_MS = 5000 // 5 seconds\n\n constructor(options?: { logger?: ConsoleLike }) {\n this.eventEmitter = new EventEmitter(ExpoAudioStreamModule)\n this.logger = options?.logger\n\n // Set up device event listeners for all platforms immediately\n this.setupDeviceEventListeners()\n }\n\n /**\n * Set up device event listeners for the current platform\n */\n private setupDeviceEventListeners(): void {\n if (Platform.OS === 'web') {\n this.setupWebDeviceChangeListener()\n } else {\n this.setupNativeDeviceEventListener()\n }\n }\n\n /**\n * Set up native device event listener for iOS/Android\n */\n private setupNativeDeviceEventListener(): void {\n // Store the last event type to avoid duplicates\n let lastEventType: string | null = null\n let lastEventTime = 0\n\n this.eventEmitter.addListener('deviceChangedEvent', (event: any) => {\n // Skip processing duplicate events that occur too close together\n const now = Date.now()\n const isSimilarEvent =\n lastEventType === event.type &&\n now - lastEventTime < this.refreshDebounceMs\n\n if (isSimilarEvent) {\n this.logger?.debug(\n `Skipping similar device event (${event.type}) received too soon`\n )\n return\n }\n\n // Update the last event tracking\n lastEventType = event.type\n lastEventTime = now\n\n // Only refresh on meaningful events\n if (\n event.type === 'deviceConnected' ||\n event.type === 'deviceDisconnected' ||\n event.type === 'routeChanged'\n ) {\n this.logger?.debug(`Processing device event: ${event.type}`)\n // Force refresh for device events to ensure fresh data\n this.forceRefreshDevices()\n }\n })\n this.logger?.debug('Native device event listener set up')\n }\n\n /**\n * Initialize the device manager with a logger\n * @param logger A logger instance that implements the ConsoleLike interface\n * @returns The manager instance for chaining\n */\n initWithLogger(logger: ConsoleLike): AudioDeviceManager {\n this.setLogger(logger)\n return this\n }\n\n /**\n * Set the logger instance\n * @param logger A logger instance that implements the ConsoleLike interface\n */\n setLogger(logger: ConsoleLike) {\n this.logger = logger\n }\n\n /**\n * Initialize or reinitialize device detection\n * Useful for restarting device detection if initial setup failed\n */\n initializeDeviceDetection(): void {\n this.logger?.debug('Initializing device detection...')\n\n // Clean up existing listeners first\n if (Platform.OS === 'web' && this.webDeviceChangeHandler) {\n if (typeof navigator !== 'undefined' && navigator.mediaDevices) {\n navigator.mediaDevices.removeEventListener(\n 'devicechange',\n this.webDeviceChangeHandler\n )\n }\n this.webDeviceChangeHandler = undefined\n }\n\n // Re-setup device event listeners\n this.setupDeviceEventListeners()\n }\n\n /**\n * Get the current logger instance\n * @returns The logger instance or undefined if not set\n */\n getLogger(): ConsoleLike | undefined {\n return this.logger\n }\n\n /**\n * Get all available audio input devices\n * @param options Optional settings to force refresh the device list. Can include a refresh flag.\n * @returns Promise resolving to an array of audio devices conforming to AudioDevice interface\n */\n async getAvailableDevices(options?: {\n refresh?: boolean\n }): Promise<AudioDevice[]> {\n try {\n if (Platform.OS === 'web') {\n this.availableDevices = await this.getWebAudioDevices()\n } else if (ExpoAudioStreamModule.getAvailableInputDevices) {\n // Expecting an array of raw device objects from native\n const rawDevices: any[] =\n await ExpoAudioStreamModule.getAvailableInputDevices(\n options\n )\n // Map raw objects to the AudioDevice interface\n this.availableDevices = rawDevices.map(\n mapRawDeviceToAudioDevice\n )\n } else {\n // Fallback for unsupported platforms\n this.availableDevices = [DEFAULT_DEVICE]\n }\n return this.availableDevices\n } catch (error) {\n this.logger?.error('Failed to get available devices:', error)\n this.availableDevices = [DEFAULT_DEVICE] // Ensure state is updated on error\n return this.availableDevices\n }\n }\n\n /**\n * Get the currently selected audio input device\n * @returns Promise resolving to the current device (conforming to AudioDevice) or null\n */\n async getCurrentDevice(): Promise<AudioDevice | null> {\n try {\n if (Platform.OS === 'web') {\n if (!this.currentDeviceId) {\n // On web, return the typed default device if nothing is selected\n return DEFAULT_DEVICE\n }\n // Refresh web devices to ensure the current one is up-to-date\n const webDevices = await this.getWebAudioDevices()\n return (\n webDevices.find((d) => d.id === this.currentDeviceId) ||\n DEFAULT_DEVICE // Fallback to default if current ID not found\n )\n } else if (ExpoAudioStreamModule.getCurrentInputDevice) {\n // Expecting a single raw device object or null from native\n const rawDevice: any | null =\n await ExpoAudioStreamModule.getCurrentInputDevice()\n // Map to AudioDevice interface if not null\n return rawDevice ? mapRawDeviceToAudioDevice(rawDevice) : null\n } else {\n // Fallback for unsupported platforms\n return DEFAULT_DEVICE\n }\n } catch (error) {\n this.logger?.error('Failed to get current device:', error)\n return DEFAULT_DEVICE // Return default on error\n }\n }\n\n /**\n * Select a specific audio input device for recording\n * @param deviceId The ID of the device to select\n * @returns Promise resolving to a boolean indicating success\n */\n async selectDevice(deviceId: string): Promise<boolean> {\n try {\n let success = false\n if (Platform.OS === 'web') {\n // Check if the device exists before setting it\n const devices = await this.getWebAudioDevices()\n if (devices.some((d) => d.id === deviceId)) {\n this.currentDeviceId = deviceId\n success = true\n } else {\n this.logger?.warn(\n `Web: Device with ID ${deviceId} not found.`\n )\n success = false\n }\n } else if (ExpoAudioStreamModule.selectInputDevice) {\n success =\n await ExpoAudioStreamModule.selectInputDevice(deviceId)\n if (success) {\n this.currentDeviceId = deviceId\n }\n }\n // Refresh devices after selection attempt to update state\n await this.refreshDevices()\n return success\n } catch (error) {\n this.logger?.error('Failed to select device:', error)\n await this.refreshDevices() // Refresh even on error\n return false\n }\n }\n\n /**\n * Reset to the default audio input device\n * @returns Promise resolving to a boolean indicating success\n */\n async resetToDefaultDevice(): Promise<boolean> {\n try {\n let success = false\n if (Platform.OS === 'web') {\n this.currentDeviceId = 'default'\n success = true\n } else if (ExpoAudioStreamModule.resetToDefaultDevice) {\n success = await ExpoAudioStreamModule.resetToDefaultDevice()\n if (success) {\n this.currentDeviceId = null\n }\n }\n // Refresh devices after reset attempt\n await this.refreshDevices()\n return success\n } catch (error) {\n this.logger?.error('Failed to reset to default device:', error)\n await this.refreshDevices() // Refresh even on error\n return false\n }\n }\n\n /**\n * Register a listener for device changes\n * @param listener Function to call when devices change (receives AudioDevice[])\n * @returns Function to remove the listener\n */\n addDeviceChangeListener(\n listener: (devices: AudioDevice[]) => void\n ): () => void {\n this.deviceChangeListeners.add(listener)\n\n // Immediately call listener with current devices if available\n if (this.availableDevices.length > 0) {\n listener([...this.availableDevices])\n }\n\n // Return a function to remove the listener\n return () => {\n this.deviceChangeListeners.delete(listener)\n }\n }\n\n /**\n * Mark a device as temporarily disconnected (for UI filtering)\n * @param deviceId The ID of the device that was disconnected\n * @param notify Whether to notify listeners immediately (default: true)\n */\n markDeviceAsDisconnected(deviceId: string, notify: boolean = true): void {\n this.logger?.debug(\n `Marking device ${deviceId} as temporarily disconnected`\n )\n\n // Clear any existing timeout for this device\n const existingTimeout = this.disconnectionTimeouts.get(deviceId)\n if (existingTimeout) {\n clearTimeout(existingTimeout)\n }\n\n // Add to disconnected set\n this.temporarilyDisconnectedDevices.add(deviceId)\n\n // Set timeout to remove from disconnected set\n const timeout = setTimeout(() => {\n this.logger?.debug(\n `Reconnection timeout expired for device ${deviceId}`\n )\n this.temporarilyDisconnectedDevices.delete(deviceId)\n this.disconnectionTimeouts.delete(deviceId)\n // Refresh devices to show the device again if it's still available\n this.forceRefreshDevices()\n }, this.DISCONNECTION_TIMEOUT_MS)\n\n this.disconnectionTimeouts.set(deviceId, timeout)\n\n // Only notify listeners if requested\n if (notify) {\n this.notifyListeners()\n }\n }\n\n /**\n * Mark a device as reconnected (remove from disconnected set)\n * @param deviceId The ID of the device that was reconnected\n */\n markDeviceAsReconnected(deviceId: string): void {\n this.logger?.debug(`Marking device ${deviceId} as reconnected`)\n\n // Clear timeout and remove from disconnected set\n const timeout = this.disconnectionTimeouts.get(deviceId)\n if (timeout) {\n clearTimeout(timeout)\n this.disconnectionTimeouts.delete(deviceId)\n }\n\n this.temporarilyDisconnectedDevices.delete(deviceId)\n\n // Notify listeners with updated device list\n this.notifyListeners()\n }\n\n /**\n * Get filtered device list (excluding temporarily disconnected devices)\n * @returns Array of available devices excluding temporarily disconnected ones\n */\n private getFilteredDevices(): AudioDevice[] {\n if (this.temporarilyDisconnectedDevices.size === 0) {\n return [...this.availableDevices]\n }\n\n const filtered = this.availableDevices.filter(\n (device) => !this.temporarilyDisconnectedDevices.has(device.id)\n )\n\n this.logger?.debug(\n `Filtered ${this.availableDevices.length - filtered.length} temporarily disconnected devices. ` +\n `Showing ${filtered.length} devices.`\n )\n\n return filtered\n }\n\n /**\n * Get the raw device list (including temporarily disconnected devices)\n * @returns Array of all available devices from native layer\n */\n getRawDevices(): AudioDevice[] {\n return [...this.availableDevices]\n }\n\n /**\n * Get the IDs of temporarily disconnected devices\n * @returns Set of device IDs that are temporarily hidden from UI\n */\n getTemporarilyDisconnectedDeviceIds(): ReadonlySet<string> {\n return new Set(this.temporarilyDisconnectedDevices)\n }\n\n /**\n * Clean up timeouts and listeners (useful for testing or cleanup)\n */\n cleanup(): void {\n // Clear all disconnection timeouts\n this.disconnectionTimeouts.forEach((timeout) => clearTimeout(timeout))\n this.disconnectionTimeouts.clear()\n this.temporarilyDisconnectedDevices.clear()\n\n // Clear device change listeners\n this.deviceChangeListeners.clear()\n\n // Clean up web device listener\n if (Platform.OS === 'web' && this.webDeviceChangeHandler) {\n if (typeof navigator !== 'undefined' && navigator.mediaDevices) {\n navigator.mediaDevices.removeEventListener(\n 'devicechange',\n this.webDeviceChangeHandler\n )\n }\n this.webDeviceChangeHandler = undefined\n }\n\n this.logger?.debug('AudioDeviceManager cleanup completed')\n }\n\n /**\n * Force refresh devices without debouncing (for device events)\n * @returns Promise resolving to the updated device list (AudioDevice[])\n */\n async forceRefreshDevices(): Promise<AudioDevice[]> {\n this.logger?.debug('Force refreshing devices (bypassing debounce)...')\n this.refreshInProgress = true\n try {\n // Force fetch the latest devices from native layer\n const devices = await this.getAvailableDevices({ refresh: true })\n // Update internal state\n this.availableDevices = devices\n // Notify listeners with fresh data\n this.notifyListeners()\n this.lastRefreshTime = Date.now()\n return devices\n } catch (error) {\n this.logger?.error('Error during forceRefreshDevices:', error)\n return this.availableDevices\n } finally {\n this.refreshInProgress = false\n this.logger?.debug('Force refresh finished.')\n }\n }\n\n /**\n * Refresh the list of available devices with debouncing and notify listeners.\n * @returns Promise resolving to the updated device list (AudioDevice[])\n */\n async refreshDevices(): Promise<AudioDevice[]> {\n const now = Date.now()\n\n if (this.refreshInProgress) {\n this.logger?.debug('Refresh already in progress, skipping')\n return this.availableDevices\n }\n\n // Always allow refresh if forced by native event or longer than 2s debounce\n const timeSinceLastRefresh = now - this.lastRefreshTime\n const shouldDebounce =\n timeSinceLastRefresh < this.refreshDebounceMs &&\n timeSinceLastRefresh < 2000\n\n if (shouldDebounce) {\n this.logger?.debug(\n `Refresh debounced, skipping (last refresh was ${timeSinceLastRefresh}ms ago)`\n )\n return this.availableDevices\n }\n\n this.logger?.debug('Refreshing devices...')\n this.refreshInProgress = true\n try {\n // Fetch the latest devices; getAvailableDevices handles mapping now\n const devices = await this.getAvailableDevices({ refresh: true })\n // availableDevices state is updated within getAvailableDevices\n this.notifyListeners() // Notify listeners with the updated list\n this.lastRefreshTime = Date.now()\n return devices // Return the fetched & mapped list\n } catch (error) {\n this.logger?.error('Error during refreshDevices:', error)\n return this.availableDevices // Return potentially stale list on error\n } finally {\n this.refreshInProgress = false\n this.logger?.debug('Refresh finished.')\n }\n }\n\n /**\n * Get audio input devices using the Web Audio API\n * @returns Promise resolving to an array of AudioDevice objects\n */\n private async getWebAudioDevices(): Promise<AudioDevice[]> {\n if (\n typeof navigator === 'undefined' ||\n !navigator.mediaDevices ||\n !navigator.mediaDevices.enumerateDevices\n ) {\n return [DEFAULT_DEVICE]\n }\n\n try {\n const permissionStatus = await this.checkMicrophonePermission()\n\n if (permissionStatus === 'denied') {\n return [\n {\n ...DEFAULT_DEVICE,\n name: 'Microphone Access Denied',\n isAvailable: false,\n },\n ]\n }\n\n if (permissionStatus !== 'granted') {\n try {\n // Requesting stream often reveals device labels\n await navigator.mediaDevices.getUserMedia({ audio: true })\n } catch (error) {\n this.logger?.warn(\n 'Microphone permission request failed:',\n error\n )\n return [\n {\n ...DEFAULT_DEVICE,\n name: 'Microphone Access Required',\n isAvailable: false,\n },\n ]\n }\n }\n\n const devices = await navigator.mediaDevices.enumerateDevices()\n const audioInputDevices = devices\n .filter((device) => device.kind === 'audioinput')\n .map((device) => this.mapWebDeviceToAudioDevice(device))\n\n const hasUnlabeledDevices = audioInputDevices.some(\n (device) =>\n !device.name || device.name.startsWith('Microphone ')\n )\n\n let finalDevices = audioInputDevices\n if (hasUnlabeledDevices && this.isSafariOrIOS()) {\n finalDevices = this.enhanceDevicesForSafari(audioInputDevices)\n }\n\n if (finalDevices.length === 0) {\n finalDevices = [DEFAULT_DEVICE]\n }\n\n this.availableDevices = finalDevices // Update internal state\n return finalDevices\n } catch (error) {\n this.logger?.error('Failed to enumerate web audio devices:', error)\n this.availableDevices = [DEFAULT_DEVICE] // Update state on error\n return this.availableDevices\n }\n }\n\n /**\n * Check the current microphone permission status\n * @returns Permission state ('prompt', 'granted', or 'denied')\n */\n private async checkMicrophonePermission(): Promise<PermissionState> {\n if (!navigator.permissions || !navigator.permissions.query) {\n return 'prompt'\n }\n try {\n const permissionStatus = await navigator.permissions.query({\n name: 'microphone' as PermissionName,\n })\n permissionStatus.onchange = () => {\n // Refresh devices when permission changes\n this.refreshDevices()\n }\n return permissionStatus.state\n } catch (error) {\n this.logger?.warn('Permission query not supported:', error)\n return 'prompt'\n }\n }\n\n /**\n * Setup listener for device changes in web environment\n */\n private setupWebDeviceChangeListener(): void {\n if (\n typeof navigator === 'undefined' ||\n !navigator.mediaDevices ||\n this.webDeviceChangeHandler // Avoid adding multiple listeners\n ) {\n this.logger?.debug(\n 'Web device change listener not available or already set up'\n )\n return\n }\n\n try {\n this.webDeviceChangeHandler = () => {\n this.logger?.debug(\n 'Web device change detected, refreshing device list'\n )\n // Force refresh to get immediate updates\n this.forceRefreshDevices()\n }\n\n navigator.mediaDevices.addEventListener(\n 'devicechange',\n this.webDeviceChangeHandler\n )\n this.logger?.debug('Web device change listener successfully set up')\n } catch (error) {\n this.logger?.warn(\n 'Failed to set up web device change listener:',\n error\n )\n this.webDeviceChangeHandler = undefined\n }\n }\n\n /**\n * Check if the current browser is Safari or iOS WebKit\n */\n private isSafariOrIOS(): boolean {\n if (typeof navigator === 'undefined') return false\n const ua = navigator.userAgent\n return (\n /^((?!chrome|android).)*safari/i.test(ua) ||\n /iPad|iPhone|iPod/.test(ua) ||\n (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)\n )\n }\n\n /**\n * Create enhanced device information for Safari and privacy-restricted browsers\n * @param devices Array of AudioDevice objects, potentially unlabeled\n * @returns Array of enhanced AudioDevice objects\n */\n private enhanceDevicesForSafari(devices: AudioDevice[]): AudioDevice[] {\n const defaultDevice = devices.find((d) => d.isDefault)\n\n if (devices.length <= 1) {\n // Return a typed default device\n return [\n {\n id: defaultDevice?.id || 'default',\n name: 'Microphone (Browser Managed)',\n type: 'builtin_mic',\n isDefault: true,\n isAvailable: true,\n capabilities:\n defaultDevice?.capabilities ||\n DEFAULT_DEVICE.capabilities,\n },\n ]\n }\n\n // Provide more descriptive names for unlabeled devices\n return devices.map((device, index) => {\n if (!device.name || device.name.startsWith('Microphone ')) {\n const deviceTypes = [\n 'Built-in Microphone',\n 'External Microphone',\n 'Headset Microphone',\n ]\n const typeName = deviceTypes[index % deviceTypes.length]\n return {\n ...device,\n name: device.isDefault ? `${typeName} (Default)` : typeName,\n }\n }\n return device\n })\n }\n\n /**\n * Map a Web MediaDeviceInfo to our AudioDevice format\n * @param device The MediaDeviceInfo object from the browser\n * @returns An object conforming to the AudioDevice interface\n */\n private mapWebDeviceToAudioDevice(device: MediaDeviceInfo): AudioDevice {\n const isDefault = device.deviceId === 'default'\n const deviceType = this.inferDeviceType(device.label || '')\n\n // Provide reasonable default capabilities for web devices\n const defaultWebCapabilities: AudioDeviceCapabilities = {\n sampleRates: [16000, 44100, 48000],\n channelCounts: [1, 2],\n bitDepths: [16, 32], // Web Audio uses float32, common PCM might be 16/32\n hasEchoCancellation: true, // Often handled by browser\n hasNoiseSuppression: true, // Often handled by browser\n hasAutomaticGainControl: true, // Often handled by browser\n }\n\n return {\n id: device.deviceId,\n name:\n device.label || `Microphone ${device.deviceId.substring(0, 8)}`,\n type: deviceType,\n isDefault,\n isAvailable: true, // Assume available if enumerated\n capabilities: defaultWebCapabilities,\n }\n }\n\n /**\n * Try to infer the device type from its name\n * @param deviceName The label of the device\n * @returns A string representing the inferred device type\n */\n private inferDeviceType(deviceName: string): string {\n const name = deviceName.toLowerCase()\n if (name.includes('bluetooth') || name.includes('airpods'))\n return 'bluetooth'\n if (name.includes('usb')) return 'usb'\n if (name.includes('headphone') || name.includes('headset')) {\n return name.includes('wired') ? 'wired_headset' : 'wired_headphones'\n }\n if (name.includes('speaker')) return 'speaker'\n return 'builtin_mic' // Default assumption\n }\n\n /**\n * Notify all registered listeners about device changes.\n */\n notifyListeners(): void {\n // Pass a copy of the filtered devices array to listeners\n const devicesCopy = this.getFilteredDevices()\n\n this.logger?.debug(\n `Notifying ${this.deviceChangeListeners.size} listeners with ${devicesCopy.length} devices ` +\n `(${this.temporarilyDisconnectedDevices.size} temporarily hidden)`\n )\n\n this.deviceChangeListeners.forEach((listener) => {\n try {\n listener(devicesCopy)\n } catch (error) {\n this.logger?.error('Error in device change listener:', error)\n }\n })\n }\n}\n\n// Create and export the singleton instance\nexport const audioDeviceManager = new AudioDeviceManager()\n\nexport { DeviceDisconnectionBehavior }\n"]}
|
|
@@ -11,6 +11,8 @@ function useAudioDevices() {
|
|
|
11
11
|
const [currentDevice, setCurrentDevice] = (0, react_1.useState)(null);
|
|
12
12
|
const [loading, setLoading] = (0, react_1.useState)(true);
|
|
13
13
|
const [error, setError] = (0, react_1.useState)(null);
|
|
14
|
+
// Generate unique instance ID for debugging
|
|
15
|
+
const instanceId = (0, react_1.useId)().replace(/:/g, '').slice(0, 5);
|
|
14
16
|
// Load devices on mount
|
|
15
17
|
(0, react_1.useEffect)(() => {
|
|
16
18
|
let isMounted = true;
|
|
@@ -28,7 +30,9 @@ function useAudioDevices() {
|
|
|
28
30
|
setCurrentDevice(device);
|
|
29
31
|
}
|
|
30
32
|
catch (err) {
|
|
31
|
-
|
|
33
|
+
AudioDeviceManager_1.audioDeviceManager
|
|
34
|
+
.getLogger()
|
|
35
|
+
?.error('Failed to load audio devices:', err);
|
|
32
36
|
if (isMounted)
|
|
33
37
|
setError(err instanceof Error
|
|
34
38
|
? err
|
|
@@ -42,16 +46,23 @@ function useAudioDevices() {
|
|
|
42
46
|
loadDevices();
|
|
43
47
|
// Set up device change listener
|
|
44
48
|
const removeListener = AudioDeviceManager_1.audioDeviceManager.addDeviceChangeListener((updatedDevices) => {
|
|
49
|
+
AudioDeviceManager_1.audioDeviceManager
|
|
50
|
+
.getLogger()
|
|
51
|
+
?.debug(`🎛️ useAudioDevices [${instanceId}] received device change. Count: ${updatedDevices.length}`);
|
|
45
52
|
if (isMounted) {
|
|
46
53
|
setDevices(updatedDevices);
|
|
47
54
|
// If our current device is no longer available, update it
|
|
48
55
|
if (currentDevice &&
|
|
49
56
|
!updatedDevices.some((d) => d.id === currentDevice.id)) {
|
|
57
|
+
AudioDeviceManager_1.audioDeviceManager
|
|
58
|
+
.getLogger()
|
|
59
|
+
?.debug(`🎛️ useAudioDevices [${instanceId}] Current device ${currentDevice.id} no longer available, updating`);
|
|
50
60
|
AudioDeviceManager_1.audioDeviceManager
|
|
51
61
|
.getCurrentDevice()
|
|
52
62
|
.then((newDevice) => {
|
|
53
|
-
if (isMounted)
|
|
63
|
+
if (isMounted) {
|
|
54
64
|
setCurrentDevice(newDevice);
|
|
65
|
+
}
|
|
55
66
|
});
|
|
56
67
|
}
|
|
57
68
|
}
|
|
@@ -79,7 +90,9 @@ function useAudioDevices() {
|
|
|
79
90
|
return success;
|
|
80
91
|
}
|
|
81
92
|
catch (err) {
|
|
82
|
-
|
|
93
|
+
AudioDeviceManager_1.audioDeviceManager
|
|
94
|
+
.getLogger()
|
|
95
|
+
?.error('Failed to select audio device:', err);
|
|
83
96
|
setError(err instanceof Error
|
|
84
97
|
? err
|
|
85
98
|
: new Error('Failed to select audio device'));
|
|
@@ -106,7 +119,9 @@ function useAudioDevices() {
|
|
|
106
119
|
return success;
|
|
107
120
|
}
|
|
108
121
|
catch (err) {
|
|
109
|
-
|
|
122
|
+
AudioDeviceManager_1.audioDeviceManager
|
|
123
|
+
.getLogger()
|
|
124
|
+
?.error('Failed to reset to default audio device:', err);
|
|
110
125
|
setError(err instanceof Error
|
|
111
126
|
? err
|
|
112
127
|
: new Error('Failed to reset to default audio device'));
|
|
@@ -131,7 +146,9 @@ function useAudioDevices() {
|
|
|
131
146
|
return updatedDevices;
|
|
132
147
|
}
|
|
133
148
|
catch (err) {
|
|
134
|
-
|
|
149
|
+
AudioDeviceManager_1.audioDeviceManager
|
|
150
|
+
.getLogger()
|
|
151
|
+
?.error('Failed to refresh audio devices:', err);
|
|
135
152
|
setError(err instanceof Error
|
|
136
153
|
? err
|
|
137
154
|
: new Error('Failed to refresh audio devices'));
|
|
@@ -141,6 +158,13 @@ function useAudioDevices() {
|
|
|
141
158
|
setLoading(false);
|
|
142
159
|
}
|
|
143
160
|
}, []);
|
|
161
|
+
/**
|
|
162
|
+
* Initialize device detection
|
|
163
|
+
* Useful for restarting device detection if it failed initially
|
|
164
|
+
*/
|
|
165
|
+
const initializeDeviceDetection = (0, react_1.useCallback)(() => {
|
|
166
|
+
AudioDeviceManager_1.audioDeviceManager.initializeDeviceDetection();
|
|
167
|
+
}, []);
|
|
144
168
|
return {
|
|
145
169
|
devices,
|
|
146
170
|
currentDevice,
|
|
@@ -149,6 +173,7 @@ function useAudioDevices() {
|
|
|
149
173
|
selectDevice,
|
|
150
174
|
resetToDefaultDevice,
|
|
151
175
|
refreshDevices,
|
|
176
|
+
initializeDeviceDetection,
|
|
152
177
|
};
|
|
153
178
|
}
|
|
154
179
|
//# sourceMappingURL=useAudioDevices.js.map
|