Check if <audio>.play() returns a promise

It doesn't always. IE and Edge crashed when trying to play the bell due
to this. Fixes #929.
This commit is contained in:
Samuel Mannehed 2017-10-17 12:16:38 +02:00
parent abfe5b7a37
commit a342ed703f
1 changed files with 5 additions and 2 deletions

View File

@ -1714,8 +1714,10 @@ var UI = {
bell: function(rfb) {
if (WebUtil.getConfigVar('bell', 'on') === 'on') {
document.getElementById('noVNC_bell').play()
.catch(function(e) {
var promise = document.getElementById('noVNC_bell').play();
// The standards disagree on the return value here
if (promise) {
promise.catch(function(e) {
if (e.name === "NotAllowedError") {
// Ignore when the browser doesn't let us play audio.
// It is common that the browsers require audio to be
@ -1724,6 +1726,7 @@ var UI = {
Log.Error("Unable to play bell: " + e);
}
});
}
}
},