From: Darren Date: Sun, 28 Oct 2012 00:41:00 +0000 (+0100) Subject: Removing bound events #101 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c08717da6b2a5da99d3e53341922c56dabadfc90;p=KiwiIRC.git Removing bound events #101 --- diff --git a/server/client.js b/server/client.js index 764d600..a49e5b1 100755 --- a/server/client.js +++ b/server/client.js @@ -57,6 +57,11 @@ Client.prototype.sendKiwiCommand = function (command, data, callback) { this.websocket.emit('kiwi', c, callback); }; +Client.prototype.dispose = function () { + websocketDisconnect.apply(this); + this.removeAllListeners(); +}; + function handleClientMessage(msg, callback) { var server, args, obj, channels, keys; @@ -128,7 +133,7 @@ function kiwiCommand(command, callback) { default: callback(); } -}; +} // Websocket has disconnected, so quit all the IRC connections @@ -136,14 +141,15 @@ function websocketDisconnect() { _.each(this.irc_connections, function (irc_connection, i, cons) { if (irc_connection) { irc_connection.end('QUIT :' + (config.get().quit_message || '')); + irc_connection.dispose(); cons[i] = null; } }); this.emit('destroy'); -}; +} // TODO: Should this close all the websocket connections too? function websocketError() { this.emit('destroy'); -}; +} \ No newline at end of file diff --git a/server/irc/commands.js b/server/irc/commands.js index a78b3d4..6e71edf 100644 --- a/server/irc/commands.js +++ b/server/irc/commands.js @@ -63,6 +63,10 @@ IrcCommands.prototype.bindEvents = function () { }); }; +IrcCommands.prototype.dispose = function () { + this.removeAllListeners(); +}; + var listeners = { diff --git a/server/irc/connection.js b/server/irc/connection.js index 2ba7c16..9e069de 100644 --- a/server/irc/connection.js +++ b/server/irc/connection.js @@ -58,6 +58,11 @@ IrcConnection.prototype.end = function (data, callback) { end.call(this, data + '\r\n', 'utf-8', callback); }; +IrcConnection.prototype.dispose = function () { + this.removeAllListeners(); +}; + + var write = function (data, encoding, callback) { this.socket.write(data, encoding, callback); }; diff --git a/server/kiwi.js b/server/kiwi.js index 87e83d7..134894a 100755 --- a/server/kiwi.js +++ b/server/kiwi.js @@ -42,7 +42,12 @@ _.each(config.get().servers, function (server) { }); wl.on('destroy', function (client) { clients = _.reject(clients, function (c) { - return client === c; + if (client === c) { + c.dispose(); + return true; + } + + return false; }); }); });