Merge pull request #590 from Pax1601/532-stop-any-previous-connection-requests-before-connecting-again

Added code to clear any previous connection attempt
This commit is contained in:
Pax1601 2023-11-24 11:50:32 +01:00 committed by GitHub
commit 915020ddc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,6 +20,7 @@ export class ServerManager {
#demoEnabled = false;
#previousMissionElapsedTime:number = 0; // Track if mission elapsed time is increasing (i.e. is the server paused)
#serverIsPaused: boolean = false;
#intervals: number[] = [];
constructor() {
this.#lastUpdateTimes[UNITS_URI] = Date.now();
@ -404,7 +405,11 @@ export class ServerManager {
}
startUpdate() {
window.setInterval(() => {
/* Clear any existing interval */
this.#intervals.forEach((interval: number) => { window.clearInterval(interval); });
this.#intervals = [];
this.#intervals.push(window.setInterval(() => {
if (!this.getPaused()) {
this.getMission((data: MissionData) => {
this.checkSessionHash(data.sessionHash);
@ -412,9 +417,9 @@ export class ServerManager {
return data.time;
});
}
}, 1000);
}, 1000));
window.setInterval(() => {
this.#intervals.push(window.setInterval(() => {
if (!this.getPaused() && getApp().getMissionManager().getCommandModeOptions().commandMode != NONE) {
this.getAirbases((data: AirbasesData) => {
this.checkSessionHash(data.sessionHash);
@ -422,9 +427,9 @@ export class ServerManager {
return data.time;
});
}
}, 10000);
}, 10000));
window.setInterval(() => {
this.#intervals.push(window.setInterval(() => {
if (!this.getPaused() && getApp().getMissionManager().getCommandModeOptions().commandMode != NONE){
this.getBullseye((data: BullseyesData) => {
this.checkSessionHash(data.sessionHash);
@ -432,9 +437,9 @@ export class ServerManager {
return data.time;
});
}
}, 10000);
}, 10000));
window.setInterval(() => {
this.#intervals.push(window.setInterval(() => {
if (!this.getPaused() && getApp().getMissionManager().getCommandModeOptions().commandMode != NONE) {
this.getLogs((data: any) => {
this.checkSessionHash(data.sessionHash);
@ -442,27 +447,27 @@ export class ServerManager {
return data.time;
});
}
}, 1000);
}, 1000));
window.setInterval(() => {
this.#intervals.push(window.setInterval(() => {
if (!this.getPaused() && getApp().getMissionManager().getCommandModeOptions().commandMode != NONE) {
this.getUnits((buffer: ArrayBuffer) => {
var time = getApp().getUnitsManager()?.update(buffer);
return time;
}, false);
}
}, 250);
}, 250));
window.setInterval(() => {
this.#intervals.push(window.setInterval(() => {
if (!this.getPaused() && getApp().getMissionManager().getCommandModeOptions().commandMode != NONE) {
this.getWeapons((buffer: ArrayBuffer) => {
var time = getApp().getWeaponsManager()?.update(buffer);
return time;
}, false);
}
}, 250);
}, 250));
window.setInterval(() => {
this.#intervals.push(window.setInterval(() => {
if (!this.getPaused() && getApp().getMissionManager().getCommandModeOptions().commandMode != NONE) {
this.getUnits((buffer: ArrayBuffer) => {
var time = getApp().getUnitsManager()?.update(buffer);
@ -486,10 +491,10 @@ export class ServerManager {
}
}
}, ( this.getServerIsPaused() ? 500 : 5000 ));
}, ( this.getServerIsPaused() ? 500 : 5000 )));
// Mission clock and elapsed time
window.setInterval( () => {
this.#intervals.push(window.setInterval( () => {
if ( !this.getConnected() || this.#serverIsPaused ) {
return;
@ -503,16 +508,16 @@ export class ServerManager {
csp.setMissionTime( [ mt.h, mt.m, mt.s ].map( n => zeroAppend( n, 2 )).join( ":" ) );
csp.setElapsedTime( new Date( elapsedMissionTime * 1000 ).toISOString().substring( 11, 19 ) );
}, 1000 );
}, 1000));
window.setInterval(() => {
this.#intervals.push(window.setInterval(() => {
if (!this.getPaused() && getApp().getMissionManager().getCommandModeOptions().commandMode != NONE) {
this.getWeapons((buffer: ArrayBuffer) => {
var time = getApp().getWeaponsManager()?.update(buffer);
return time;
}, true);
}
}, 5000);
}, 5000));
}
refreshAll() {