question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebSocket "onclose" event is missing code attribute

See original GitHub issue

Description

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

screen shot 2017-03-03 at 09 15 56

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
miniFrankcommented, Mar 24, 2017

+1

1reaction
wpratercommented, Dec 27, 2017

Im seeing this same behavior when I close with a custom code, its not being set

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebSocket "onclose" event is missing code and reason ...
I have successfully opened a WebSocket connection on Android, but when I receive the event object in my "onerror" handler, there is no...
Read more >
WebSocket: close event - Web APIs - MDN Web Docs
Returns a boolean value that Indicates whether or not the connection was cleanly closed.
Read more >
React-Native Websocket Event data property is missing
It seems as if the event.data property is completely missing. If I log it to the console in react-native I get 'undefined' as...
Read more >
WebSocket API: close and error events - Mailing lists - W3C
I have two questions related to WebSocket API and close/error handling. ... code attribute is initialized to the WebSocket connection close ...
Read more >
Both sides - websockets 10.4 documentation
If the corresponding Pong frame isn't received within ping_timeout seconds, the connection is considered unusable and is closed with code 1011. This ensures ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found