Sending connection errors back to the client. Stack overflow fix
authorDarren <darren@darrenwhitlen.com>
Mon, 22 Oct 2012 23:50:18 +0000 (00:50 +0100)
committerDarren <darren@darrenwhitlen.com>
Mon, 22 Oct 2012 23:50:18 +0000 (00:50 +0100)
client/assets/dev/model_application.js
client/assets/dev/model_gateway.js
server/client.js
server/irc/connection.js

index 54a3ad5024511701d2887003f1fdba7fa42f11fa..d02c9420b163dcbc948318673217ee0cdff6b112 100644 (file)
@@ -68,7 +68,11 @@ kiwi.model.Application = function () {
                     kiwi.gateway.set('kiwi_server', that.kiwi_server + '/kiwi');\r
                     kiwi.gateway.set('nick', event.nick);\r
                     \r
-                    kiwi.gateway.connect(event.server, event.port, event.ssl, event.password, function () {});\r
+                    kiwi.gateway.connect(event.server, event.port, event.ssl, event.password, function (error) {\r
+                        if (error) {\r
+                            kiwiServerNotFound();\r
+                        }\r
+                    });\r
                 });\r
             });\r
 \r
index c68e114dc879b3eae80d59612a298d431160bee0..91cf5d0aeab8da86a7c1a7fdd11cfeede4371a94 100644 (file)
@@ -80,10 +80,6 @@ kiwi.model.Gateway = function () {
             'sync disconnect on unload': false\r
         });\r
         this.socket.on('connect_failed', function (reason) {\r
-            // TODO: When does this even actually get fired? I can't find a case! ~Darren\r
-            console.debug('Unable to connect Socket.IO', reason);\r
-            console.log("kiwi.gateway.socket.on('connect_failed')");\r
-            //kiwi.front.tabviews.server.addMsg(null, ' ', 'Unable to connect to Kiwi IRC.\n' + reason, 'error');\r
             this.socket.disconnect();\r
             this.trigger("connect_fail", {reason: reason});\r
         });\r
@@ -111,6 +107,7 @@ kiwi.model.Gateway = function () {
                     console.log("kiwi.gateway.socket.on('connect')");\r
                 } else {\r
                     console.log("kiwi.gateway.socket.on('error')", {reason: err});\r
+                    callback(err);\r
                 }\r
             });\r
         });\r
@@ -123,6 +120,10 @@ kiwi.model.Gateway = function () {
             that.parse(data.command, data.data);\r
         });\r
 \r
+        this.socket.on('kiwi', function (data, callback) {\r
+            that.parseKiwi(data.command, data.data);\r
+        });\r
+\r
         this.socket.on('disconnect', function () {\r
             that.trigger("disconnect", {});\r
             console.log("kiwi.gateway.socket.on('disconnect')");\r
@@ -149,6 +150,10 @@ kiwi.model.Gateway = function () {
     };\r
 \r
 \r
+\r
+    this.parseKiwi = function (command, data) {\r
+        console.log('kiwi event', command, data);\r
+    };\r
     /*\r
         Events:\r
             msg\r
@@ -172,7 +177,7 @@ kiwi.model.Gateway = function () {
     *   Parses the response from the server\r
     */\r
     this.parse = function (command, data) {\r
-        console.log('gateway event', command, data);\r
+        //console.log('gateway event', command, data);\r
         if (command !== undefined) {\r
             that.trigger('on' + command, data);\r
 \r
index 28e6f0524dc70f122cf69bca4bc2077bf6814942..e597666751f77a574fa92a7188e4bea405e57b93 100755 (executable)
@@ -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 () {
index 7ab3d024619673bfc53cd8dd357d0175ce87a0c9..7c3940b1ff2e3ba20f2ade815bc3e922ea4acd03 100644 (file)
@@ -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');