diff --git a/.changeset/tough-cities-make.md b/.changeset/tough-cities-make.md new file mode 100644 index 00000000..4bc42538 --- /dev/null +++ b/.changeset/tough-cities-make.md @@ -0,0 +1,5 @@ +--- +'@livekit/react-native': patch +--- + +Polyfill for DOMException to handle usage in livekit-client diff --git a/src/index.tsx b/src/index.tsx index fc9e660c..65af20b4 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,6 +1,7 @@ import 'well-known-symbols/Symbol.asyncIterator/auto'; import 'well-known-symbols/Symbol.iterator/auto'; import './polyfills/MediaRecorderShim'; +import './polyfills/DOMException'; import { registerGlobals as webrtcRegisterGlobals } from '@livekit/react-native-webrtc'; import { setupURLPolyfill } from 'react-native-url-polyfill'; import './polyfills/EncoderDecoderTogether.min.js'; diff --git a/src/polyfills/DOMException.ts b/src/polyfills/DOMException.ts new file mode 100644 index 00000000..e87c6d77 --- /dev/null +++ b/src/polyfills/DOMException.ts @@ -0,0 +1,21 @@ +/** + * DOMException is missing in some React Native / JS runtimes but is required by + * web APIs (e.g. AbortController, fetch) that may be used in livekit-client. + */ + +// @ts-expect-error: global may not declare DOMException in RN types. +if (typeof global.DOMException === 'undefined') { + class PolyfillDOMException extends Error { + readonly code: number; + + constructor(message = '', name?: string) { + super(message); + this.message = message; + this.name = name ?? 'Error'; + this.code = 0; + Object.setPrototypeOf(this, PolyfillDOMException.prototype); + } + }; + // @ts-expect-error + global.DOMException = PolyfillDOMException; +} \ No newline at end of file