Implement robust WebRTC polyfills and native audio session management for LiveKit on mobile platforms. This includes configuring iOS audio sessions to prevent issues during calls and implementing a delayed video activation strategy to avoid main thread deadlocks on iOS. - Add WebRTC and environment polyfills in `src/polyfills.ts` - Implement iOS-specific `AudioSession` configuration in `LiveKitService` - Add support for toggling speaker output on iOS - Update `callStore` to handle video enablement after connection settles - Fix `useUnreadCountQuery` to correctly handle async fetching
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import { Platform } from 'react-native';
|
|
|
|
// Register WebRTC globals for LiveKit (native only — web has built-in WebRTC)
|
|
if (Platform.OS !== 'web') {
|
|
// Use @livekit/react-native's registerGlobals which sets up:
|
|
// - WebRTC native modules (via @livekit/react-native-webrtc)
|
|
// - iOS audio session management
|
|
// - LiveKitReactNativeGlobal (so livekit-client detects RN environment)
|
|
// - RN-specific polyfills (Promise.allSettled, webstreams, crypto, etc.)
|
|
const { registerGlobals } = require('@livekit/react-native');
|
|
registerGlobals();
|
|
}
|
|
|
|
if (typeof globalThis.Event === 'undefined') {
|
|
(globalThis as any).Event = class Event {
|
|
type: string;
|
|
bubbles: boolean;
|
|
cancelable: boolean;
|
|
defaultPrevented: boolean;
|
|
target: any;
|
|
currentTarget: any;
|
|
constructor(type: string, opts?: { bubbles?: boolean; cancelable?: boolean }) {
|
|
this.type = type;
|
|
this.bubbles = opts?.bubbles ?? false;
|
|
this.cancelable = opts?.cancelable ?? false;
|
|
this.defaultPrevented = false;
|
|
this.target = null;
|
|
this.currentTarget = null;
|
|
}
|
|
preventDefault() { this.defaultPrevented = true; }
|
|
stopPropagation() {}
|
|
stopImmediatePropagation() {}
|
|
};
|
|
}
|
|
|
|
if (typeof globalThis.DOMException === 'undefined') {
|
|
(globalThis as any).DOMException = class DOMException extends Error {
|
|
constructor(message?: string, name?: string) {
|
|
super(message);
|
|
this.name = name || 'DOMException';
|
|
}
|
|
};
|
|
} |