This happened in RN 0.44.0.
It doesn't happen in the simulator, only on the real iPhone device (iPhone 6).
When you lock the phone while the app is running and you have an open WebSocket, the onclose handler will eventually be triggered and an event object will be passed to the handler. This event object doesn't have an event.code or event.reason property defined (which is inconsistent with all major browsers which always pass back a status code) so there is no way to tell what kind of error/condition caused the connection to become closed.
I'm not sure if this is in breach of the WebSocket RFC but it's not ideal because it's inconsistent with major browsers (e.g. when closing the latop and it goes to sleep, I get a 1006 in Chrome).
Create a new WebSocket connection. E.g. var socket = new WebSocket(uri);
Attach onclose handler. E.g. socket.onclose = function (event) { console.log('close:', event.code, event.reason); }
Lock phone
Wait a bit
Unlock phone
event.code should be logged as undefined.
Sample Code
var socket = new WebSocket(uri);
socket.onclose = function (event) {
console.log('close:', event.code, event.reason);
}
Solution
According to the WebSocket RFC, if no status code is given as part of a close control frame, then the code is assumed to be 1005 (assuming that a close control frame is sent) or 1006 (assuming that the client was closed 'abnormally' - Which typically means terminated immediately without sending a close control frame over the wire). See https://tools.ietf.org/html/rfc6455#section-7.1.5
Description
This happened in RN 0.44.0. It doesn't happen in the simulator, only on the real iPhone device (iPhone 6).
When you lock the phone while the app is running and you have an open WebSocket, the
onclose
handler will eventually be triggered and anevent
object will be passed to the handler. Thisevent
object doesn't have anevent.code
orevent.reason
property defined (which is inconsistent with all major browsers which always pass back a status code) so there is no way to tell what kind of error/condition caused the connection to become closed.I'm not sure if this is in breach of the WebSocket RFC but it's not ideal because it's inconsistent with major browsers (e.g. when closing the latop and it goes to sleep, I get a 1006 in Chrome).
See original issue: https://github.com/SocketCluster/socketcluster-client/issues/83
Reproduction Steps
var socket = new WebSocket(uri);
socket.onclose = function (event) { console.log('close:', event.code, event.reason); }
event.code
should be logged asundefined
.Sample Code
Solution
According to the WebSocket RFC, if no status code is given as part of a close control frame, then the code is assumed to be 1005 (assuming that a close control frame is sent) or 1006 (assuming that the client was closed 'abnormally' - Which typically means terminated immediately without sending a close control frame over the wire). See https://tools.ietf.org/html/rfc6455#section-7.1.5
Additional Information