Fix for irc client - to make connection "lazy", so it doesn't start untill needed.

This commit is contained in:
Dave C-J 2013-10-07 18:46:06 +01:00
parent 56476312c1
commit f1bcf130aa
1 changed files with 22 additions and 13 deletions

View File

@ -24,28 +24,29 @@ function IRCServerNode(n) {
this.server = n.server;
this.channel = n.channel;
this.nickname = n.nickname;
this.ircclient = new irc.Client(this.server, this.nickname, {
channels: [this.channel]
this.ircclient = null;
this.on("close", function() {
if (this.ircclient != null) {
this.ircclient.disconnect();
}
});
this.ircclient.addListener('error', function(message) {
util.log('[irc] '+ JSON.stringify(message));
});
this._close = function() {
this.ircclient.disconnect();
}
}
RED.nodes.registerType("irc-server",IRCServerNode);
IRCServerNode.prototype.close = function() {
this._close();
}
// The Input Node
function IrcInNode(n) {
RED.nodes.createNode(this,n);
this.ircserver = n.ircserver;
this.serverConfig = RED.nodes.getNode(this.ircserver);
if (this.serverConfig.ircclient == null) {
this.serverConfig.ircclient = new irc.Client(this.serverConfig.server, this.serverConfig.nickname, {
channels: [this.serverConfig.channel]
});
this.serverConfig.ircclient.addListener('error', function(message) {
util.log('[irc] '+ JSON.stringify(message));
});
}
this.ircclient = this.serverConfig.ircclient;
var node = this;
@ -64,8 +65,16 @@ function IrcOutNode(n) {
this.sendAll = n.sendObject;
this.ircserver = n.ircserver;
this.serverConfig = RED.nodes.getNode(this.ircserver);
this.ircclient = this.serverConfig.ircclient;
this.channel = this.serverConfig.channel;
if (this.serverConfig.ircclient == null) {
this.serverConfig.ircclient = new irc.Client(this.serverConfig.server, this.serverConfig.nickname, {
channels: [this.serverConfig.channel]
});
this.serverConfig.ircclient.addListener('error', function(message) {
util.log('[irc] '+ JSON.stringify(message));
});
}
this.ircclient = this.serverConfig.ircclient;
var node = this;
this.on("input", function(msg) {