From a5a16cb7becb360e94fb426f3f89b86e667d41e3 Mon Sep 17 00:00:00 2001 From: davidliu Date: Tue, 17 Jun 2025 18:17:07 +0900 Subject: [PATCH 1/3] fix: add crypto.randomUUID and webstream polyfills --- package.json | 1 + src/index.tsx | 30 ++++++++++++++++++++++++++++++ yarn.lock | 8 ++++++++ 3 files changed, 39 insertions(+) diff --git a/package.json b/package.json index 58ee6181..37b42b39 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "promise.allsettled": "^1.0.5", "react-native-url-polyfill": "^1.3.0", "typed-emitter": "^2.1.0", + "web-streams-polyfill": "^4.1.0", "well-known-symbols": "^4.0.0" }, "devDependencies": { diff --git a/src/index.tsx b/src/index.tsx index 76ebd024..1848aa43 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -18,6 +18,7 @@ import type { LogLevel, SetLogLevelOptions } from './logger'; import RNE2EEManager from './e2ee/RNE2EEManager'; import RNKeyProvider, { type RNKeyProviderOptions } from './e2ee/RNKeyProvider'; import { setupNativeEvents } from './events/EventEmitter'; +import { ReadableStream, WritableStream } from 'web-streams-polyfill'; /** * Registers the required globals needed for LiveKit to work. @@ -34,6 +35,8 @@ export function registerGlobals() { shimArrayAt(); shimAsyncIterator(); shimIterator(); + shimCryptoUuid(); + shimWebstreams(); setupNativeEvents(); } @@ -100,6 +103,33 @@ function shimIterator() { var shim = require('well-known-symbols/Symbol.iterator/shim'); shim(); } + +function shimCryptoUuid() { + if (typeof global.crypto?.randomUUID !== 'function') { + global.crypto.randomUUID = () => + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { + /* eslint-disable no-bitwise */ + const r = (Math.random() * 16) | 0; + const v = c === 'x' ? r : (r & 0x3) | 0x8; + return v.toString(16); + }) as `${string}-${string}-${string}-${string}-${string}`; + } +} + +function shimWebstreams() { + // @ts-expect-error: global.WritableStream isn't typed here. + if (typeof global.WritableStream === 'undefined') { + // @ts-expect-error + global.WritableStream = WritableStream; + } + + // @ts-expect-error: global.ReadableStream isn't typed here. + if (typeof global.ReadableStream === 'undefined') { + // @ts-expect-error + global.WritableStream = ReadableStream; + } +} + export * from './hooks'; export * from './components/BarVisualizer'; export * from './components/LiveKitRoom'; diff --git a/yarn.lock b/yarn.lock index 855998ee..89da5ba7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2486,6 +2486,7 @@ __metadata: typed-emitter: ^2.1.0 typedoc: ^0.25.13 typescript: 5.0.4 + web-streams-polyfill: ^4.1.0 well-known-symbols: ^4.0.0 peerDependencies: "@livekit/react-native-webrtc": ^125.0.9 @@ -12739,6 +12740,13 @@ __metadata: languageName: node linkType: hard +"web-streams-polyfill@npm:^4.1.0": + version: 4.1.0 + resolution: "web-streams-polyfill@npm:4.1.0" + checksum: bce16f6bcca895439131fb21e4df15659a34d6f31fedd34b1680ab4fe9c438e02aabd336e4641eb1821e04a8da38dd03c6219fa8ca149ee9a002858a0d32f90d + languageName: node + linkType: hard + "webidl-conversions@npm:^3.0.0": version: 3.0.1 resolution: "webidl-conversions@npm:3.0.1" From 748ac30dca6c0c523a042c429638b27d7d767e8a Mon Sep 17 00:00:00 2001 From: davidliu Date: Tue, 17 Jun 2025 19:16:23 +0900 Subject: [PATCH 2/3] fix: fixes --- example/android/build.gradle | 2 +- src/index.tsx | 27 +++++++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/example/android/build.gradle b/example/android/build.gradle index 3689a7aa..0c97edc7 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -4,7 +4,7 @@ buildscript { minSdkVersion = 24 compileSdkVersion = 34 targetSdkVersion = 34 - ndkVersion = "26.1.10909125" + ndkVersion = "28.1.13356709" kotlinVersion = "1.9.22" } repositories { diff --git a/src/index.tsx b/src/index.tsx index 1848aa43..77f86dff 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -105,14 +105,25 @@ function shimIterator() { } function shimCryptoUuid() { + let crypto = global.crypto; if (typeof global.crypto?.randomUUID !== 'function') { - global.crypto.randomUUID = () => - 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { - /* eslint-disable no-bitwise */ - const r = (Math.random() * 16) | 0; - const v = c === 'x' ? r : (r & 0x3) | 0x8; - return v.toString(16); - }) as `${string}-${string}-${string}-${string}-${string}`; + let createRandomUUID = () => { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace( + /[xy]/g, + function (c) { + /* eslint-disable no-bitwise */ + const r = (Math.random() * 16) | 0; + const v = c === 'x' ? r : (r & 0x3) | 0x8; + return v.toString(16); + } + ) as `${string}-${string}-${string}-${string}-${string}`; + }; + + if (!crypto) { + crypto = {} as typeof global.crypto; + global.crypto = crypto; + } + crypto.randomUUID = createRandomUUID; } } @@ -126,7 +137,7 @@ function shimWebstreams() { // @ts-expect-error: global.ReadableStream isn't typed here. if (typeof global.ReadableStream === 'undefined') { // @ts-expect-error - global.WritableStream = ReadableStream; + global.ReadableStream = ReadableStream; } } From 3dc3121bfd10934798cee65e980666d0de5e5839 Mon Sep 17 00:00:00 2001 From: davidliu Date: Tue, 17 Jun 2025 22:03:08 +0900 Subject: [PATCH 3/3] fix: reorder symbol shims to the top --- example/yarn.lock | 18 ++++---- package.json | 2 +- src/index.tsx | 14 +------ yarn.lock | 102 ++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 107 insertions(+), 29 deletions(-) diff --git a/example/yarn.lock b/example/yarn.lock index 6d6b2f94..522c59d1 100644 --- a/example/yarn.lock +++ b/example/yarn.lock @@ -2163,12 +2163,12 @@ __metadata: languageName: node linkType: hard -"@livekit/protocol@npm:1.36.1": - version: 1.36.1 - resolution: "@livekit/protocol@npm:1.36.1" +"@livekit/protocol@npm:1.39.1": + version: 1.39.1 + resolution: "@livekit/protocol@npm:1.39.1" dependencies: "@bufbuild/protobuf": ^1.10.0 - checksum: 5868e498ba3dc8773913830ae1207145551938c6d460e6e1dc1d6f3b5b30213a4ebf59da2c4b2a72fb005e8a2eecba64a95d14cc407a03b9e166ab4ca159cecd + checksum: 2ca25994ac28c05c618272029f4af82197897545096402548b5ae75b2bd97de993d345b0cca902d2b0fb4f0110602c667844a7a540824d6a12b726f6f495b988 languageName: node linkType: hard @@ -6103,11 +6103,11 @@ __metadata: linkType: hard "livekit-client@npm:^2.9.8": - version: 2.11.4 - resolution: "livekit-client@npm:2.11.4" + version: 2.13.5 + resolution: "livekit-client@npm:2.13.5" dependencies: "@livekit/mutex": 1.1.1 - "@livekit/protocol": 1.36.1 + "@livekit/protocol": 1.39.1 events: ^3.3.0 loglevel: ^1.9.2 sdp-transform: ^2.15.0 @@ -6115,7 +6115,9 @@ __metadata: tslib: 2.8.1 typed-emitter: ^2.1.0 webrtc-adapter: ^9.0.1 - checksum: f47222c8ac1bee5fd7c2f7bf040481110953ba0c6138a5377a57fcb4a8871264f9ff22bfc92d2377de646adc518575d2b3de3f86901992b35386438da7d4aa02 + peerDependencies: + "@types/dom-mediacapture-record": ^1 + checksum: aaff2e0729a7dd51b8641153043ab77825614c12af80662c4f1b98b713af7b7d2565210eed1a56c9e068c45afe4b03bb60a49de02117769868b516a9d1a3a1de languageName: node linkType: hard diff --git a/package.json b/package.json index 37b42b39..005d209d 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "react-native-url-polyfill": "^1.3.0", "typed-emitter": "^2.1.0", "web-streams-polyfill": "^4.1.0", - "well-known-symbols": "^4.0.0" + "well-known-symbols": "^4.1.0" }, "devDependencies": { "@babel/core": "^7.20.0", diff --git a/src/index.tsx b/src/index.tsx index 77f86dff..a8a176bc 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,3 +1,5 @@ +import 'well-known-symbols/Symbol.asyncIterator/auto'; +import 'well-known-symbols/Symbol.iterator/auto'; import { registerGlobals as webrtcRegisterGlobals } from '@livekit/react-native-webrtc'; import { setupURLPolyfill } from 'react-native-url-polyfill'; import './polyfills/EncoderDecoderTogether.min.js'; @@ -33,8 +35,6 @@ export function registerGlobals() { fixWebrtcAdapter(); shimPromiseAllSettled(); shimArrayAt(); - shimAsyncIterator(); - shimIterator(); shimCryptoUuid(); shimWebstreams(); setupNativeEvents(); @@ -94,16 +94,6 @@ function shimArrayAt() { } } -function shimAsyncIterator() { - var shim = require('well-known-symbols/Symbol.asyncIterator/shim'); - shim(); -} - -function shimIterator() { - var shim = require('well-known-symbols/Symbol.iterator/shim'); - shim(); -} - function shimCryptoUuid() { let crypto = global.crypto; if (typeof global.crypto?.randomUUID !== 'function') { diff --git a/yarn.lock b/yarn.lock index 89da5ba7..a8a06f08 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2487,7 +2487,7 @@ __metadata: typedoc: ^0.25.13 typescript: 5.0.4 web-streams-polyfill: ^4.1.0 - well-known-symbols: ^4.0.0 + well-known-symbols: ^4.1.0 peerDependencies: "@livekit/react-native-webrtc": ^125.0.9 livekit-client: ^2.9.0 @@ -4392,6 +4392,16 @@ __metadata: languageName: node linkType: hard +"call-bind-apply-helpers@npm:^1.0.1, call-bind-apply-helpers@npm:^1.0.2": + version: 1.0.2 + resolution: "call-bind-apply-helpers@npm:1.0.2" + dependencies: + es-errors: ^1.3.0 + function-bind: ^1.1.2 + checksum: b2863d74fcf2a6948221f65d95b91b4b2d90cfe8927650b506141e669f7d5de65cea191bf788838bc40d13846b7886c5bc5c84ab96c3adbcf88ad69a72fcdc6b + languageName: node + linkType: hard + "call-bind@npm:^1.0.2, call-bind@npm:^1.0.5, call-bind@npm:^1.0.6, call-bind@npm:^1.0.7": version: 1.0.7 resolution: "call-bind@npm:1.0.7" @@ -5476,6 +5486,17 @@ __metadata: languageName: node linkType: hard +"dunder-proto@npm:^1.0.1": + version: 1.0.1 + resolution: "dunder-proto@npm:1.0.1" + dependencies: + call-bind-apply-helpers: ^1.0.1 + es-errors: ^1.3.0 + gopd: ^1.2.0 + checksum: 149207e36f07bd4941921b0ca929e3a28f1da7bd6b6ff8ff7f4e2f2e460675af4576eeba359c635723dc189b64cdd4787e0255897d5b135ccc5d15cb8685fc90 + languageName: node + linkType: hard + "duplexer3@npm:^0.1.4": version: 0.1.5 resolution: "duplexer3@npm:0.1.5" @@ -5671,6 +5692,13 @@ __metadata: languageName: node linkType: hard +"es-define-property@npm:^1.0.1": + version: 1.0.1 + resolution: "es-define-property@npm:1.0.1" + checksum: 0512f4e5d564021c9e3a644437b0155af2679d10d80f21adaf868e64d30efdfbd321631956f20f42d655fedb2e3a027da479fad3fa6048f768eb453a80a5f80a + languageName: node + linkType: hard + "es-errors@npm:^1.2.1, es-errors@npm:^1.3.0": version: 1.3.0 resolution: "es-errors@npm:1.3.0" @@ -5726,6 +5754,15 @@ __metadata: languageName: node linkType: hard +"es-object-atoms@npm:^1.1.1": + version: 1.1.1 + resolution: "es-object-atoms@npm:1.1.1" + dependencies: + es-errors: ^1.3.0 + checksum: 214d3767287b12f36d3d7267ef342bbbe1e89f899cfd67040309fc65032372a8e60201410a99a1645f2f90c1912c8c49c8668066f6bdd954bcd614dda2e3da97 + languageName: node + linkType: hard + "es-set-tostringtag@npm:^2.0.3": version: 2.0.3 resolution: "es-set-tostringtag@npm:2.0.3" @@ -6544,7 +6581,7 @@ __metadata: languageName: node linkType: hard -"get-intrinsic@npm:^1.1.1, get-intrinsic@npm:^1.1.3, get-intrinsic@npm:^1.2.0, get-intrinsic@npm:^1.2.1, get-intrinsic@npm:^1.2.3, get-intrinsic@npm:^1.2.4": +"get-intrinsic@npm:^1.1.1, get-intrinsic@npm:^1.1.3, get-intrinsic@npm:^1.2.1, get-intrinsic@npm:^1.2.3, get-intrinsic@npm:^1.2.4": version: 1.2.4 resolution: "get-intrinsic@npm:1.2.4" dependencies: @@ -6557,6 +6594,24 @@ __metadata: languageName: node linkType: hard +"get-intrinsic@npm:^1.2.7": + version: 1.3.0 + resolution: "get-intrinsic@npm:1.3.0" + dependencies: + call-bind-apply-helpers: ^1.0.2 + es-define-property: ^1.0.1 + es-errors: ^1.3.0 + es-object-atoms: ^1.1.1 + function-bind: ^1.1.2 + get-proto: ^1.0.1 + gopd: ^1.2.0 + has-symbols: ^1.1.0 + hasown: ^2.0.2 + math-intrinsics: ^1.1.0 + checksum: 301008e4482bb9a9cb49e132b88fee093bff373b4e6def8ba219b1e96b60158a6084f273ef5cafe832e42cd93462f4accb46a618d35fe59a2b507f2388c5b79d + languageName: node + linkType: hard + "get-package-type@npm:^0.1.0": version: 0.1.0 resolution: "get-package-type@npm:0.1.0" @@ -6578,6 +6633,16 @@ __metadata: languageName: node linkType: hard +"get-proto@npm:^1.0.1": + version: 1.0.1 + resolution: "get-proto@npm:1.0.1" + dependencies: + dunder-proto: ^1.0.1 + es-object-atoms: ^1.0.0 + checksum: 4fc96afdb58ced9a67558698b91433e6b037aaa6f1493af77498d7c85b141382cf223c0e5946f334fb328ee85dfe6edd06d218eaf09556f4bc4ec6005d7f5f7b + languageName: node + linkType: hard + "get-stream@npm:^4.1.0": version: 4.1.0 resolution: "get-stream@npm:4.1.0" @@ -6835,6 +6900,13 @@ __metadata: languageName: node linkType: hard +"gopd@npm:^1.2.0": + version: 1.2.0 + resolution: "gopd@npm:1.2.0" + checksum: cc6d8e655e360955bdccaca51a12a474268f95bb793fc3e1f2bdadb075f28bfd1fd988dab872daf77a61d78cbaf13744bc8727a17cfb1d150d76047d805375f3 + languageName: node + linkType: hard + "got@npm:9.6.0, got@npm:^9.6.0": version: 9.6.0 resolution: "got@npm:9.6.0" @@ -6937,6 +7009,13 @@ __metadata: languageName: node linkType: hard +"has-symbols@npm:^1.1.0": + version: 1.1.0 + resolution: "has-symbols@npm:1.1.0" + checksum: b2316c7302a0e8ba3aaba215f834e96c22c86f192e7310bdf689dd0e6999510c89b00fbc5742571507cebf25764d68c988b3a0da217369a73596191ac0ce694b + languageName: node + linkType: hard + "has-tostringtag@npm:^1.0.0, has-tostringtag@npm:^1.0.2": version: 1.0.2 resolution: "has-tostringtag@npm:1.0.2" @@ -9015,6 +9094,13 @@ __metadata: languageName: node linkType: hard +"math-intrinsics@npm:^1.1.0": + version: 1.1.0 + resolution: "math-intrinsics@npm:1.1.0" + checksum: 0e513b29d120f478c85a70f49da0b8b19bc638975eca466f2eeae0071f3ad00454c621bf66e16dd435896c208e719fc91ad79bbfba4e400fe0b372e7c1c9c9a2 + languageName: node + linkType: hard + "memoize-one@npm:^5.0.0": version: 5.2.1 resolution: "memoize-one@npm:5.2.1" @@ -12770,13 +12856,13 @@ __metadata: languageName: node linkType: hard -"well-known-symbols@npm:^4.0.0": - version: 4.0.0 - resolution: "well-known-symbols@npm:4.0.0" +"well-known-symbols@npm:^4.1.0": + version: 4.1.0 + resolution: "well-known-symbols@npm:4.1.0" dependencies: - get-intrinsic: ^1.2.0 - has-symbols: ^1.0.3 - checksum: f8c55e9bcb79f19d818800c07cc807739a412aebb29a9d6a2ee9fa9ff01c875593120a29a2fbfd2c99220d7c1977849090e74e98eb4a7d4b1b6fc112a1d3b4f0 + get-intrinsic: ^1.2.7 + has-symbols: ^1.1.0 + checksum: 077eb4d3258a3c05e4b877cb93f4d84e41092387ad37c500d72d464d3dd874ff5ee02f2d0a0c86185f314e575ce6b4c9e57e2baf28af1fca28c162547af47f1a languageName: node linkType: hard