Skip to content

Commit 5486644

Browse files
authored
Polyfill DOMException (#341)
Fixes #337 and livekit/client-sdk-js#1871.
1 parent 19a34d3 commit 5486644

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

.changeset/tough-cities-make.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@livekit/react-native': patch
3+
---
4+
5+
Polyfill for DOMException to handle usage in livekit-client

src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'well-known-symbols/Symbol.asyncIterator/auto';
22
import 'well-known-symbols/Symbol.iterator/auto';
33
import './polyfills/MediaRecorderShim';
4+
import './polyfills/DOMException';
45
import { registerGlobals as webrtcRegisterGlobals } from '@livekit/react-native-webrtc';
56
import { setupURLPolyfill } from 'react-native-url-polyfill';
67
import './polyfills/EncoderDecoderTogether.min.js';

src/polyfills/DOMException.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* DOMException is missing in some React Native / JS runtimes but is required by
3+
* web APIs (e.g. AbortController, fetch) that may be used in livekit-client.
4+
*/
5+
6+
// @ts-expect-error: global may not declare DOMException in RN types.
7+
if (typeof global.DOMException === 'undefined') {
8+
class PolyfillDOMException extends Error {
9+
readonly code: number;
10+
11+
constructor(message = '', name?: string) {
12+
super(message);
13+
this.message = message;
14+
this.name = name ?? 'Error';
15+
this.code = 0;
16+
Object.setPrototypeOf(this, PolyfillDOMException.prototype);
17+
}
18+
};
19+
// @ts-expect-error
20+
global.DOMException = PolyfillDOMException;
21+
}

0 commit comments

Comments
 (0)