From 1fb02f4e79b2d0936d00ff985a8a360f97a1a15e Mon Sep 17 00:00:00 2001 From: Roslot Date: Sat, 11 May 2019 22:35:04 -0400 Subject: Fixed audio on ff, chrome, edge --- client/audio/notify.mp3 | Bin 0 -> 35013 bytes client/audio/notify.ogg | Bin 65732 -> 0 bytes client/client.js | 32 +++++++++++++++++++++----------- client/index.html | 4 ++-- 4 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 client/audio/notify.mp3 delete mode 100644 client/audio/notify.ogg (limited to 'client') diff --git a/client/audio/notify.mp3 b/client/audio/notify.mp3 new file mode 100644 index 0000000..f9f203a Binary files /dev/null and b/client/audio/notify.mp3 differ diff --git a/client/audio/notify.ogg b/client/audio/notify.ogg deleted file mode 100644 index 20c1a35..0000000 Binary files a/client/audio/notify.ogg and /dev/null differ diff --git a/client/client.js b/client/client.js index 26974e3..1d4088c 100644 --- a/client/client.js +++ b/client/client.js @@ -128,16 +128,21 @@ function spawnNotification(title, body) { } // Otherwise, we need to ask the user for permission else if (Notification.permission !== "denied") { - Notification.requestPermission().then(function (permission) { - // If the user accepts, let's create a notification - if (permission === "granted") { - var options = { - body: body, - icon: "/favicon-96x96.png" - }; - var n = new Notification(title, options); - } - }); + var notifyPromise = Notification.requestPermission(); + if (notifyPromise) { + notifyPromise.then(function (permission) { + // If the user accepts, let's create a notification + if (permission === "granted") { + var options = { + body: body, + icon: "/favicon-96x96.png" + }; + var n = new Notification(title, options); + } + }).catch(function (error) { + console.error("Problem creating notification:\n" + error); + }); + } } // At last, if the user has denied notifications, and you // want to be respectful, there is no need to bother them any more. @@ -176,7 +181,12 @@ function notify(args) { // Play sound if enabled if (soundSwitch.checked) { - document.getElementById("notify-sound").play() + var soundPromise = document.getElementById("notify-sound").play(); + if (soundPromise) { + soundPromise.catch(function (error) { + console.error("Problem playing sound:\n" + error); + }); + } } } diff --git a/client/index.html b/client/index.html index 86a4c29..6931451 100644 --- a/client/index.html +++ b/client/index.html @@ -16,8 +16,8 @@ -