Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Catch exceptions when we can't play audio
Browse files Browse the repository at this point in the history
...or try to: the chrome debugger still breakpoints, even when we
catch the exception.

Related to, but probably does not fix element-hq/element-web#7657
  • Loading branch information
dbkr committed Nov 21, 2019
1 parent 6597e0b commit 5d84761
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/CallHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,26 @@ function play(audioId) {
// which listens?
const audio = document.getElementById(audioId);
if (audio) {
const playAudio = async () => {
try {
// This still causes the chrome debugger to break on promise rejection if
// the promise is rejected, even though we're catching the exception.
await audio.play();
} catch (e) {
// This is usually because the user hasn't interacted with the document,
// or chrome doesn't think so and is denying the request. Not sure what
// we can really do here...
// https://github.com/vector-im/riot-web/issues/7657
console.log("Unable to play audio clip", e);
}
};
if (audioPromises[audioId]) {
audioPromises[audioId] = audioPromises[audioId].then(()=>{
audio.load();
return audio.play();
return playAudio();
});
} else {
audioPromises[audioId] = audio.play();
audioPromises[audioId] = playAudio();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const Notifier = {
}
document.body.appendChild(audioElement);
}
audioElement.play();
await audioElement.play();
} catch (ex) {
console.warn("Caught error when trying to fetch room notification sound:", ex);
}
Expand Down

0 comments on commit 5d84761

Please sign in to comment.