Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions packages/mobile-client/src/webrtc-polyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'react-native-get-random-values';
import 'react-native-url-polyfill/auto';

import { EventTarget, registerGlobals } from '@fishjam-cloud/react-native-webrtc';
import { NativeModules } from 'react-native';

import { patchGetUserMediaWithPermissionWarnings } from './overrides/getUserMedia';
import { RTCPeerConnection } from './overrides/RTCPeerConnection';
Expand All @@ -17,4 +18,38 @@ const registerGlobalsPolyfill = () => {
patchGetUserMediaWithPermissionWarnings();
};

const assertReactNativeWebRTCNativeModule = () => {
if (NativeModules.WebRTCModule) return;
throw new Error(
'@fishjam-cloud/react-native-client: the native module for `@fishjam-cloud/react-native-webrtc` is not linked. ' +
'Install the package and rebuild your native app:\n' +
' 1. yarn add @fishjam-cloud/react-native-webrtc\n' +
' 2. cd ios && pod install (bare React Native)\n' +
' or: npx expo prebuild --clean && rebuild your dev client (Expo)',
Comment thread
MiloszFilimowski marked this conversation as resolved.
);
};

const assertGetRandomValuesPolyfill = () => {
try {
if (typeof globalThis.crypto?.getRandomValues !== 'function') {
throw new Error('crypto.getRandomValues is undefined');
}
globalThis.crypto.getRandomValues(new Uint8Array(1));
} catch (cause) {
const causeMessage = cause instanceof Error ? cause.message : String(cause);
throw new Error(
'@fishjam-cloud/react-native-client: `react-native-get-random-values` is not installed or its native module is not linked. ' +
'Install the package and rebuild your native app:\n' +
' 1. yarn add react-native-get-random-values\n' +
' 2. cd ios && pod install (bare React Native)\n' +
' or: npx expo prebuild --clean && rebuild your dev client (Expo)\n' +
Comment thread
MiloszFilimowski marked this conversation as resolved.
`Underlying error: ${causeMessage}`,
);
}
};

if (__DEV__) {
assertReactNativeWebRTCNativeModule();
assertGetRandomValuesPolyfill();
}
registerGlobalsPolyfill();
Loading