From 48892456df75d03f59dd333d24fb40480c237ac4 Mon Sep 17 00:00:00 2001 From: Tobias Baumann <48487608+tbn-mm@users.noreply.github.com> Date: Thu, 13 Oct 2022 20:16:27 +0200 Subject: [PATCH 1/2] Allow passing in a custom createConnection function https://github.com/websockets/ws/issues/1944 --- lib/websocket.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/websocket.js b/lib/websocket.js index 4391c73ab..2bcfcf738 100644 --- a/lib/websocket.js +++ b/lib/websocket.js @@ -643,7 +643,6 @@ function initAsClient(websocket, address, protocols, options) { followRedirects: false, maxRedirects: 10, ...options, - createConnection: undefined, socketPath: undefined, hostname: undefined, protocol: undefined, @@ -706,7 +705,7 @@ function initAsClient(websocket, address, protocols, options) { const protocolSet = new Set(); let perMessageDeflate; - opts.createConnection = isSecure ? tlsConnect : netConnect; + opts.createConnection = opts.createConnection ?? (isSecure ? tlsConnect : netConnect); opts.defaultPort = opts.defaultPort || defaultPort; opts.port = parsedUrl.port || defaultPort; opts.host = parsedUrl.hostname.startsWith('[') From 976491a561cf5d14f141f94a274125f84de908a2 Mon Sep 17 00:00:00 2001 From: Tobias Baumann <48487608+tbn-mm@users.noreply.github.com> Date: Thu, 13 Oct 2022 22:16:52 +0200 Subject: [PATCH 2/2] Update websocket.js Nullish coalescing operator (??) not supported in node 10, replaced by Logical OR (||) --- lib/websocket.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/websocket.js b/lib/websocket.js index 2bcfcf738..23aa11a46 100644 --- a/lib/websocket.js +++ b/lib/websocket.js @@ -705,7 +705,7 @@ function initAsClient(websocket, address, protocols, options) { const protocolSet = new Set(); let perMessageDeflate; - opts.createConnection = opts.createConnection ?? (isSecure ? tlsConnect : netConnect); + opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect); opts.defaultPort = opts.defaultPort || defaultPort; opts.port = parsedUrl.port || defaultPort; opts.host = parsedUrl.hostname.startsWith('[')