1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Added support for commaseparated subprotocols

Removed placeholder from html
This commit is contained in:
Tobias Oort 2022-01-12 09:10:35 +01:00
parent 83203d5f5d
commit 555f155cad
3 changed files with 10 additions and 5 deletions

View File

@ -268,7 +268,7 @@
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-config-input-subprotocol"><i class="fa fa-tag"></i> <span data-i18n="websocket.label.subprotocol"></span></label> <label for="node-config-input-subprotocol"><i class="fa fa-tag"></i> <span data-i18n="websocket.label.subprotocol"></span></label>
<input id="node-config-input-subprotocol" type="text" data-i18n="[placeholder]websocket.placeholder.subprotocol"> <input type="text" id="node-config-input-subprotocol">
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-config-input-wholemsg" data-i18n="websocket.sendrec"></label> <label for="node-config-input-wholemsg" data-i18n="websocket.sendrec"></label>

View File

@ -46,7 +46,12 @@ module.exports = function(RED) {
// Store local copies of the node configuration (as defined in the .html) // Store local copies of the node configuration (as defined in the .html)
node.path = n.path; 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.wholemsg = (n.wholemsg === "true");
node._inputNodes = []; // collection of nodes that want to receive events node._inputNodes = []; // collection of nodes that want to receive events

View File

@ -370,10 +370,10 @@ describe('websocket Node', function() {
var flow = [ var flow = [
{ id: "server", type: "websocket-listener", path: "/ws" }, { id: "server", type: "websocket-listener", path: "/ws" },
{ id: "n1", type: "websocket-client", path: getWsUrl("/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.load(websocketNode, flow, function() {
helper.getNode("n1").should.have.property("subprotocol", undefined); helper.getNode("n1").should.have.property("subprotocol", []);
helper.getNode("n2").should.have.property("subprotocol", "testprotocol"); helper.getNode("n2").should.have.property("subprotocol", ["testprotocol1","testprotocol2"]);
done(); done();
}); });
}); });