From 516369fb07384b735e98b2034f8c1adbc40760d0 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Wed, 31 Aug 2016 16:38:37 +0100 Subject: [PATCH 1/2] use promises to mediate access to HTMLAudioElements --- src/CallHandler.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/CallHandler.js b/src/CallHandler.js index 015160a1fe..b0057aec90 100644 --- a/src/CallHandler.js +++ b/src/CallHandler.js @@ -63,13 +63,22 @@ global.mxCalls = { var calls = global.mxCalls; var ConferenceHandler = null; +var audioPromises = {}; + function play(audioId) { // TODO: Attach an invisible element for this instead // which listens? var audio = document.getElementById(audioId); if (audio) { - audio.load(); - audio.play(); + if (audioPromises[audioId]) { + audioPromises[audioId] = audioPromises[audioId].then(()=>{ + audio.load(); + return audio.play()); + }); + } + else { + audioPromises[audioId] = audio.play(); + } } } @@ -78,7 +87,13 @@ function pause(audioId) { // which listens? var audio = document.getElementById(audioId); 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(); + } } } From 35fff744771aae322e6a2e85dc9d891a10700c5f Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Wed, 31 Aug 2016 17:25:41 +0100 Subject: [PATCH 2/2] oops, typo --- src/CallHandler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CallHandler.js b/src/CallHandler.js index b0057aec90..4c68718709 100644 --- a/src/CallHandler.js +++ b/src/CallHandler.js @@ -73,7 +73,7 @@ function play(audioId) { if (audioPromises[audioId]) { audioPromises[audioId] = audioPromises[audioId].then(()=>{ audio.load(); - return audio.play()); + return audio.play(); }); } else {