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

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

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) {