ComunicWeb/assets/js/components/notifications/song.js

50 lines
990 B
JavaScript
Raw Normal View History

/**
* Notification song
*
* @author Pierre HUBERT
*/
2021-04-11 11:52:18 +00:00
const NotificationsSong = {
/**
* Song element : null by default
2021-04-11 12:02:17 +00:00
*
* @type {HTMLAudioElement}
*/
songElem: null,
2021-04-11 12:02:17 +00:00
/**
* Check whether notifications song is enabled or not
*/
enableSong: false,
/**
* Play notification song once
*/
play: function(){
2021-04-11 12:02:17 +00:00
if (!NotificationsSong.enableSong)
return;
//Create song element if required
2021-04-11 12:02:17 +00:00
if(NotificationsSong.songElem == null){
NotificationsSong.songElem = new SongPlayer([
2019-01-26 14:26:49 +00:00
ComunicWeb.__config.assetsURL + "audio/notif_song.mp3",
ComunicWeb.__config.assetsURL + "audio/notif_song.ogg"
]);
}
//Play song
2021-04-11 12:02:17 +00:00
NotificationsSong.songElem.playOnce();
}
}
// Get notification settings as soon as the page is loaded
document.addEventListener("wsOpen", async () => {
try {
const settings = await SettingsInterface.getNotifications();
NotificationsSong.enableSong = settings.allow_notifications_sound;
} catch(e) {
console.error(e);
}
2021-04-11 12:02:17 +00:00
})