From d2d91c10a3a2ed9cc81f4af40907fd75c350558c Mon Sep 17 00:00:00 2001 From: Darren Date: Tue, 23 Oct 2012 00:50:18 +0100 Subject: [PATCH] Sending connection errors back to the client. Stack overflow fix --- client/assets/dev/model_application.js | 6 +++++- client/assets/dev/model_gateway.js | 15 ++++++++++----- server/client.js | 12 +++++++----- server/irc/connection.js | 6 ++---- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/client/assets/dev/model_application.js b/client/assets/dev/model_application.js index 54a3ad5..d02c942 100644 --- a/client/assets/dev/model_application.js +++ b/client/assets/dev/model_application.js @@ -68,7 +68,11 @@ kiwi.model.Application = function () { kiwi.gateway.set('kiwi_server', that.kiwi_server + '/kiwi'); kiwi.gateway.set('nick', event.nick); - kiwi.gateway.connect(event.server, event.port, event.ssl, event.password, function () {}); + kiwi.gateway.connect(event.server, event.port, event.ssl, event.password, function (error) { + if (error) { + kiwiServerNotFound(); + } + }); }); }); diff --git a/client/assets/dev/model_gateway.js b/client/assets/dev/model_gateway.js index c68e114..91cf5d0 100644 --- a/client/assets/dev/model_gateway.js +++ b/client/assets/dev/model_gateway.js @@ -80,10 +80,6 @@ kiwi.model.Gateway = function () { 'sync disconnect on unload': false }); this.socket.on('connect_failed', function (reason) { - // TODO: When does this even actually get fired? I can't find a case! ~Darren - console.debug('Unable to connect Socket.IO', reason); - console.log("kiwi.gateway.socket.on('connect_failed')"); - //kiwi.front.tabviews.server.addMsg(null, ' ', 'Unable to connect to Kiwi IRC.\n' + reason, 'error'); this.socket.disconnect(); this.trigger("connect_fail", {reason: reason}); }); @@ -111,6 +107,7 @@ kiwi.model.Gateway = function () { console.log("kiwi.gateway.socket.on('connect')"); } else { console.log("kiwi.gateway.socket.on('error')", {reason: err}); + callback(err); } }); }); @@ -123,6 +120,10 @@ kiwi.model.Gateway = function () { that.parse(data.command, data.data); }); + this.socket.on('kiwi', function (data, callback) { + that.parseKiwi(data.command, data.data); + }); + this.socket.on('disconnect', function () { that.trigger("disconnect", {}); console.log("kiwi.gateway.socket.on('disconnect')"); @@ -149,6 +150,10 @@ kiwi.model.Gateway = function () { }; + + this.parseKiwi = function (command, data) { + console.log('kiwi event', command, data); + }; /* Events: msg @@ -172,7 +177,7 @@ kiwi.model.Gateway = function () { * Parses the response from the server */ this.parse = function (command, data) { - console.log('gateway event', command, data); + //console.log('gateway event', command, data); if (command !== undefined) { that.trigger('on' + command, data); diff --git a/server/client.js b/server/client.js index 28e6f05..e597666 100755 --- a/server/client.js +++ b/server/client.js @@ -49,12 +49,12 @@ module.exports.Client = Client; Client.prototype.sendIrcCommand = function (command, data, callback) { var c = {command: command, data: data}; - //console.log('C<--', c); this.websocket.emit('irc', c, callback); }; -Client.prototype.sendKiwiCommand = function (command, callback) { - this.websocket.emit('kiwi', command, callback); +Client.prototype.sendKiwiCommand = function (command, data, callback) { + var c = {command: command, data: data}; + this.websocket.emit('kiwi', c, callback); }; function handleClientMessage(msg, callback) { @@ -83,7 +83,7 @@ function handleClientMessage(msg, callback) { // Run the client command this.client_commands.run(msg.data.method, msg.data.args, server, callback); -}; +} @@ -113,7 +113,9 @@ function kiwiCommand(command, callback) { }); con.on('error', function (err) { - this.websocket.sendKiwiCommand('error', {server: con_num, error: err}); + // TODO: Once multiple servers implemented, specify which server failed + //that.sendKiwiCommand('error', {server: con_num, error: err}); + return callback(err.code, null); }); con.on('close', function () { diff --git a/server/irc/connection.js b/server/irc/connection.js index 7ab3d02..7c3940b 100644 --- a/server/irc/connection.js +++ b/server/irc/connection.js @@ -16,10 +16,8 @@ var IrcConnection = function (hostname, port, ssl, nick, user, pass, webirc) { }); } - this.socket.on('error', function () { - var a = Array.prototype.slice.call(arguments); - a.unshift('error'); - that.emit.apply(this, a); + this.socket.on('error', function (event) { + that.emit('error', event); }); this.socket.setEncoding('utf-8'); -- 2.25.1