mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
parent
4b73a92f71
commit
d49ed69a0a
@ -28,6 +28,7 @@ module.exports = function(RED) {
|
|||||||
this.ircclient = null;
|
this.ircclient = null;
|
||||||
this.on("close", function() {
|
this.on("close", function() {
|
||||||
if (this.ircclient != null) {
|
if (this.ircclient != null) {
|
||||||
|
this.ircclient.removeAllListeners();
|
||||||
this.ircclient.disconnect();
|
this.ircclient.disconnect();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -42,10 +43,11 @@ module.exports = function(RED) {
|
|||||||
this.serverConfig = RED.nodes.getNode(this.ircserver);
|
this.serverConfig = RED.nodes.getNode(this.ircserver);
|
||||||
this.channel = n.channel || this.serverConfig.channel;
|
this.channel = n.channel || this.serverConfig.channel;
|
||||||
var node = this;
|
var node = this;
|
||||||
if (node.serverConfig.ircclient == null) {
|
if (node.serverConfig.ircclient === null) {
|
||||||
node.log("Connecting to "+node.serverConfig.server);
|
node.log("Connecting to "+node.serverConfig.server);
|
||||||
node.status({fill:"grey",shape:"dot",text:"connecting"});
|
node.status({fill:"grey",shape:"dot",text:"connecting"});
|
||||||
node.serverConfig.ircclient = new irc.Client(node.serverConfig.server, node.serverConfig.nickname,{autoConnect:false,retryDelay:20000});
|
node.serverConfig.ircclient = new irc.Client(node.serverConfig.server, node.serverConfig.nickname,{autoConnect:false,retryDelay:20000});
|
||||||
|
node.serverConfig.ircclient.setMaxListeners(0);
|
||||||
node.serverConfig.ircclient.addListener('error', function(message) {
|
node.serverConfig.ircclient.addListener('error', function(message) {
|
||||||
node.log(JSON.stringify(message));
|
node.log(JSON.stringify(message));
|
||||||
});
|
});
|
||||||
@ -130,6 +132,7 @@ module.exports = function(RED) {
|
|||||||
node.serverConfig.lastseen = Date.now();
|
node.serverConfig.lastseen = Date.now();
|
||||||
});
|
});
|
||||||
node.on("close", function() {
|
node.on("close", function() {
|
||||||
|
node.ircclient.removeAllListeners();
|
||||||
if (node.recon) { clearInterval(node.recon); }
|
if (node.recon) { clearInterval(node.recon); }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -144,10 +147,11 @@ module.exports = function(RED) {
|
|||||||
this.serverConfig = RED.nodes.getNode(this.ircserver);
|
this.serverConfig = RED.nodes.getNode(this.ircserver);
|
||||||
this.channel = n.channel || this.serverConfig.channel;
|
this.channel = n.channel || this.serverConfig.channel;
|
||||||
var node = this;
|
var node = this;
|
||||||
if (node.serverConfig.ircclient == null) {
|
if (node.serverConfig.ircclient === null) {
|
||||||
node.log("Connecting to "+node.serverConfig.server);
|
node.log("Connecting to "+node.serverConfig.server);
|
||||||
node.status({fill:"grey",shape:"dot",text:"connecting"});
|
node.status({fill:"grey",shape:"dot",text:"connecting"});
|
||||||
node.serverConfig.ircclient = new irc.Client(node.serverConfig.server, node.serverConfig.nickname,{autoConnect:false,retryDelay:20000});
|
node.serverConfig.ircclient = new irc.Client(node.serverConfig.server, node.serverConfig.nickname,{autoConnect:false,retryDelay:20000});
|
||||||
|
node.serverConfig.ircclient.setMaxListeners(0);
|
||||||
node.serverConfig.ircclient.addListener('error', function(message) {
|
node.serverConfig.ircclient.addListener('error', function(message) {
|
||||||
node.log(JSON.stringify(message));
|
node.log(JSON.stringify(message));
|
||||||
});
|
});
|
||||||
@ -162,6 +166,9 @@ module.exports = function(RED) {
|
|||||||
node.serverConfig.lastseen = Date.now();
|
node.serverConfig.lastseen = Date.now();
|
||||||
node.log("PING "+JSON.stringify(server));
|
node.log("PING "+JSON.stringify(server));
|
||||||
});
|
});
|
||||||
|
node.serverConfig.ircclient.addListener('raw', function (message) { // any message received means we are alive
|
||||||
|
if (message.commandType === "reply") { node.serverConfig.lastseen = Date.now(); }
|
||||||
|
});
|
||||||
node.recon = setInterval( function() {
|
node.recon = setInterval( function() {
|
||||||
//console.log("CHK ",(Date.now()-node.serverConfig.lastseen)/1000);
|
//console.log("CHK ",(Date.now()-node.serverConfig.lastseen)/1000);
|
||||||
if ((Date.now()-node.serverConfig.lastseen) > 300000) { // if more than 5 mins since last seen
|
if ((Date.now()-node.serverConfig.lastseen) > 300000) { // if more than 5 mins since last seen
|
||||||
@ -188,10 +195,6 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
node.ircclient.addListener('raw', function (message) { // any message received means we are alive
|
|
||||||
if (message.commandType === "reply") { node.serverConfig.lastseen = Date.now(); }
|
|
||||||
});
|
|
||||||
|
|
||||||
node.on("input", function(msg) {
|
node.on("input", function(msg) {
|
||||||
if (Object.prototype.toString.call( msg.raw ) === '[object Array]') {
|
if (Object.prototype.toString.call( msg.raw ) === '[object Array]') {
|
||||||
node.log("RAW command:"+msg.raw);
|
node.log("RAW command:"+msg.raw);
|
||||||
@ -226,6 +229,7 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
node.on("close", function() {
|
node.on("close", function() {
|
||||||
|
node.ircclient.removeAllListeners();
|
||||||
if (node.recon) { clearInterval(node.recon); }
|
if (node.recon) { clearInterval(node.recon); }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user