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) { bell: function(rfb) {
if (WebUtil.getConfigVar('bell', 'on') === 'on') { if (WebUtil.getConfigVar('bell', 'on') === 'on') {
document.getElementById('noVNC_bell').play() var promise = document.getElementById('noVNC_bell').play();
.catch(function(e) { // The standards disagree on the return value here
if (promise) {
promise.catch(function(e) {
if (e.name === "NotAllowedError") { if (e.name === "NotAllowedError") {
// Ignore when the browser doesn't let us play audio. // Ignore when the browser doesn't let us play audio.
// It is common that the browsers require audio to be // It is common that the browsers require audio to be
@ -1725,6 +1727,7 @@ var UI = {
} }
}); });
} }
}
}, },
//Helper to add options to dropdown. //Helper to add options to dropdown.