React Native with Socket.io
I'm trying to use socket.io client from react native. I found several answers in stack overflow including this one: Is it possible to combine React Native with socket.io which suggests using socket-io client and setting the navigator.userAgent to react-native. I tried it and it doesn't work on my android, I also found a video about this in youtube but the guy got it to work on an emulator, for me once I used remote debugging it worked as well because it was on the browser I guess.
And I found a project on https://www.npmjs.com/package/react-native-socketio but it is still a work in progress. Can someone who had to deal with this issue and managed to find a solution give out some pointers? In the end I resorted to using react native websockets on the client side and the npm ws library on the server side which works just fine but I don't have any of the fallbacks.
I don't know if you solved your problem, but for anyone facing the same issue: you don't need navigator.userAgent
anymore to use socket.io with React Native.
Here is a little example of how you can do it now:
import io from 'socket.io-client'
const socket = io('http://123.456.78.987:3200', {
transports: ['websocket'],
})
socket.emit('dispatch', "Real time baby 🎉")
Comments
Post a Comment