Refactor: retry polling in a dedicated function

This commit is contained in:
Raphaël Jakse 2020-04-04 15:39:10 +02:00
parent 3315e7511d
commit 915c99da38
1 changed files with 13 additions and 9 deletions

View File

@ -669,6 +669,18 @@
}
}
function retryPolling() {
pollingServer = false;
pollingReady = false;
if (retriedImmediately) {
setTimeout(sendCmds.bind(null, []), POLLING_DELAY);
} else {
retriedImmediately = true;
sendCmds()
}
}
function send(data) {
if (!pollingReady && ((data.cmds && data.cmds.length) && data.cmds[0].cmd !== "joinGame")) {
sendCmds();
@ -749,15 +761,7 @@
}
} else if (xhr.readyState === 4) {
if (thisRequestIsPolling) {
pollingServer = false;
pollingReady = false;
if (retriedImmediately) {
setTimeout(sendCmds.bind(null, []), POLLING_DELAY);
} else {
retriedImmediately = true;
sendCmds()
}
retryPolling();
return;
}