diff --git a/js/GUI/Screen/Login.js b/js/GUI/Screen/Login.js index 1d4f2e1..e394759 100644 --- a/js/GUI/Screen/Login.js +++ b/js/GUI/Screen/Login.js @@ -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); } diff --git a/js/Messaging.js b/js/Messaging.js index 3ac2c9a..9aa0558 100644 --- a/js/Messaging.js +++ b/js/Messaging.js @@ -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(); +}