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