StanzaJS does work with React Native (through 0.60), but it requires a little bit of extra configuration to shim properly.
node-libs-react-native
vm-browserify
react-native-randombytes
npm i --save node-libs-react-native vm-browserify react-native-randombytes
Add a resolver
section to the Metro config, specifying the extraNodeModules
to use:
// metro.config.js
module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false
}
})
},
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).
Linking modules depends on the version of React Native you are using.
Install CocoaPods for your project:
cd ios && pod install;
Link the react-native-randombytes
module:
react-native link
Add an import for node-libs-react-native/globals
:
// your top-level index.js
import 'node-libs-react-native/globals';
Your app should now be able to load and use StanzaJS. If you are trying to use Jingle and WebRTC, you will need to also set up react-native-webrtc.