From 9f91493cd1b487ba6c783c92bfa007794e20c15f Mon Sep 17 00:00:00 2001 From: dansu Date: Tue, 13 Jan 2015 08:48:59 +0100 Subject: [PATCH 1/2] rename 'send' to 'reply' to not collide with internal node function names, a config node has no wires so the 'send' function gets overwritten with a noop (nodes/red/Node.js:42, introduced in 57ae297) --- nodes/core/io/22-websocket.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nodes/core/io/22-websocket.js b/nodes/core/io/22-websocket.js index 72eda5027..b232c06a9 100644 --- a/nodes/core/io/22-websocket.js +++ b/nodes/core/io/22-websocket.js @@ -125,7 +125,7 @@ module.exports = function(RED) { } } - WebSocketListenerNode.prototype.send = function(id,data) { + WebSocketListenerNode.prototype.reply = function(id,data) { var session = this._clients[id]; if (session) { try { @@ -171,7 +171,7 @@ module.exports = function(RED) { } } if (msg._session && msg._session.type == "websocket") { - node.serverConfig.send(msg._session.id,payload); + node.serverConfig.reply(msg._session.id,payload); } else { node.serverConfig.broadcast(payload,function(error){ if (!!error) { From 25776313347172291f8303ea5351f05c956bf500 Mon Sep 17 00:00:00 2001 From: dansu Date: Tue, 13 Jan 2015 10:38:53 +0100 Subject: [PATCH 2/2] Added unittests for websocket node --- test/nodes/core/io/22-websocket_spec.js | 223 ++++++++++++++++++++++++ 1 file changed, 223 insertions(+) create mode 100644 test/nodes/core/io/22-websocket_spec.js diff --git a/test/nodes/core/io/22-websocket_spec.js b/test/nodes/core/io/22-websocket_spec.js new file mode 100644 index 000000000..4f1da5319 --- /dev/null +++ b/test/nodes/core/io/22-websocket_spec.js @@ -0,0 +1,223 @@ +/** + * Copyright 2014 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var ws = require("ws"); +var when = require("when"); +var should = require("should"); +var helper = require("../../helper.js"); +var websocketNode = require("../../../../nodes/core/io/22-websocket.js"); + +var sockets = []; +function createClient(listenerid) { + return when.promise(function(resolve, reject) { + var node = helper.getNode(listenerid); + var url = helper.url().replace(/http/, "ws") + node.path; + var sock = new ws(url); + sockets.push(sock); + + sock.on("open", function() { + resolve(sock); + }); + + sock.on("error", function(err) { + reject(err); + }); + }); +} + +function closeAll() { + for(var i=0;i