Client reconnection notification cleanup + fixes
authorDarren <darren@darrenwhitlen.com>
Mon, 4 Aug 2014 15:52:33 +0000 (16:52 +0100)
committerDarren <darren@darrenwhitlen.com>
Mon, 4 Aug 2014 15:52:33 +0000 (16:52 +0100)
client/src/models/application.js
client/src/models/network.js
client/src/views/tabs.js

index 7b4f97147b710672cea1c1e9b89c1d04190b27e1..b81b109090d18edf9c969dcc92676e17ed216810 100644 (file)
                 // 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
-                    unplanned_disconnect = !gw.disconnect_requested;\r
-\r
-                    if (unplanned_disconnect) {\r
-                        var msg = _kiwi.global.i18n.translate('client_models_application_reconnecting').fetch() + '...';\r
-                        that.message.text(msg, {timeout: 10000});\r
-                    }\r
-\r
                     that.view.$el.removeClass('connected');\r
 \r
-                    // Mention the disconnection on every channel\r
-                    _kiwi.app.connections.forEach(function(connection) {\r
-                        connection.panels.server.addMsg('', styleText('quit', {text: msg}), 'action quit');\r
-\r
-                        connection.panels.forEach(function(panel) {\r
-                            if (!panel.isChannel())\r
-                                return;\r
-\r
-                            panel.addMsg('', styleText('quit', {text: msg}), 'action quit');\r
-                        });\r
-                    });\r
-\r
+                    // Reconnection phase will start to kick in\r
                     gw_stat = 1;\r
                 });\r
 \r
 \r
                 gw.on('reconnecting', function (event) {\r
-                    var msg = _kiwi.global.i18n.translate('client_models_application_reconnect_in_x_seconds').fetch(event.delay/1000) + '...';\r
+                    var msg = translateText('client_models_application_reconnect_in_x_seconds', [event.delay/1000]) + '...';\r
 \r
                     // Only need to mention the repeating re-connection messages on server panels\r
                     _kiwi.app.connections.forEach(function(connection) {\r
 \r
                 // After the socket has connected, kiwi handshakes and then triggers a kiwi:connected event\r
                 gw.on('kiwi:connected', function (event) {\r
+                    var msg;\r
+\r
                     that.view.$el.addClass('connected');\r
-                    if (gw_stat !== 1) return;\r
 \r
-                    if (unplanned_disconnect) {\r
-                        var msg = _kiwi.global.i18n.translate('client_models_application_reconnect_successfully').fetch() + ':)';\r
+                    // If we were reconnecting, show some messages we have connected back OK\r
+                    if (gw_stat === 1) {\r
+\r
+                        // No longer in the reconnection state\r
+                        gw_stat = 0;\r
+\r
+                        msg = translateText('client_models_application_reconnect_successfully') + ' :)';\r
                         that.message.text(msg, {timeout: 5000});\r
-                    }\r
 \r
-                    // Mention the re-connection on every channel\r
-                    _kiwi.app.connections.forEach(function(connection) {\r
-                        connection.reconnect();\r
+                        // Mention the re-connection on every channel\r
+                        _kiwi.app.connections.forEach(function(connection) {\r
+                            connection.reconnect();\r
 \r
-                        connection.panels.server.addMsg('', styleText('rejoin', {text: msg}), 'action join');\r
+                            connection.panels.server.addMsg('', styleText('rejoin', {text: msg}), 'action join');\r
 \r
-                        connection.panels.forEach(function(panel) {\r
-                            if (!panel.isChannel())\r
-                                return;\r
+                            connection.panels.forEach(function(panel) {\r
+                                if (!panel.isChannel())\r
+                                    return;\r
 \r
-                            panel.addMsg('', styleText('rejoin', {text: msg}), 'action join');\r
+                                panel.addMsg('', styleText('rejoin', {text: msg}), 'action join');\r
+                            });\r
                         });\r
-                    });\r
+                    }\r
 \r
-                    gw_stat = 0;\r
                 });\r
             })();\r
 \r
                 if (data.force) {\r
                     // Get an interval between 5 and 6 minutes so everyone doesn't reconnect it all at once\r
                     var jump_server_interval = Math.random() * (360 - 300) + 300;\r
+                    jump_server_interval = 1;\r
 \r
                     // Tell the user we are going to disconnect, wait 5 minutes then do the actual reconnect\r
                     var msg = _kiwi.global.i18n.translate('client_models_application_jumpserver_prepare').fetch();\r
index 0fb5fa72547ecef136a4d7ad8382883e3a32f098..df8ac5361999667a73f0c8d5f0f7515b70510c74 100644 (file)
                     that.gateway = _kiwi.global.components.Network(that.get('connection_id'));
                     that.bindGatewayEvents();
 
+                    // Reset each of the panels connection ID
+                    that.panels.forEach(function(panel) {
+                        panel.set('connection_id', connection_id);
+                    });
+
                     callback_fn && callback_fn(err);
 
                 } else {
                 query = new _kiwi.model.Query({name: nick});
                 that.panels.add(query);
             }
-            
+
             // In all cases, show the demanded query
             query.view.show();
         }
index 1830701f3db64a5e5b74e2733eaa8a32f60d2b4e..fc81b4237c84bb12219470ec5f9fa6cb76ffe830 100644 (file)
@@ -24,6 +24,12 @@ _kiwi.view.Tabs = Backbone.View.extend({
             this.model.network.on('change:name', function (network, new_val) {
                 $('span', this.model.server.tab).text(new_val);
             }, this);
+
+            this.model.network.on('change:connection_id', function (network, new_val) {
+                this.model.forEach(function(panel) {
+                    panel.tab.data('connection_id', new_val);
+                });
+            }, this);
         }
     },