From 555f155cadfb7fb601b63b7b7a782df070dfdcf1 Mon Sep 17 00:00:00 2001 From: Tobias Oort Date: Wed, 12 Jan 2022 09:10:35 +0100 Subject: [PATCH] Added support for commaseparated subprotocols Removed placeholder from html --- .../@node-red/nodes/core/network/22-websocket.html | 2 +- .../@node-red/nodes/core/network/22-websocket.js | 7 ++++++- test/nodes/core/network/22-websocket_spec.js | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/network/22-websocket.html b/packages/node_modules/@node-red/nodes/core/network/22-websocket.html index 8a97c50ab..a7b54d72f 100644 --- a/packages/node_modules/@node-red/nodes/core/network/22-websocket.html +++ b/packages/node_modules/@node-red/nodes/core/network/22-websocket.html @@ -268,7 +268,7 @@
- +
diff --git a/packages/node_modules/@node-red/nodes/core/network/22-websocket.js b/packages/node_modules/@node-red/nodes/core/network/22-websocket.js index c22e3dea1..0ceac5b01 100644 --- a/packages/node_modules/@node-red/nodes/core/network/22-websocket.js +++ b/packages/node_modules/@node-red/nodes/core/network/22-websocket.js @@ -46,7 +46,12 @@ module.exports = function(RED) { // Store local copies of the node configuration (as defined in the .html) node.path = n.path; - node.subprotocol = n.subprotocol; // optional client protocol + if (typeof n.subprotocol === "string") { + // Split the string on comma and trim each result + node.subprotocol = n.subprotocol.split(",").map(v => v.trim()) + } else { + node.subprotocol = []; + } node.wholemsg = (n.wholemsg === "true"); node._inputNodes = []; // collection of nodes that want to receive events diff --git a/test/nodes/core/network/22-websocket_spec.js b/test/nodes/core/network/22-websocket_spec.js index 4ab96f8ff..21f415531 100644 --- a/test/nodes/core/network/22-websocket_spec.js +++ b/test/nodes/core/network/22-websocket_spec.js @@ -370,10 +370,10 @@ describe('websocket Node', function() { var flow = [ { id: "server", type: "websocket-listener", path: "/ws" }, { id: "n1", type: "websocket-client", path: getWsUrl("/ws") }, - { id: "n2", type: "websocket-client", path: getWsUrl("/ws"), subprotocol: "testprotocol" }]; + { id: "n2", type: "websocket-client", path: getWsUrl("/ws"), subprotocol: "testprotocol1, testprotocol2" }]; helper.load(websocketNode, flow, function() { - helper.getNode("n1").should.have.property("subprotocol", undefined); - helper.getNode("n2").should.have.property("subprotocol", "testprotocol"); + helper.getNode("n1").should.have.property("subprotocol", []); + helper.getNode("n2").should.have.property("subprotocol", ["testprotocol1","testprotocol2"]); done(); }); });