From 2a80140e704b35c694640ba5f59edab69a4a4e60 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 10 Mar 2015 11:52:32 -0400 Subject: [PATCH] fixed issue where socket.io would no longer reconnect perpetually, new behaviour waits 10x the reconnect delay, and then starts over. Also upped the reconnection delay default to 1.5s. --- public/src/app.js | 14 +++++++------- src/controllers/api.js | 2 +- src/views/admin/settings/sockets.tpl | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/public/src/app.js b/public/src/app.js index 53e43e86fc..d1f6ab93bc 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -17,12 +17,12 @@ app.cacheBuster = null; function socketIOConnect() { var ioParams = { reconnectionAttempts: config.maxReconnectionAttempts, - reconnectionDelay : config.reconnectionDelay, + reconnectionDelay: config.reconnectionDelay, transports: config.socketioTransports, path: config.relative_path + '/socket.io' }; - socket = io.connect(config.websocketAddress, ioParams); + socket = io(config.websocketAddress, ioParams); reconnecting = false; socket.on('event:connect', function () { @@ -41,11 +41,6 @@ app.cacheBuster = null; }); socket.on('reconnecting', function (attempt) { - if(attempt === parseInt(config.maxReconnectionAttempts, 10)) { - socket.io.attempts = 0; - return; - } - reconnecting = true; var reconnectEl = $('#reconnect'); @@ -74,6 +69,11 @@ app.cacheBuster = null; socket.on('event:alert', function(data) { app.alert(data); }); + + socket.on('reconnect_failed', function() { + // Wait ten times the reconnection delay and then start over + setTimeout(socket.connect.bind(socket), parseInt(config.reconnectionDelay, 10) * 10); + }); } function onSocketConnect(data) { diff --git a/src/controllers/api.js b/src/controllers/api.js index c98fd79e0c..8be2211ca1 100644 --- a/src/controllers/api.js +++ b/src/controllers/api.js @@ -51,7 +51,7 @@ apiController.getConfig = function(req, res, next) { config.disableSocialButtons = parseInt(meta.config.disableSocialButtons, 10) === 1; config.disableChat = parseInt(meta.config.disableChat, 10) === 1; config.maxReconnectionAttempts = meta.config.maxReconnectionAttempts || 5; - config.reconnectionDelay = meta.config.reconnectionDelay || 200; + config.reconnectionDelay = meta.config.reconnectionDelay || 1500; config.tagsPerTopic = meta.config.tagsPerTopic || 5; config.minimumTagLength = meta.config.minimumTagLength || 3; config.maximumTagLength = meta.config.maximumTagLength || 15; diff --git a/src/views/admin/settings/sockets.tpl b/src/views/admin/settings/sockets.tpl index ab24ab2970..94ef41bf56 100644 --- a/src/views/admin/settings/sockets.tpl +++ b/src/views/admin/settings/sockets.tpl @@ -6,11 +6,11 @@
- +
- +