pladaria / reconnecting-websocket

Reconnecting WebSocket. For Web, React Native, cli (Node.js)
MIT License
1.22k stars 197 forks source link

Cannot send "code" and "reason" to server in close command #21

Closed msageryd closed 7 years ago

msageryd commented 7 years ago

I need to send a code (other that the default 1000) to my server. I cannot get it to work.

Here is what I'm using:

I can verify the following:

  1. Server gets code=1000, reason=""
  2. In ReconnectingWebsocket.close() I have verified (console.log) that code=1003 right before ws.close(code, reason) is called

I cant understand what's wrong. The only logical explanation I can come up with is that React Native's implementation of WebSocket sends code=1000 and reason="" as hard coded values.

I have probably missed something though. Anyone else having trouble with this?

pladaria commented 7 years ago

Can you please try to reproduce using RN websocket directly?

pladaria commented 7 years ago

Have a look at the RN Websocket implementation, it performs some type and OS checks:

https://github.com/facebook/react-native/blob/3360999431b4ed931068ac2f96c8234cdd1f6662/Libraries/WebSocket/WebSocket.js#L135

Looks like there's the reason of your problem