Gateway + Network reconnection methods. Jumpserver improvements
[KiwiIRC.git] / client / assets / src / models / application.js
index 8e9df4bcceafdef5c80bd1b5f4960483e1b9a9b1..7269e461ab471628762a80093175a94870ef98a1 100644 (file)
@@ -345,7 +345,10 @@ _kiwi.model.Application = function () {
              * Handle the reconnections to the kiwi server\r
              */\r
             (function () {\r
+                // 0 = non-reconnecting state. 1 = reconnecting state.\r
                 var gw_stat = 0;\r
+\r
+                // If the current or upcoming disconnect was planned\r
                 var unplanned_disconnect = false;\r
 \r
                 gw.on('disconnect', function (event) {\r
@@ -393,7 +396,7 @@ _kiwi.model.Application = function () {
                         that.message.text(msg, {timeout: 5000});\r
                     }\r
 \r
-                    // Mention the disconnection on every channel\r
+                    // Mention the re-connection on every channel\r
                     _kiwi.app.connections.forEach(function(connection) {\r
                         connection.panels.server.addMsg('', msg, 'action join');\r
 \r
@@ -419,17 +422,25 @@ _kiwi.model.Application = function () {
 \r
 \r
             gw.on('kiwi:jumpserver', function (data) {\r
-                // Switching kiwi server?\r
-                if (typeof data.kiwi_server !== 'undefined') {\r
-                    _kiwi.app.kiwi_server = data.kiwi_server;\r
-                    _kiwi.gateway.set('kiwi_server', data.kiwi_server);\r
-                }\r
+                var serv;\r
+                // No server set? Then nowhere to jump to.\r
+                if (typeof data.kiwi_server === 'undefined')\r
+                    return;\r
+\r
+                serv = data.kiwi_server;\r
+\r
+                // Strip any trailing slash from the end\r
+                if (serv[serv.length-1] === '/')\r
+                    serv = serv.substring(0, serv.length-1);\r
+\r
+                _kiwi.app.kiwi_server = serv;\r
 \r
                 // Force the jumpserver now?\r
                 if (data.force) {\r
                     // Get an interval around 1 minute so everyone doesn't reconnect it all at once\r
                     var jump_server_interval = Math.random() * (90 - 60) + 60;\r
 \r
+                    // Tell the user we are going to disconnect, wait a minute then do the actual reconnect\r
                     var msg = _kiwi.global.i18n.translate('client_models_application_jumpserver_prepare').fetch();\r
                     that.message.text(msg, {timeout: 10000});\r
 \r
@@ -438,7 +449,10 @@ _kiwi.model.Application = function () {
                         that.message.text(msg, {timeout: 8000});\r
 \r
                         setTimeout(function forcedReconnectPartTwo() {\r
-                            _kiwi.gateway.reconnect();\r
+                            _kiwi.gateway.reconnect(function() {\r
+                                // Reconnect all the IRC connections\r
+                                that.connections.forEach(function(con){ con.reconnect(); });\r
+                            });\r
                         }, 5000);\r
 \r
                     }, jump_server_interval * 1000);\r