From: Darren Date: Thu, 3 Apr 2014 15:22:31 +0000 (+0100) Subject: Moving connection logic into gateway.js X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=28b4b095adeee5467d04c679a9c464d0a83319e2;p=KiwiIRC.git Moving connection logic into gateway.js --- diff --git a/client/src/models/gateway.js b/client/src/models/gateway.js index c602437..1e8c8bf 100644 --- a/client/src/models/gateway.js +++ b/client/src/models/gateway.js @@ -126,6 +126,11 @@ _kiwi.model.Gateway = function () { this.socket.on('error', function (e) { console.log("_kiwi.gateway.socket.on('error')", {reason: e}); + if (that.connect_callback) { + that.connect_callback(e); + delete that.connect_callback; + } + that.trigger("connect_fail", {reason: e}); }); @@ -181,6 +186,20 @@ _kiwi.model.Gateway = function () { this.newConnection = function(connection_info, callback_fn) { var that = this; + // If not connected, connect first then re-call this function + if (!this.isConnected()) { + this.connect(function(err) { + if (err) { + callback_fn(err); + return; + } + + that.newConnection(connection_info, callback_fn); + }); + + return; + } + this.makeIrcConnection(connection_info, function(err, server_num) { var connection; diff --git a/client/src/models/newconnection.js b/client/src/models/newconnection.js index 2b77b68..c3c4095 100644 --- a/client/src/models/newconnection.js +++ b/client/src/models/newconnection.js @@ -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,