StanzaJS does work with React Native (through 0.65), but it requires a little bit of extra configuration to shim properly.
node-libs-react-native
react-native-get-random-values
(orexpo-standard-web-crypto
)vm-browserify
If you are using WebRTC, you will also need react-native-webrtc
.
Add a resolver
section to the Metro config, specifying the extraNodeModules
to use:
// metro.config.js
module.exports = {
resolver: {
extraNodeModules: {
...require('node-libs-react-native'),
vm: require.resolve('vm-browserify')
}
}
};
The vm
module is not currently shimmed by node-libs-react-native
(but there is a PR for it).
// your top-level index.js
import 'node-libs-react-native/globals';
// If you are using react-native-get-random-values:
import 'react-native-get-random-values';
// Or if you are using expo-standard-web-crypto:
import { polyfillWebCrypto } from 'expo-standard-web-crypto';
polyfillWebCrypto();
// If you are using WebRTC:
import { registerGlobals } from 'react-native-webrtc';
registerGlobals();
Your app should now be able to load and use StanzaJS.