Live video on the AT Protocol
1// awkward use of require()? you betcha. but import() with Metro causes it to try and
2// resolve the package at compile-time even if not installed, so here we are.
3let rnqc: any | null = null;
4let expoCrypto: any | null = null;
5try {
6 rnqc = require("react-native-quick-crypto");
7} catch (err) {}
8try {
9 expoCrypto = require("expo-crypto");
10} catch (err) {}
11
12if (!rnqc && !expoCrypto) {
13 throw new Error(
14 "Livestreaming requires one of react-native-quick-crypto or expo-crypto",
15 );
16}
17if (rnqc) {
18 console.log("Using react-native-quick-crypto for crypto polyfill");
19 // we import this in the main app, but in case this file is used standalone:
20 globalThis.crypto = rnqc as any as Crypto;
21}
22if (expoCrypto) {
23 console.log("Using expo-crypto for crypto polyfill");
24 // @atproto/crypto dependencies expect crypto.getRandomValues to be a function
25 if (typeof globalThis.crypto === "undefined") {
26 globalThis.crypto = {} as any;
27 }
28 if (typeof globalThis.crypto.getRandomValues === "undefined") {
29 globalThis.crypto.getRandomValues = expoCrypto.getRandomValues;
30 }
31}