Merge pull request #433 from matrix-org/matthew/audio-promises
use promises to mediate access to HTMLAudioElements
This commit is contained in:
commit
dae250b3a3
1 changed files with 18 additions and 3 deletions
|
@ -63,13 +63,22 @@ global.mxCalls = {
|
||||||
var calls = global.mxCalls;
|
var calls = global.mxCalls;
|
||||||
var ConferenceHandler = null;
|
var ConferenceHandler = null;
|
||||||
|
|
||||||
|
var audioPromises = {};
|
||||||
|
|
||||||
function play(audioId) {
|
function play(audioId) {
|
||||||
// TODO: Attach an invisible element for this instead
|
// TODO: Attach an invisible element for this instead
|
||||||
// which listens?
|
// which listens?
|
||||||
var audio = document.getElementById(audioId);
|
var audio = document.getElementById(audioId);
|
||||||
if (audio) {
|
if (audio) {
|
||||||
|
if (audioPromises[audioId]) {
|
||||||
|
audioPromises[audioId] = audioPromises[audioId].then(()=>{
|
||||||
audio.load();
|
audio.load();
|
||||||
audio.play();
|
return audio.play();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
audioPromises[audioId] = audio.play();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +87,13 @@ function pause(audioId) {
|
||||||
// which listens?
|
// which listens?
|
||||||
var audio = document.getElementById(audioId);
|
var audio = document.getElementById(audioId);
|
||||||
if (audio) {
|
if (audio) {
|
||||||
audio.pause();
|
if (audioPromises[audioId]) {
|
||||||
|
audioPromises[audioId] = audioPromises[audioId].then(()=>audio.pause());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// pause doesn't actually return a promise, but might as well do this for symmetry with play();
|
||||||
|
audioPromises[audioId] = audio.pause();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue