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.

This commit is contained in:
Julian Lam
2015-03-10 11:52:32 -04:00
parent 724df69561
commit 2a80140e70
3 changed files with 10 additions and 10 deletions

View File

@@ -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) {

View File

@@ -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;

View File

@@ -6,11 +6,11 @@
<form>
<div class="form-group">
<label for="maxReconnectionAttempts">Max Reconnection Attempts</label>
<input class="form-control" id="maxReconnectionAttempts" type="text" value="5" data-field="maxReconnectionAttempts" />
<input class="form-control" id="maxReconnectionAttempts" type="text" value="5" placeholder="Default: 5" data-field="maxReconnectionAttempts" />
</div>
<div class="form-group">
<label for="reconnectionDelay">Reconnection Delay</label>
<input class="form-control" id="reconnectionDelay" type="text" value="200" data-field="reconnectionDelay" />
<input class="form-control" id="reconnectionDelay" type="text" value="1500" placeholder="Default: 1500" data-field="reconnectionDelay" />
</div>
</form>
</div>