Fix sub protocol handling when no protocol is specified

Some browsers are being difficult and won't let us pass on
undefined values for the protocols argument.
This commit is contained in:
Pierre Ossman 2017-09-04 14:11:55 +02:00
parent 5e19bc3f96
commit 0506b3431f
1 changed files with 8 additions and 1 deletions

View File

@ -218,7 +218,14 @@
var ws_schema = uri.match(/^([a-z]+):\/\//)[1];
this.init();
this._websocket = new WebSocket(uri, protocols);
// IE, Edge and Firefox misbehave when protocols is
// undefined, converting it to a string rather than
// treating it as if it wasn't specified
if (protocols) {
this._websocket = new WebSocket(uri, protocols);
} else {
this._websocket = new WebSocket(uri);
}
this._websocket.binaryType = 'arraybuffer';
this._websocket.onmessage = this._recv_message.bind(this);