Files
frontend/src/polyfills.ts

43 lines
1.4 KiB
TypeScript
Raw Normal View History

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';
}
};
}