@@ -18,6 +18,7 @@ import type { LogLevel, SetLogLevelOptions } from './logger';
1818import RNE2EEManager from './e2ee/RNE2EEManager' ;
1919import RNKeyProvider , { type RNKeyProviderOptions } from './e2ee/RNKeyProvider' ;
2020import { setupNativeEvents } from './events/EventEmitter' ;
21+ import { ReadableStream , WritableStream } from 'web-streams-polyfill' ;
2122
2223/**
2324 * Registers the required globals needed for LiveKit to work.
@@ -34,6 +35,8 @@ export function registerGlobals() {
3435 shimArrayAt ( ) ;
3536 shimAsyncIterator ( ) ;
3637 shimIterator ( ) ;
38+ shimCryptoUuid ( ) ;
39+ shimWebstreams ( ) ;
3740 setupNativeEvents ( ) ;
3841}
3942
@@ -100,6 +103,33 @@ function shimIterator() {
100103 var shim = require ( 'well-known-symbols/Symbol.iterator/shim' ) ;
101104 shim ( ) ;
102105}
106+
107+ function shimCryptoUuid ( ) {
108+ if ( typeof global . crypto ?. randomUUID !== 'function' ) {
109+ global . crypto . randomUUID = ( ) =>
110+ 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' . replace ( / [ x y ] / g, function ( c ) {
111+ /* eslint-disable no-bitwise */
112+ const r = ( Math . random ( ) * 16 ) | 0 ;
113+ const v = c === 'x' ? r : ( r & 0x3 ) | 0x8 ;
114+ return v . toString ( 16 ) ;
115+ } ) as `${string } -${string } -${string } -${string } -${string } `;
116+ }
117+ }
118+
119+ function shimWebstreams ( ) {
120+ // @ts -expect-error: global.WritableStream isn't typed here.
121+ if ( typeof global . WritableStream === 'undefined' ) {
122+ // @ts -expect-error
123+ global . WritableStream = WritableStream ;
124+ }
125+
126+ // @ts -expect-error: global.ReadableStream isn't typed here.
127+ if ( typeof global . ReadableStream === 'undefined' ) {
128+ // @ts -expect-error
129+ global . WritableStream = ReadableStream ;
130+ }
131+ }
132+
103133export * from './hooks' ;
104134export * from './components/BarVisualizer' ;
105135export * from './components/LiveKitRoom' ;
0 commit comments