Always reconnect the socket except when there is an error

Turns out we can get ABNORMAL_CODE (1006) for disconnects where (for
instance) we pause the background page too long. However, in these cases
there is no preceeding ErrorEvent. In contrast, when we have bad
authentication credentials, there is an ErrorEvent. Thus, this change
ensures that we only reconnect if there was no Error.
This commit is contained in:
lilia 2015-03-11 14:06:29 -07:00
parent 5becd80fe9
commit b9969b14b6
2 changed files with 12 additions and 4 deletions

View file

@ -15915,6 +15915,7 @@ window.axolotl.sessions = {
onerror : function() {},
getStatus : function() { return socket.readyState; }
};
var error;
function resetKeepAliveTimer() {
clearTimeout(keepAliveTimer);
@ -15933,16 +15934,19 @@ window.axolotl.sessions = {
};
function onclose(e) {
if (e.code === 1000) { // CLOSE_NORMAL
if (!error) {
reconnectSemaphore--;
setTimeout(connect, reconnectTimeout);
} else {
}
if (e !== 1000 ) { // CLOSE_NORMAL
console.log('websocket closed', e.code);
}
socketWrapper.onclose(e);
};
function onerror(e) {
error = e;
console.log('websocket error');
socketWrapper.onerror(e);
};

View file

@ -35,6 +35,7 @@
onerror : function() {},
getStatus : function() { return socket.readyState; }
};
var error;
function resetKeepAliveTimer() {
clearTimeout(keepAliveTimer);
@ -53,16 +54,19 @@
};
function onclose(e) {
if (e.code === 1000) { // CLOSE_NORMAL
if (!error) {
reconnectSemaphore--;
setTimeout(connect, reconnectTimeout);
} else {
}
if (e !== 1000 ) { // CLOSE_NORMAL
console.log('websocket closed', e.code);
}
socketWrapper.onclose(e);
};
function onerror(e) {
error = e;
console.log('websocket error');
socketWrapper.onerror(e);
};