An easy way to have a 24/7 audio stream of music.

Close the notification by ourself

Changed files
+12 -14
+12 -14
status.xsl
···
let lastTitle = ''
// Store the current mount point
let currentMount = ''
-
// Store the last notification
-
let lastNotification = null
// On every audio element, create a new Plyr instance
document.querySelectorAll('div[data-mount]').forEach((e) => {
···
// If we have permission, send a notification
if ('Notification' in window && Notification.permission === 'granted') {
-
lastNotification = new Notification(
'RRM - Now Playing',
{
body: j.icestats.source.title,
icon: 'https://rita.moe/rita-icon.png',
renotify: true,
-
requireInteraction: false,
tag: 'now-playing',
}
)
}
}
···
if ('Notification' in window && Notification.permission === 'default') {
Notification.requestPermission()
}
-
-
document.addEventListener(
-
'visibilitychange',
-
() => {
-
// If the page is visible, close the last notification
-
if (document.visibilityState === 'visible') {
-
lastNotification?.close()
-
}
-
}
-
)
]]>
</script>
</body>
···
let lastTitle = ''
// Store the current mount point
let currentMount = ''
// On every audio element, create a new Plyr instance
document.querySelectorAll('div[data-mount]').forEach((e) => {
···
// If we have permission, send a notification
if ('Notification' in window && Notification.permission === 'granted') {
+
const lastNotification = new Notification(
'RRM - Now Playing',
{
body: j.icestats.source.title,
icon: 'https://rita.moe/rita-icon.png',
renotify: true,
+
requireInteraction: true,
+
silent: true,
tag: 'now-playing',
}
+
)
+
+
// Close the notification after 10 seconds, as renotify
+
// isn't working perfectly when the track changes
+
setTimeout(
+
(_) => {
+
lastNotification.close()
+
},
+
10000
)
}
}
···
if ('Notification' in window && Notification.permission === 'default') {
Notification.requestPermission()
}
]]>
</script>
</body>