Skip to content

Commit 8fb65a8

Browse files
committed
call setupIOSAudioManagement in registerGlobals
1 parent 30c53b3 commit 8fb65a8

1 file changed

Lines changed: 5 additions & 24 deletions

File tree

src/index.tsx

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import AudioSession, {
2121
} from './audio/AudioSession';
2222
import type { AudioConfiguration } from './audio/AudioSession';
2323
import { PixelRatio, Platform } from 'react-native';
24+
import { setupIOSAudioManagement } from './audio/AudioManager';
2425
import { type LiveKitReactNativeInfo } from 'livekit-client';
2526
import type { LogLevel, SetLogLevelOptions } from './logger';
2627
import RNE2EEManager from './e2ee/RNE2EEManager';
@@ -30,9 +31,9 @@ import { ReadableStream, WritableStream } from 'web-streams-polyfill';
3031

3132
export interface RegisterGlobalsOptions {
3233
/**
33-
* Automatically configure audio session before accessing microphone.
34-
* When enabled, sets the iOS audio category to 'playAndRecord' before getUserMedia.
35-
* Has no effect on non-iOS platforms.
34+
* Automatically configure and activate the iOS audio session
35+
* based on audio engine lifecycle events.
36+
* Has no effect on non-Apple platforms.
3637
*
3738
* @default true
3839
*/
@@ -54,7 +55,7 @@ export function registerGlobals(options?: RegisterGlobalsOptions) {
5455

5556
webrtcRegisterGlobals();
5657
if (opts.autoConfigureAudioSession) {
57-
iosCategoryEnforce();
58+
setupIOSAudioManagement();
5859
}
5960
livekitRegisterGlobals();
6061
setupURLPolyfill();
@@ -66,26 +67,6 @@ export function registerGlobals(options?: RegisterGlobalsOptions) {
6667
setupNativeEvents();
6768
}
6869

69-
/**
70-
* Enforces changing to playAndRecord category prior to obtaining microphone.
71-
*/
72-
function iosCategoryEnforce() {
73-
if (Platform.OS === 'ios') {
74-
// @ts-ignore
75-
let getUserMediaFunc = global.navigator.mediaDevices.getUserMedia;
76-
// @ts-ignore
77-
global.navigator.mediaDevices.getUserMedia = async (constraints: any) => {
78-
if (constraints.audio) {
79-
await AudioSession.setAppleAudioConfiguration({
80-
audioCategory: 'playAndRecord',
81-
});
82-
}
83-
84-
return await getUserMediaFunc(constraints);
85-
};
86-
}
87-
}
88-
8970
function livekitRegisterGlobals() {
9071
let lkGlobal: LiveKitReactNativeInfo = {
9172
platform: Platform.OS,

0 commit comments

Comments
 (0)