Refactor: retry polling in a dedicated function
This commit is contained in:
parent
3315e7511d
commit
915c99da38
22
trivabble.js
22
trivabble.js
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue