mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 21:22:46 +08:00
FIX: improves chat audio notification reliability (#27089)
Debouncing the audio was causing the audio to be lost sometimes, somewhat randomly. It's not supposed to be necessary. The commit also refactors the code to async/await.
This commit is contained in:
parent
fb9a43c282
commit
7a0c4c5296
|
@ -87,7 +87,7 @@ export default class PreferencesChatController extends Controller {
|
|||
@action
|
||||
onChangeChatSound(sound) {
|
||||
if (sound) {
|
||||
this.chatAudioManager.playImmediately(sound);
|
||||
this.chatAudioManager.play(sound);
|
||||
}
|
||||
this.model.set("user_option.chat_sound", sound);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
import Service from "@ember/service";
|
||||
import { isTesting } from "discourse-common/config/environment";
|
||||
import { getURLWithCDN } from "discourse-common/lib/get-url";
|
||||
import { debounce } from "discourse-common/utils/decorators";
|
||||
|
||||
const AUDIO_DEBOUNCE_DELAY = 3000;
|
||||
|
||||
export const CHAT_SOUNDS = {
|
||||
bell: [{ src: "/plugins/chat/audio/bell.mp3", type: "audio/mpeg" }],
|
||||
|
@ -39,16 +36,7 @@ export default class ChatAudioManager extends Service {
|
|||
this._audioCache = {};
|
||||
}
|
||||
|
||||
playImmediately(soundName) {
|
||||
return this._play(soundName);
|
||||
}
|
||||
|
||||
@debounce(AUDIO_DEBOUNCE_DELAY, true)
|
||||
play(soundName) {
|
||||
return this._play(soundName);
|
||||
}
|
||||
|
||||
_play(soundName) {
|
||||
async play(soundName) {
|
||||
const audio =
|
||||
this._audioCache[soundName] || this._audioCache[DEFAULT_SOUND_NAME];
|
||||
|
||||
|
@ -63,13 +51,15 @@ export default class ChatAudioManager extends Service {
|
|||
}
|
||||
}
|
||||
|
||||
return audio.play().catch(() => {
|
||||
try {
|
||||
await audio.play();
|
||||
} catch (e) {
|
||||
if (!isTesting()) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.info(
|
||||
"[chat] User needs to interact with DOM before we can play notification sounds."
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user