fix bug with timer continuing to run after client reconnect

This commit is contained in:
AlecM33
2022-01-17 19:43:34 -05:00
parent 07e7b77d5f
commit 68a6bb8608
2 changed files with 2 additions and 19 deletions

View File

@@ -150,16 +150,6 @@ export class GameTimerManager {
pauseBtn.addEventListener('click', this.pauseListener);
document.getElementById('play-pause').appendChild(pauseBtn);
}
processTimeRemaining (timeRemaining, paused, timerWorker) {
if (paused) {
this.displayPausedTime(timeRemaining);
} else if (timeRemaining === 0) {
this.displayExpiredTime();
} else {
this.resumeGameTimer(timeRemaining, globals.CLOCK_TICK_INTERVAL_MILLIS, null, timerWorker);
}
}
}
function returnHumanReadableTime (milliseconds, tenthsOfSeconds = false) {

View File

@@ -11,19 +11,14 @@ import { injectNavbar } from '../modules/Navbar.js';
const game = () => {
injectNavbar();
let timerWorker;
const timerWorker = new Worker(new URL('../modules/Timer.js', import.meta.url));
const socket = io('/in-game');
socket.on('disconnect', () => {
if (timerWorker) {
timerWorker.terminate();
}
timerWorker = null;
toast('Disconnected. Attempting reconnect...', 'error', true, false);
});
socket.on('connect', () => {
console.log("connect event fired");
socket.emit(globals.COMMANDS.GET_ENVIRONMENT, function (returnedEnvironment) {
timerWorker = new Worker(new URL('../modules/Timer.js', import.meta.url));
prepareGamePage(returnedEnvironment, socket, timerWorker);
});
});
@@ -141,9 +136,7 @@ function processGameState (currentGameState, userId, socket, gameStateRenderer,
break;
}
if (currentGameState.timerParams) {
socket.emit(globals.COMMANDS.GET_TIME_REMAINING, currentGameState.accessCode, (timeRemaining, paused) => {
gameTimerManager.processTimeRemaining(timeRemaining, paused, timerWorker);
});
socket.emit(globals.COMMANDS.GET_TIME_REMAINING, currentGameState.accessCode);
} else {
document.querySelector('#game-timer')?.remove();
document.querySelector('label[for="game-timer"]')?.remove();