Disconnected page only shown after 10 seconds disconnected

This commit is contained in:
Pax1601 2025-07-29 18:59:02 +02:00 committed by GitHub
parent de1f233848
commit 8ef86e75f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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);
}
};