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

Don't let IRC node try to join channels multiple times...

Addresses #447
This commit is contained in:
Dave C-J 2014-10-18 20:36:49 +01:00
parent dd9fc6a250
commit 28a4ba1aad
2 changed files with 12 additions and 13 deletions

View File

@ -1,5 +1,5 @@
<!-- <!--
Copyright 2013 IBM Corp. Copyright 2013,2014 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/** /**
* Copyright 2013 IBM Corp. * Copyright 2013,2014 IBM Corp.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -169,32 +169,31 @@ module.exports = function(RED) {
node.serverConfig.ircclient.addListener('raw', function (message) { // any message received means we are alive node.serverConfig.ircclient.addListener('raw', function (message) { // any message received means we are alive
if (message.commandType === "reply") { node.serverConfig.lastseen = Date.now(); } if (message.commandType === "reply") { node.serverConfig.lastseen = Date.now(); }
}); });
node.serverConfig.ircclient.addListener('registered', function(message) {
node.log(node.serverConfig.ircclient.nick+" ONLINE");
node.status({fill:"yellow",shape:"dot",text:"connected"});
node.serverConfig.ircclient.join( node.channel, function(data) {
//node.log(data+" JOINED "+node.channel);
node.status({fill:"green",shape:"dot",text:"joined"});
});
});
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
node.ircclient.send.apply(node.ircclient,["TIME"]); // request time to check link node.serverConfig.ircclient.send.apply(node.serverConfig.ircclient,["TIME"]); // request time to check link
} }
if ((Date.now()-node.serverConfig.lastseen) > 400000) { // If more than 6.5 mins if ((Date.now()-node.serverConfig.lastseen) > 400000) { // If more than 6.5 mins
node.serverConfig.ircclient.disconnect(); node.serverConfig.ircclient.disconnect();
node.serverConfig.ircclient.connect(); node.serverConfig.ircclient.connect();
node.log("reconnect"); // then retry node.log("reconnect"); // then retry
} }
node.ircclient.send.apply(node.ircclient,["TIME"]); // request time to check link node.serverConfig.ircclient.send.apply(node.serverConfig.ircclient,["TIME"]); // request time to check link
}, 60000); // check every 1 min }, 60000); // check every 1 min
node.serverConfig.ircclient.connect(); node.serverConfig.ircclient.connect();
} }
else { node.status({text:""}); } else { node.status({text:""}); }
node.ircclient = node.serverConfig.ircclient; node.ircclient = node.serverConfig.ircclient;
node.ircclient.addListener('registered', function(message) {
node.log(node.ircclient.nick+" ONLINE");
node.status({fill:"yellow",shape:"dot",text:"connected"});
node.ircclient.join( node.channel, function(data) {
//node.log(data+" JOINED "+node.channel);
node.status({fill:"green",shape:"dot",text:"joined"});
});
});
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);