Closed JperF closed 6 years ago
@JperF What version of socketcluster-client
are you using? What version of socketcluster
?
Are you calling socket.disconnect(...)
somewhere?
"Socket connection failed for unknown reasons" means that the socket does not recognize the error code which was passed to it when closing.
Last time I saw this error, someone was trying to pass a string to disconnect like this: socket.disconnect('some custom error')
.
The first argument to the disconnect function should be an error code (a Number) and the second argument is the reason string (or you can call disconnect without any arguments). Search for the disconnect
method here: http://socketcluster.io/#!/docs/api-scsocket-client
Also note that if you call socket.disconnect(...)
with a custom error code and you do not provide a reason string as the second argument, then you will also get 'Socket connection failed for unknown reasons'
because SC cannot match the custom code to any known SC error.
Let me know if this is caused by a different issue.
"socketcluster-client": "^5.5.1"
"socketcluster": "5.x.x",
In our code we never directly call the disconnect function. I referenced a similar issue in a different library that suggested that you needed to disconnect your socket and reconnect it when an iOS application goes into the background.
After doing this with the use of AppState
in react-native
the crashing issue stopped but now when attempting to reconnect to the channels we defined before they aren't recognized correctly.
Can you do npm ls socketcluster
and also npm ls socketcluster-server
when inside your project directory to get the exact version numbers?
└─┬ socketcluster@5.15.0
└── socketcluster-server@5.14.0
└── socketcluster-client@5.5.1
What do you mean by 'they aren't recognized correctly' are you seeing an error?
Feel free to chat on Gitter if you need assistance: https://gitter.im/SocketCluster/socketcluster
@JperF I pushed a fix with a small workaround to handle React Native having event.code
being undefined (it will treat it as code 1005). socketcluster-client@5.5.2
. Let me know if this fixes it.
Note that you will still get an error on the socket (since it is not a clean WebSocket close), but if you catch/handle it correctly with:
socket.on('error', function (err) {
// Log error somewhere...
});
Then it shouldn't kill your RN process and SC should reconnect automatically.
@jondubois
Sounds good! Thanks so much for being so helpful and quick to respond!
I am having trouble debugging an issue that is causing the socket to be prematurely disconnected.
Steps to reproduce the problem:
Upon the application reloading I receive the following error.
iphone 6
XCode Debug message:
This error does not happen on the simulator and only appears on an actual iphone.
Any suggestions??