@@ -21,6 +21,7 @@ import AudioSession, {
2121} from './audio/AudioSession' ;
2222import type { AudioConfiguration } from './audio/AudioSession' ;
2323import { PixelRatio , Platform } from 'react-native' ;
24+ import { setupIOSAudioManagement } from './audio/AudioManager' ;
2425import { type LiveKitReactNativeInfo } from 'livekit-client' ;
2526import type { LogLevel , SetLogLevelOptions } from './logger' ;
2627import RNE2EEManager from './e2ee/RNE2EEManager' ;
@@ -30,9 +31,9 @@ import { ReadableStream, WritableStream } from 'web-streams-polyfill';
3031
3132export 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-
8970function livekitRegisterGlobals ( ) {
9071 let lkGlobal : LiveKitReactNativeInfo = {
9172 platform : Platform . OS ,
0 commit comments