diff --git a/assets/audio/notif_song.mp3 b/assets/audio/notif_song.mp3 new file mode 100644 index 00000000..678dfa4f Binary files /dev/null and b/assets/audio/notif_song.mp3 differ diff --git a/assets/audio/notif_song.ogg b/assets/audio/notif_song.ogg new file mode 100644 index 00000000..d8dc16eb Binary files /dev/null and b/assets/audio/notif_song.ogg differ diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index 1c2ada5a..166a9387 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -1038,6 +1038,13 @@ var ComunicWeb = { //TODO : implement }, + /** + * Notification song system + */ + song: { + //TODO : implement + }, + /** * Notifications utilities */ diff --git a/assets/js/components/notifications/service.js b/assets/js/components/notifications/service.js index 224eca8b..d046f2bd 100644 --- a/assets/js/components/notifications/service.js +++ b/assets/js/components/notifications/service.js @@ -6,6 +6,11 @@ ComunicWeb.components.notifications.service = { + /** + * Last known number of notifications + */ + last_notifs_number: -1, + /** * Init the service * @@ -19,17 +24,18 @@ ComunicWeb.components.notifications.service = { init: function(target, auto_hide, target_conversations){ //Initialize interval - var interval = setInterval(function(){ + var interval = setInterval(() => { //Auto-remove interval if the target has been removed if(!target.isConnected){ ComunicWeb.common.pageTitle.setNotificationsNumber(0); + this.last_notifs_number = -1; return clearInterval(interval); } //Get the number of notifications from the API - ComunicWeb.components.notifications.interface.getAllUnread(function(response){ + ComunicWeb.components.notifications.interface.getAllUnread(response => { //Continue in case of success if(response.error) @@ -58,8 +64,17 @@ ComunicWeb.components.notifications.service = { } + //Sum notification number + let total_number_notifs = response.notifications + response.conversations; + //Update page title too - ComunicWeb.common.pageTitle.setNotificationsNumber(response.notifications + response.conversations); + ComunicWeb.common.pageTitle.setNotificationsNumber(total_number_notifs); + + //Play song if required + if(this.last_notifs_number != -1 && total_number_notifs > this.last_notifs_number) + ComunicWeb.components.notifications.song.play(); + + this.last_notifs_number = total_number_notifs; }); }, 2000); diff --git a/assets/js/components/notifications/song.js b/assets/js/components/notifications/song.js new file mode 100644 index 00000000..e79c160f --- /dev/null +++ b/assets/js/components/notifications/song.js @@ -0,0 +1,41 @@ +/** + * Notification song + * + * @author Pierre HUBERT + */ + +ComunicWeb.components.notifications.song = { + + /** + * Song element : null by default + */ + songElem: null, + + /** + * Play notification song once + */ + play: function(){ + + //Create song element if required + if(this.songElem == null){ + this.songElem = createElem2({ + type: "audio" + }); + + createElem2({ + type: "source", + appendTo: this.songElem, + src: ComunicWeb.__config.assetsURL + "audio/notif_song.mp3" + }); + + createElem2({ + type: "source", + appendTo: this.songElem, + src: ComunicWeb.__config.assetsURL + "audio/notif_song.ogg" + }); + } + + //Play song + this.songElem.play(); + } +} \ No newline at end of file diff --git a/system/config/dev.config.php b/system/config/dev.config.php index d957b964..fbff00c2 100644 --- a/system/config/dev.config.php +++ b/system/config/dev.config.php @@ -396,6 +396,7 @@ class Dev { "js/components/notifications/dropdown.js", "js/components/notifications/service.js", "js/components/notifications/interface.js", + "js/components/notifications/song.js", "js/components/notifications/ui.js", "js/components/notifications/utils.js",