Implement reconnection during account loading

This commit is contained in:
Tissevert 2020-02-03 23:34:52 +01:00
parent 49df598d7d
commit 6615a7db65
2 changed files with 8 additions and 0 deletions

View file

@ -77,6 +77,7 @@ function loadAccount() {
fileReader.addEventListener('load', function() {
Save.set(null, JSON.parse(fileReader.result));
var name = restoreName();
Messaging.reset();
if(name != undefined) {
Session.start(name);
}

View file

@ -20,6 +20,7 @@ init();
return {
addEventListener: addEventListener,
isOn: isOn,
reset: reset,
send: send
};
@ -136,3 +137,9 @@ function ping() {
}
}, keepAlivePeriod * s);
}
function reset() {
on = false; // this should be handled by the close event but when other operations are performed right after the reset, the event might not have had time to fire and the other functions, in particular send(), will assume the socket is still open and fail to actually send them instead of gently queueing them for when connectivity goes back up
reconnectDelay = 0.125; // since we're forcing the connection to close, there's no reason to assume the server went down so we manually lower the reconnectDelay to make the reconnection more fluid (there's no point making the user wait the usual 1 s. and the worse that could happen is we overflow the server a little with 3 connection attempts in 1 s.)
ws.close();
}