mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-22 12:09:21 +00:00
Play a song when new notifications arrives.
This commit is contained in:
parent
46bb22b17b
commit
5c19d9c04c
BIN
assets/audio/notif_song.mp3
Normal file
BIN
assets/audio/notif_song.mp3
Normal file
Binary file not shown.
BIN
assets/audio/notif_song.ogg
Normal file
BIN
assets/audio/notif_song.ogg
Normal file
Binary file not shown.
@ -1038,6 +1038,13 @@ var ComunicWeb = {
|
||||
//TODO : implement
|
||||
},
|
||||
|
||||
/**
|
||||
* Notification song system
|
||||
*/
|
||||
song: {
|
||||
//TODO : implement
|
||||
},
|
||||
|
||||
/**
|
||||
* Notifications utilities
|
||||
*/
|
||||
|
@ -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);
|
||||
|
41
assets/js/components/notifications/song.js
Normal file
41
assets/js/components/notifications/song.js
Normal 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();
|
||||
}
|
||||
}
|
@ -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",
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user