From 0506b3431f31f5c5365a4cb16aba25b056c640f5 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 4 Sep 2017 14:11:55 +0200 Subject: [PATCH] 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. --- include/websock.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/websock.js b/include/websock.js index 51d9b62..08698bb 100644 --- a/include/websock.js +++ b/include/websock.js @@ -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);