diff options
author | Roslot <pines@null.net> | 2019-05-12 04:35:04 +0200 |
---|---|---|
committer | Roslot <pines@null.net> | 2019-05-12 04:35:04 +0200 |
commit | 1fb02f4e79b2d0936d00ff985a8a360f97a1a15e (patch) | |
tree | e52d2a2bbff3bfd592edbaef8d093883af412e58 /client | |
parent | Added notifications and sound alerts in client.js (diff) | |
download | hackchat-1fb02f4e79b2d0936d00ff985a8a360f97a1a15e.tar.gz hackchat-1fb02f4e79b2d0936d00ff985a8a360f97a1a15e.zip |
Fixed audio on ff, chrome, edge
Diffstat (limited to 'client')
-rw-r--r-- | client/audio/notify.mp3 | bin | 0 -> 35013 bytes | |||
-rw-r--r-- | client/audio/notify.ogg | bin | 65732 -> 0 bytes | |||
-rw-r--r-- | client/client.js | 32 | ||||
-rw-r--r-- | client/index.html | 4 |
4 files changed, 23 insertions, 13 deletions
diff --git a/client/audio/notify.mp3 b/client/audio/notify.mp3 Binary files differnew file mode 100644 index 0000000..f9f203a --- /dev/null +++ b/client/audio/notify.mp3 diff --git a/client/audio/notify.ogg b/client/audio/notify.ogg Binary files differdeleted file mode 100644 index 20c1a35..0000000 --- a/client/audio/notify.ogg +++ /dev/null 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 @@ </head> <body> - <audio style="display: none" id="notify-sound" preload="auto" src="audio/notify.ogg"> - <source src="audio/notify.ogg" type="audio/ogg"> + <audio style="display: none" id="notify-sound" preload="auto" src="audio/notify.mp3"> + <source src="audio/notify.mp3" type="audio/ogg"> </audio> <article class="container"> <div id="messages" class="messages"></div> |