Skip to content

Commit

Permalink
fix: add protocols fallback for Firefox (#20)
Browse files Browse the repository at this point in the history
On the latest Firefox and Edge versions, with the current version of sockette.js, the usage of opts.protocols without any check causes the browser to send "undefined" in the Sec-WebSocket-Protocol header.

Protocol being undefined, the server is likely to send a 426: No Sec-WebSocket-Protocols requested supported (except if you specify on your server side that 'undefined' is a possible protocol value).

Passing [] to the WebSocket constructor instead of undefined nullify the need for protocol check on the server side, as browsers stop sending the header.
  • Loading branch information
gfaugere authored and lukeed committed Nov 13, 2018
1 parent 5e6dec4 commit a465457
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function (url, opts) {
};

self.open = function () {
ws = new WebSocket(url, opts.protocols);
ws = new WebSocket(url, opts.protocols || []);
for (k in $) ws[k] = $[k];
};

Expand Down

0 comments on commit a465457

Please sign in to comment.