mirror of https://github.com/vector-im/riot-web
Simplyify
parent
f14d96e069
commit
b0bacdba15
|
@ -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();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue