mirror of
https://github.com/hack-chat/main.git
synced 2024-03-22 13:20:33 +08:00
Fixed audio on ff, chrome, edge
This commit is contained in:
parent
53e4968cb4
commit
1fb02f4e79
BIN
client/audio/notify.mp3
Normal file
BIN
client/audio/notify.mp3
Normal file
Binary file not shown.
Binary file not shown.
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue
Block a user