From 1db80aa45c54acd22906b5c59beb7b367b831077 Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Fri, 13 May 2022 20:31:53 +0200 Subject: [PATCH] Fix: Overflow of performance entrys, unnecessary loading of sounds --- src/static/js/synced-timer.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/static/js/synced-timer.js b/src/static/js/synced-timer.js index 98b3095..0e16843 100644 --- a/src/static/js/synced-timer.js +++ b/src/static/js/synced-timer.js @@ -47,8 +47,10 @@ document.addEventListener('alpine:init', () => { scheduleNextRequest() { setTimeout(() => { let requestUrl; + // Clear timings to avoid overflow + performance.clearResourceTimings(); // Add a request Id to be able to identify this request later on - fetch(`/api/${username}?id=${parseInt(performance.now())}`) + fetch(`/api/${username}?id=${parseInt(performance.now()) % 10000}`) .then((response) => { requestUrl = response.url return response.json() @@ -119,10 +121,6 @@ document.addEventListener('alpine:init', () => { this.audioPlayer.play().then(() => { this.isAvailable = true this.hasBeenTested = true - - this.preloadSound(this.sounds.beep) - this.preloadSound(this.sounds.countdown) - }).catch((error) => { console.warn("Audio permission not granted!") this.isAvailable = false @@ -134,7 +132,7 @@ document.addEventListener('alpine:init', () => { if (!this.audioPlayer.paused || !this.isAvailable || this.isDisabledByUser || this.isDisabledByServer || this.replayLocked) { return; } - if (this.audioPlayer.src !== soundFile) { + if (!this.audioPlayer.src.endsWith(soundFile)) { this.audioPlayer.src = soundFile; } this.replayLocked = true; @@ -142,7 +140,7 @@ document.addEventListener('alpine:init', () => { }, preloadSound(soundFile) { - if (this.audioPlayer.src === soundFile) { + if (this.audioPlayer.src.endsWith(soundFile)) { return; } console.log(`Preloading sound ${soundFile}`)