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

Websocket input node not unsubscribing properly

Fixes #739
This commit is contained in:
Nick O'Leary 2015-10-23 23:01:25 +01:00
parent 712f8b4680
commit f66886dbdb

View File

@ -48,7 +48,7 @@ module.exports = function(RED) {
if (!node.isServer) { node.emit('opened',''); } if (!node.isServer) { node.emit('opened',''); }
}); });
socket.on('close',function() { socket.on('close',function() {
if (node.isServer) { delete node._clients[id]; node.emit('opened',Object.keys(node._clients).length); } if (node.isServer) { delete node._clients[id]; node.emit('closed',Object.keys(node._clients).length); }
else { node.emit('closed'); } else { node.emit('closed'); }
if (!node.closing && !node.isServer) { if (!node.closing && !node.isServer) {
node.tout = setTimeout(function(){ startconn(); }, 3000); // try to reconnect every 3 secs... bit fast ? node.tout = setTimeout(function(){ startconn(); }, 3000); // try to reconnect every 3 secs... bit fast ?
@ -126,6 +126,14 @@ module.exports = function(RED) {
this._inputNodes.push(handler); this._inputNodes.push(handler);
} }
WebSocketListenerNode.prototype.removeInputNode = function(/*Node*/handler) {
this._inputNodes.forEach(function(node, i, inputNodes) {
if (node === handler) {
inputNodes.splice(i, 1);
}
});
}
WebSocketListenerNode.prototype.handleEvent = function(id,/*socket*/socket,/*String*/event,/*Object*/data,/*Object*/flags){ WebSocketListenerNode.prototype.handleEvent = function(id,/*socket*/socket,/*String*/event,/*Object*/data,/*Object*/flags){
var msg; var msg;
if (this.wholemsg) { if (this.wholemsg) {
@ -187,6 +195,11 @@ module.exports = function(RED) {
} else { } else {
this.error(RED._("websocket.errors.missing-conf")); this.error(RED._("websocket.errors.missing-conf"));
} }
this.on('close', function() {
node.serverConfig.removeInputNode(node);
});
} }
RED.nodes.registerType("websocket in",WebSocketInNode); RED.nodes.registerType("websocket in",WebSocketInNode);