Fix: Overflow of performance entrys, unnecessary loading of sounds

This commit is contained in:
Dorian Zedler 2022-05-13 20:31:53 +02:00
parent cb03447971
commit 1db80aa45c
Signed by: dorian
GPG key ID: 989DE36109AFA354

View file

@ -47,8 +47,10 @@ document.addEventListener('alpine:init', () => {
scheduleNextRequest() { scheduleNextRequest() {
setTimeout(() => { setTimeout(() => {
let requestUrl; let requestUrl;
// Clear timings to avoid overflow
performance.clearResourceTimings();
// Add a request Id to be able to identify this request later on // 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) => { .then((response) => {
requestUrl = response.url requestUrl = response.url
return response.json() return response.json()
@ -119,10 +121,6 @@ document.addEventListener('alpine:init', () => {
this.audioPlayer.play().then(() => { this.audioPlayer.play().then(() => {
this.isAvailable = true this.isAvailable = true
this.hasBeenTested = true this.hasBeenTested = true
this.preloadSound(this.sounds.beep)
this.preloadSound(this.sounds.countdown)
}).catch((error) => { }).catch((error) => {
console.warn("Audio permission not granted!") console.warn("Audio permission not granted!")
this.isAvailable = false this.isAvailable = false
@ -134,7 +132,7 @@ document.addEventListener('alpine:init', () => {
if (!this.audioPlayer.paused || !this.isAvailable || this.isDisabledByUser || this.isDisabledByServer || this.replayLocked) { if (!this.audioPlayer.paused || !this.isAvailable || this.isDisabledByUser || this.isDisabledByServer || this.replayLocked) {
return; return;
} }
if (this.audioPlayer.src !== soundFile) { if (!this.audioPlayer.src.endsWith(soundFile)) {
this.audioPlayer.src = soundFile; this.audioPlayer.src = soundFile;
} }
this.replayLocked = true; this.replayLocked = true;
@ -142,7 +140,7 @@ document.addEventListener('alpine:init', () => {
}, },
preloadSound(soundFile) { preloadSound(soundFile) {
if (this.audioPlayer.src === soundFile) { if (this.audioPlayer.src.endsWith(soundFile)) {
return; return;
} }
console.log(`Preloading sound ${soundFile}`) console.log(`Preloading sound ${soundFile}`)