Moving connection logic into gateway.js
authorDarren <darren@darrenwhitlen.com>
Thu, 3 Apr 2014 15:22:31 +0000 (16:22 +0100)
committerDarren <darren@darrenwhitlen.com>
Thu, 3 Apr 2014 15:22:31 +0000 (16:22 +0100)
client/src/models/gateway.js
client/src/models/newconnection.js

index c60243732ec2bfa1c3e2dc07420105cb421ec25e..1e8c8bfb377d44393aaf223ceab6044873aa60cc 100644 (file)
@@ -126,6 +126,11 @@ _kiwi.model.Gateway = function () {
 \r
         this.socket.on('error', function (e) {\r
             console.log("_kiwi.gateway.socket.on('error')", {reason: e});\r
+            if (that.connect_callback) {\r
+                that.connect_callback(e);\r
+                delete that.connect_callback;\r
+            }\r
+\r
             that.trigger("connect_fail", {reason: e});\r
         });\r
 \r
@@ -181,6 +186,20 @@ _kiwi.model.Gateway = function () {
     this.newConnection = function(connection_info, callback_fn) {\r
         var that = this;\r
 \r
+        // If not connected, connect first then re-call this function\r
+        if (!this.isConnected()) {\r
+            this.connect(function(err) {\r
+                if (err) {\r
+                    callback_fn(err);\r
+                    return;\r
+                }\r
+\r
+                that.newConnection(connection_info, callback_fn);\r
+            });\r
+\r
+            return;\r
+        }\r
+\r
         this.makeIrcConnection(connection_info, function(err, server_num) {\r
             var connection;\r
 \r
index 2b77b688bf315ea1a3684b09965e8abbf321a2f6..c3c4095e58b2eebf81315d656066bcc9ba073d30 100644 (file)
@@ -14,36 +14,12 @@ _kiwi.model.NewConnection = Backbone.Collection.extend({
 
 
     onMakeConnection: function(new_connection_event) {
-        var that = this,
-            transport_path = '',
-            auto_connect_details = new_connection_event;
-
-        this.view.networkConnecting();
-
-        // If not connected already, connect then send the IRC connect info
-        if (!_kiwi.gateway.isConnected()) {
-            _kiwi.gateway.connect(function() {
-                that.makeConnection(new_connection_event);
-            });
-
-        } else {
-            this.makeConnection(new_connection_event);
-        }
-
-
-    },
-
-
-    onKiwiServerNotFound: function() {
-        this.view.showError();
-    },
-
-
-    makeConnection: function(new_connection_event) {
         var that = this;
 
         this.connect_details = new_connection_event;
 
+        this.view.networkConnecting();
+
         _kiwi.gateway.newConnection({
             nick: new_connection_event.nick,
             host: new_connection_event.server,