Simplyify

pull/21833/head
Will Hunt 2019-04-19 13:21:58 +01:00
parent f14d96e069
commit b0bacdba15
1 changed files with 5 additions and 12 deletions

View File

@ -109,30 +109,23 @@ const Notifier = {
return null;
}
url = MatrixClientPeg.get().mxcUrlToHttp(url);
this.notifSoundsByRoom.set(room.roomId, url);
return url;
},
_playAudioNotification: function(ev, room) {
_getSoundForRoom(room).then((soundUrl) => {
this._getSoundForRoom(room).then((soundUrl) => {
console.log(`Got sound ${soundUrl || "default"} for ${room.roomId}`);
// XXX: How do we ensure this is a sound file and not
// going to be exploited?
const selector = document.querySelector(`audio source[src='${soundUrl}']`) || "#messageAudio";
let audioElement = null;
const selector = document.querySelector(soundUrl ? `audio[src='${soundUrl}']` : "#messageAudio");
let audioElement = selector;
if (!selector) {
if (!soundUrl) {
console.error("Tried to play alert sound but missing #messageAudio")
return
}
audioElement = new HTMLAudioElement();
let sourceElement = new HTMLSourceElement();
// XXX: type
sourceElement.src = soundUrl;
audioElement.appendChild(sourceElement);
document.appendChild(audioElement);
} else {
audioElement = selector.parentNode;
audioElement = new Audio(soundUrl);
document.body.appendChild(audioElement);
}
audioElement.play();
});