WebSocket "onclose" event is missing code attribute
See original GitHub issueDescription
I have successfully opened a WSS connection on the iOS Simulator where I get data back from the socket. No issues. However, the same socket doesn’t seem to get any data at all in the Android emulator. I’ve tried with another WSS endpoint just to rule out the SSL being the issue. wss://echo.websocket.org works on both platforms without issues.
To debug this, I expected to get a code
in the WebSocketEvent that is sent on the onerror
listener I have registered, but it is undefined and missing from the event object. I expected a code in return to be able to know the reason why I can’t connect to the socket in the Android emulator.
Reproduction
The code I used is very simple and works on iOS:
const socket = new WebSocket("wss://endpoint")
socket.onopen = () => {
console.log("Connected!")
}
socket.onmessage = event => {
console.log(event.data)
}
socket.onclose = event => {
console.log("Socket closed") // event.code is missing here
}
socket.onerror = error => {
console.log("Error", error)
}
Solution
As the WebSocket implementation in Chrome retrieves both code
and reason
(although almost always empty), so should the RN implementation of WebSocket.
Additional Information
- React Native version: 0.41.2
- Platform: iOS (works), Android (Nexus 5, API 25:5554doesn’t work)
- Operating System: MacOS 10.12.2
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:9 (1 by maintainers)
+1
Im seeing this same behavior when I close with a custom code, its not being set