diff --git a/src/utils/sounds.js b/src/utils/sounds.js index 8e0455356..f7ec79699 100644 --- a/src/utils/sounds.js +++ b/src/utils/sounds.js @@ -31,13 +31,22 @@ export const Sounds = { backgroundAudio: null, backgroundInterval: null, - _playSounceOnce(soundFile) { + _playSoundOnce(soundFile) { const file = generateFilePath('spreed', 'img', soundFile) const audio = new Audio(file) audio.volume = 0.75 audio.play() }, + _stopWaiting() { + console.debug('Stop waiting sound') + if (this.backgroundAudio) { + this.backgroundAudio.pause() + this.backgroundAudio = null + } + clearInterval(this.backgroundInterval) + }, + async playWaiting() { if (!store.getters.playSounds) { return @@ -59,19 +68,20 @@ export const Sounds = { return } + if (this.playedWaiting >= 3) { + // Played 3 times, so we stop now. + this._stopWaiting() + } + console.debug('Playing waiting sound') this.backgroundAudio.play() this.playedWaiting++ - if (this.playedWaiting >= 3) { - // Played 3 times, so we stop now. - clearInterval(this.backgroundInterval) - } }, 15000) }, async playJoin(force, playWaitingSound) { - clearInterval(this.backgroundInterval) + this._stopWaiting() if (!store.getters.playSounds) { return @@ -101,12 +111,12 @@ export const Sounds = { if (playWaitingSound) { await this.playWaiting() } else { - this._playSounceOnce('join_call.wav') + this._playSoundOnce('join_call.wav') } }, async playLeave(force, playWaitingSound) { - clearInterval(this.backgroundInterval) + this._stopWaiting() if (!store.getters.playSounds) { return @@ -132,7 +142,7 @@ export const Sounds = { } this.lastPlayedLeave = currentTime - this._playSounceOnce('leave_call.wav') + this._playSoundOnce('leave_call.wav') if (playWaitingSound) { this.playWaiting()