mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Disconnected page only shown after 10 seconds disconnected
This commit is contained in:
parent
de1f233848
commit
8ef86e75f0
@ -44,6 +44,7 @@ export class ServerManager {
|
||||
#requests: { [key: string]: XMLHttpRequest } = {};
|
||||
#updateMode = "normal"; // normal or awacs
|
||||
#activeCommandMode = "";
|
||||
#failedRequestEpoch: number | null = null;
|
||||
|
||||
constructor() {
|
||||
this.#lastUpdateTimes[UNITS_URI] = Date.now();
|
||||
@ -131,6 +132,7 @@ export class ServerManager {
|
||||
if (xmlHttp.status == 200) {
|
||||
/* Success */
|
||||
this.setConnected(true);
|
||||
this.#failedRequestEpoch = null;
|
||||
if (xmlHttp.responseType == "arraybuffer") this.#lastUpdateTimes[uri] = callback(xmlHttp.response);
|
||||
else {
|
||||
/* Check if the response headers contain the enabled command modes and set them */
|
||||
@ -153,8 +155,9 @@ export class ServerManager {
|
||||
WrongCredentialsEvent.dispatch();
|
||||
errorCallback && errorCallback(xmlHttp.status);
|
||||
} else {
|
||||
/* Failure, probably disconnected */
|
||||
this.setConnected(false);
|
||||
/* Failure, probably disconnected. If not a single good message has been received in 10 seconds assume the connection is down */
|
||||
if (this.#failedRequestEpoch === null) this.#failedRequestEpoch = Date.now();
|
||||
else if (Date.now() - this.#failedRequestEpoch > 10000) this.setConnected(false);
|
||||
errorCallback && errorCallback(xmlHttp.status);
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user