Play a song when new notifications arrives.

This commit is contained in:
Pierre HUBERT 2018-11-24 18:54:02 +01:00
parent 46bb22b17b
commit 5c19d9c04c
6 changed files with 67 additions and 3 deletions

BIN
assets/audio/notif_song.mp3 Normal file

Binary file not shown.

BIN
assets/audio/notif_song.ogg Normal file

Binary file not shown.

View File

@ -1038,6 +1038,13 @@ var ComunicWeb = {
//TODO : implement
},
/**
* Notification song system
*/
song: {
//TODO : implement
},
/**
* Notifications utilities
*/

View File

@ -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);

View File

@ -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();
}
}

View File

@ -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",