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() {
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}`)