Gateway.newConnection()
authorDarren <darren@Darrens-MacBook-Pro.local>
Tue, 23 Apr 2013 22:47:02 +0000 (23:47 +0100)
committerDarren <darren@Darrens-MacBook-Pro.local>
Tue, 23 Apr 2013 22:47:02 +0000 (23:47 +0100)
client/assets/dev/model_gateway.js

index 1a534c338508b44aee9704e0fd5795b00a4843ef..d1e7faa703153dce8741fc2b5fccf9628f365dae 100644 (file)
@@ -179,6 +179,14 @@ _kiwi.model.Gateway = function () {
          * IRCD and the nick has been accepted.\r
          */\r
         this.socket.on('connect', function () {\r
+            that.newConnection({\r
+                nick: that.get('nick'),\r
+                host: host,\r
+                port: port,\r
+                ssl: ssl,\r
+                password: password\r
+            }, callback);\r
+            /*\r
             this.emit('kiwi', {command: 'connect', nick: that.get('nick'), hostname: host, port: port, ssl: ssl, password:password}, function (err, server_num) {\r
                 if (!err) {\r
                     that.server_num = server_num;\r
@@ -188,6 +196,7 @@ _kiwi.model.Gateway = function () {
                     callback(err);\r
                 }\r
             });\r
+            */\r
         });\r
 \r
         this.socket.on('too_many_connections', function () {\r
@@ -223,6 +232,29 @@ _kiwi.model.Gateway = function () {
 \r
 \r
 \r
+    this.newConnection = function(connection_info, callback_fn) {\r
+        var that = this,\r
+            h = connection_info;\r
+\r
+        this.socket.emit('kiwi', {command: 'connect', nick: h.nick, hostname: h.host, port: h.port, ssl: h.ssl, password: h.password}, function (err, server_num) {\r
+            if (!err) {\r
+                that.server_num = server_num;\r
+\r
+                // TODO: Remove this whole premature connection thing when panel code is tidied\r
+                if (server_num != 0 && !_kiwi.app.connections.getByConnectionId(server_num)){\r
+                    _kiwi.app.connections.add(new _kiwi.model.Network({connection_id: server_num}));\r
+                }\r
+\r
+                console.log("_kiwi.gateway.socket.on('connect')");\r
+            } else {\r
+                console.log("_kiwi.gateway.socket.on('error')", {reason: err});\r
+                callback_fn && callback_fn(err);\r
+            }\r
+        });\r
+    };\r
+\r
+\r
+\r
     this.isConnected = function () {\r
         return this.socket.socket.connected;\r
     };\r
@@ -280,9 +312,6 @@ _kiwi.model.Gateway = function () {
                 break;\r
 \r
             case 'connect':\r
-                if (!_kiwi.app.connections.getByConnectionId(data.server)) {\r
-                    _kiwi.app.connections.add(new _kiwi.model.Network({connection_id: data.server}));\r
-                }\r
                 that.set('nick', data.nick);\r
                 break;\r
 \r