Issue
So I have this issue with Socket.io-client (^2.3.0) running on React Native (0.61.5). I already submitted an issue on GitHub, but I'm hoping someone here can help me out.
So first of all: my code works on iOS, but not on Android.
Steps to reproduce
Environment:
- React Native 0.61.5
- React 16.9.0
- Socket.io-client ^2.3.0
- Android Studio: Android 9.0 Pie API 28
Front end code (simplified): React Native
import io from 'socket.io-client';
useEffect(() => {
socket = io('https://127.0.0.1:8001', {
secure: true,
transports: ['websocket']
})
socket.on('message', () => console.log('message received'))
// cleanup
return () => socket.close()
}, [])
Back end code (simplified): NodeJS
const io = require('socket.io')(https)
io.on('connection', socket => {
console.log('connection established')
socket.on('disconnect', () => console.log('disconnected'))
})
What I did so far?
I tried a few things before submitting an issue and asking this question here. First of all, I tried adding android:usesCleartextTraffic=true
to AndroidManifest.XML. It's suggested here and here. I also tried to downgrade socket.io-client to 2.1.0 and even 2.0.4.
Both steps did not work.
Does anyone have an idea what could be the fix of this problem? I need to use websockets, if there is a workaround (or another library), please let me know!