Package Exports
- react-native-wss
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-native-wss) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
React native WebSocket Secure
Every project what i created was problem with securing websockets. So I decide to share my codes with everyone, and i hope this will be merged into react native one day.
Installing
Copy scripts/postinstall.js into your project rootCopy patches/node_modules.zip into your project rootAdd yauzl devDependencies into package.jsonCompile android native code with wss support
Clone repository from github.
git clone https://github.com/facebook/react-native.gitCheckout to your version of react native into cloned react native repository folder.
git checkout 0.61-stableNow, You have to replace a file
ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.javawith (into react native repository folder)
scripts/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.javaLet's build android native project( be sure NDK is installed and path is defined into bash_brofile ) Run this into react native repository folder
./gradlew clean
./gradlew assembleReleaseAfter the react native was builded with success, rename the file
ReactAndroid/build/outputs/aar/ReactAndroid-release.aarto your project react native version ( for example 0.61.5 )
ReactAndroid/build/outputs/aar/react-native-0.61.5.aarand copy it into your project root with path
patches/android/com/facebook/react/react-native/0.61.5/react-native-0.61.5.aarThe last step is zip the folder patches/android/ with name of your react native project version ( for example 0.61.5 )
zip -r 0.61.5.zip android/Run the postinstall
npm ior
node scripts/postinstall.jsAPI
Now, you can use wss address with certificates. ( No need to import any other libs. )
this._ws = new WebSocket( 'wss://192.168.0.1', [],
{
headers: { Authorization: 'Bearer 123' },
ca: '-----BEGIN CERTIFICATE-----\n\n-----END CERTIFICATE-----\n',
pfx: '',
passphrase: ''
});