pladaria / reconnecting-websocket

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

How to set protocol #9

Closed vincent714 closed 7 years ago

vincent714 commented 8 years ago

I set up the new object as follows,

var options = {connectionTimeout: 1000};
var reconnectingWebSocket = new ReconnectingWebsocket('wss://localhost:9090', null, options);

but in the Chrome console, it showed:

Error during WebSocket handshake: Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received

I don't have any idea to fix it. Can someone help me? Thanks.

pladaria commented 8 years ago

Do you have the same issue using a regular WebSocket?

dubiousdavid commented 7 years ago

I'm having the same issue. Actually here is a pretty small test case:

import WebSocket from 'reconnecting-websocket'
let ws = new WebSocket('wss://echo.websocket.org', null)

Without the second argument it works correctly.

pladaria commented 7 years ago

According to the spec, the second argument must be a string or an array of strings: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket

If you don't want to set it, use undefined

Test here: http://requirebin.com/?gist=d5d5e8aa7a31de1a4e4810a055c6c46d