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:
@@ -15915,6 +15915,7 @@ window.axolotl.sessions = {
|
|||||||
onerror : function() {},
|
onerror : function() {},
|
||||||
getStatus : function() { return socket.readyState; }
|
getStatus : function() { return socket.readyState; }
|
||||||
};
|
};
|
||||||
|
var error;
|
||||||
|
|
||||||
function resetKeepAliveTimer() {
|
function resetKeepAliveTimer() {
|
||||||
clearTimeout(keepAliveTimer);
|
clearTimeout(keepAliveTimer);
|
||||||
@@ -15933,16 +15934,19 @@ window.axolotl.sessions = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function onclose(e) {
|
function onclose(e) {
|
||||||
if (e.code === 1000) { // CLOSE_NORMAL
|
if (!error) {
|
||||||
reconnectSemaphore--;
|
reconnectSemaphore--;
|
||||||
setTimeout(connect, reconnectTimeout);
|
setTimeout(connect, reconnectTimeout);
|
||||||
} else {
|
}
|
||||||
|
if (e !== 1000 ) { // CLOSE_NORMAL
|
||||||
console.log('websocket closed', e.code);
|
console.log('websocket closed', e.code);
|
||||||
}
|
}
|
||||||
socketWrapper.onclose(e);
|
socketWrapper.onclose(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
function onerror(e) {
|
function onerror(e) {
|
||||||
|
error = e;
|
||||||
|
console.log('websocket error');
|
||||||
socketWrapper.onerror(e);
|
socketWrapper.onerror(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -35,6 +35,7 @@
|
|||||||
onerror : function() {},
|
onerror : function() {},
|
||||||
getStatus : function() { return socket.readyState; }
|
getStatus : function() { return socket.readyState; }
|
||||||
};
|
};
|
||||||
|
var error;
|
||||||
|
|
||||||
function resetKeepAliveTimer() {
|
function resetKeepAliveTimer() {
|
||||||
clearTimeout(keepAliveTimer);
|
clearTimeout(keepAliveTimer);
|
||||||
@@ -53,16 +54,19 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
function onclose(e) {
|
function onclose(e) {
|
||||||
if (e.code === 1000) { // CLOSE_NORMAL
|
if (!error) {
|
||||||
reconnectSemaphore--;
|
reconnectSemaphore--;
|
||||||
setTimeout(connect, reconnectTimeout);
|
setTimeout(connect, reconnectTimeout);
|
||||||
} else {
|
}
|
||||||
|
if (e !== 1000 ) { // CLOSE_NORMAL
|
||||||
console.log('websocket closed', e.code);
|
console.log('websocket closed', e.code);
|
||||||
}
|
}
|
||||||
socketWrapper.onclose(e);
|
socketWrapper.onclose(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
function onerror(e) {
|
function onerror(e) {
|
||||||
|
error = e;
|
||||||
|
console.log('websocket error');
|
||||||
socketWrapper.onerror(e);
|
socketWrapper.onerror(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user