Connection issues fix #472
authorDarren <darren@darrenwhitlen.com>
Sat, 8 Feb 2014 21:05:14 +0000 (21:05 +0000)
committerDarren <darren@darrenwhitlen.com>
Sat, 8 Feb 2014 21:05:14 +0000 (21:05 +0000)
client/src/models/gateway.js
server/client.js

index 753bc027a63106c46c8dd64c82cabe51118eb37f..7ee21fa5bd806a6c185e2d1f76599c540d8b4511 100644 (file)
@@ -151,6 +151,8 @@ _kiwi.model.Gateway = function () {
     *   @param  {Function}  callback    A callback function to be invoked once Kiwi's server has connected to the IRC server\r
     */\r
     this.connect = function (callback) {\r
+        this.connect_callback = callback;\r
+\r
         // Keep note of the server we are connecting to\r
         this.set('kiwi_server', _kiwi.app.kiwi_server);\r
 \r
@@ -188,8 +190,6 @@ _kiwi.model.Gateway = function () {
             that.disconnect_requested = false;\r
 \r
             console.log("_kiwi.gateway.socket.on('open')");\r
-\r
-            callback && callback();\r
         });\r
 \r
         this.rpc.on('too_many_connections', function () {\r
@@ -294,6 +294,13 @@ _kiwi.model.Gateway = function () {
     this.parseKiwi = function (command, data) {\r
         this.trigger('kiwi:' + command, data);\r
         this.trigger('kiwi', data);\r
+\r
+        switch (command) {\r
+        case 'connected':\r
+            this.connect_callback && this.connect_callback();\r
+            delete this.connect_callback;\r
+            break;\r
+        }\r
     };\r
     /*\r
         Events:\r
index b8e7faff1c0f91673a1e33685d02b954d1aee0d3..d41dc52e3db96568ccc86567c3fa6f87727bab82 100755 (executable)
@@ -49,6 +49,9 @@ var Client = function (websocket) {
     });
 
     this.disposed = false;
+
+    // Let the client know it's finished connecting
+    this.sendKiwiCommand('connected');
 };
 util.inherits(Client, events.EventEmitter);