2017-12-07 18:11:23 +00:00
|
|
|
// make router usable as it
|
|
|
|
const router = window._router_;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (1) Emergency channel
|
|
|
|
---------------------------------------------------------*/
|
2017-12-07 19:06:45 +00:00
|
|
|
window.wsc_emergency = wsc.channel('emergency/31').listen(function(msg, err){
|
2017-12-07 18:11:23 +00:00
|
|
|
|
|
|
|
/* (1) Manage error */
|
|
|
|
if( msg == null && err != null )
|
|
|
|
return infobox.show('Erreur de connexion WebSocket@emergency ('+err+')', 'error', 3000);
|
|
|
|
|
|
|
|
/* (2) Manage wsclient error */
|
|
|
|
if( typeof msg.error != 'boolean' || msg.error !== false )
|
|
|
|
return infobox.show('Erreur de connexion WebSocket@emergency', 'warning', 3000);
|
|
|
|
|
2017-12-07 21:16:15 +00:00
|
|
|
/* (3) If message(s) to add */
|
|
|
|
if( msg.add != null ){
|
2017-12-07 18:11:23 +00:00
|
|
|
|
2017-12-07 21:16:15 +00:00
|
|
|
// {1} Play sound if 1msg received + not already on page //
|
|
|
|
// note: 1msg means a new message but not the page load past buffer
|
|
|
|
if( msg.add.length == 1 && router.app.$route.path != '/emergency' )
|
|
|
|
( new Audio('https://notificationsounds.com/message-tones/communication-channel-519/download/mp3') ).play();
|
2017-12-07 18:11:23 +00:00
|
|
|
|
2017-12-07 21:16:15 +00:00
|
|
|
// {2} Add messages to stack //
|
2017-12-07 22:19:49 +00:00
|
|
|
for( var id in msg.add ){
|
|
|
|
|
|
|
|
var tmp = msg.add[id]; // add id to data
|
|
|
|
tmp.id = id;
|
|
|
|
|
|
|
|
gstore.data.notif.emergency.data.push(tmp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// if( gstore.data.notif.emergency.data[id] == null )
|
|
|
|
// gstore.data.notif.emergency.data[id] = msg.add[id];
|
2017-12-07 18:11:23 +00:00
|
|
|
|
2017-12-07 21:16:15 +00:00
|
|
|
// {3} Add notification count if not already on page //
|
|
|
|
if( router.app.$route.path != '/emergency' )
|
|
|
|
gstore.data.notif.emergency.count += msg.add.length;
|
2017-12-07 18:11:23 +00:00
|
|
|
|
2017-12-07 21:16:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* (4) If message(s) to del */
|
|
|
|
if( msg.del != null ){
|
|
|
|
|
|
|
|
// {1} Rem messages from stack //
|
2017-12-07 22:19:49 +00:00
|
|
|
for( var id of gstore.data.notif.emergency.data )
|
2017-12-07 22:27:39 +00:00
|
|
|
if( msg.del[ gstore.data.notif.emergency.data[id].id ] != null )
|
2017-12-07 21:16:15 +00:00
|
|
|
delete gstore.data.notif.emergency.data[id];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (5) If message(s) to update */
|
|
|
|
if( msg.upd != null ){
|
|
|
|
|
|
|
|
// {1} Update messages in stack //
|
2017-12-07 22:19:49 +00:00
|
|
|
for( var id of gstore.data.notif.emergency.data )
|
2017-12-07 22:27:39 +00:00
|
|
|
if( msg.upd[ gstore.data.notif.emergency.data[id].id ] != null )
|
2017-12-07 22:19:49 +00:00
|
|
|
gstore.data.notif.emergency.data[id] = msg.upd;
|
2017-12-07 21:16:15 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (6) Remove loader */
|
2017-12-07 18:11:23 +00:00
|
|
|
gstore.data.msg_pending.emergency = false;
|
|
|
|
|
|
|
|
}).send({name: _SERVER.session.name});
|
|
|
|
|
2017-12-07 21:16:15 +00:00
|
|
|
|
|
|
|
|
2017-12-07 18:11:23 +00:00
|
|
|
/* (2) Event channel
|
|
|
|
---------------------------------------------------------*/
|
2017-12-07 19:06:45 +00:00
|
|
|
window.wsc_event = wsc.channel('event/31').listen(function(msg, err){
|
2017-12-07 18:11:23 +00:00
|
|
|
|
|
|
|
/* (1) Manage error */
|
|
|
|
if( msg == null && err != null )
|
|
|
|
return infobox.show('Erreur de connexion WebSocket@event ('+err+')', 'error', 3000);
|
|
|
|
|
|
|
|
/* (2) Manage wsclient error */
|
|
|
|
if( typeof msg.error != 'boolean' || msg.error !== false )
|
|
|
|
return infobox.show('Erreur de connexion WebSocket@event', 'warning', 3000);
|
|
|
|
|
2017-12-07 21:16:15 +00:00
|
|
|
/* (3) If message(s) to add */
|
|
|
|
if( msg.add != null ){
|
2017-12-07 18:11:23 +00:00
|
|
|
|
2017-12-07 21:16:15 +00:00
|
|
|
// {1} Play sound if 1msg received + not already on page //
|
|
|
|
// note: 1msg means a new message but not the page load past buffer
|
|
|
|
if( msg.add.length == 1 && router.app.$route.path != '/event' )
|
|
|
|
( new Audio('https://notificationsounds.com/message-tones/communication-channel-519/download/mp3') ).play();
|
2017-12-07 18:11:23 +00:00
|
|
|
|
2017-12-07 21:16:15 +00:00
|
|
|
// {2} Add messages to stack //
|
2017-12-07 21:48:28 +00:00
|
|
|
for( var id in msg.add )
|
|
|
|
if( gstore.data.notif.event.data[id] == null )
|
|
|
|
gstore.data.notif.event.data[id] = msg.add[id];
|
2017-12-07 18:11:23 +00:00
|
|
|
|
2017-12-07 21:16:15 +00:00
|
|
|
// {3} Add notification count if not already on page //
|
|
|
|
if( router.app.$route.path != '/event' )
|
|
|
|
gstore.data.notif.event.count += msg.add.length;
|
2017-12-07 18:11:23 +00:00
|
|
|
|
2017-12-07 21:16:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* (4) If message(s) to del */
|
|
|
|
if( msg.del != null ){
|
|
|
|
|
|
|
|
// {1} Rem messages from stack //
|
|
|
|
for( var id of msg.del )
|
|
|
|
if( gstore.data.notif.event.data[id] != null )
|
|
|
|
delete gstore.data.notif.event.data[id];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (5) If message(s) to update */
|
|
|
|
if( msg.upd != null ){
|
|
|
|
|
|
|
|
// {1} Update messages in stack //
|
|
|
|
for( var id of msg.upd )
|
|
|
|
if( gstore.data.notif.event.data[id] != null )
|
|
|
|
gstore.data.notif.event.data[id] = msg.upd[id];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (6) Remove loader */
|
2017-12-07 18:11:23 +00:00
|
|
|
gstore.data.msg_pending.event = false;
|
|
|
|
|
|
|
|
|
|
|
|
}).send({name: _SERVER.session.name});
|
|
|
|
|
2017-12-07 21:16:15 +00:00
|
|
|
|
|
|
|
|
2017-12-07 18:11:23 +00:00
|
|
|
/* (3) Message channel
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
window.wsc_chat = wsc.channel('chat').listen(function(msg, err){
|
|
|
|
|
|
|
|
/* (1) Manage error */
|
|
|
|
if( msg == null && err != null )
|
|
|
|
return infobox.show('Erreur de connexion WebSocket@chat ('+err+')', 'error', 3000);
|
|
|
|
|
|
|
|
/* (2) Manage wsclient error */
|
|
|
|
if( typeof msg.error != 'boolean' || msg.error !== false )
|
|
|
|
return infobox.show('Erreur de connexion WebSocket@chat', 'warning', 3000);
|
|
|
|
|
|
|
|
/* (3) If no message -> exit */
|
|
|
|
if( msg.msg == null )
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* (4) Play sound if 1msg received + not already on page */
|
|
|
|
// note: 1msg means a new message but not the page load past buffer
|
|
|
|
if( msg.msg.length == 1 && router.app.$route.path != '/inbox' )
|
|
|
|
( new Audio('https://notificationsounds.com/message-tones/communication-channel-519/download/mp3') ).play();
|
|
|
|
|
|
|
|
/* (5) Add messages to stack */
|
|
|
|
gstore.data.notif.inbox.data = gstore.data.notif.inbox.data.concat( msg.msg );
|
|
|
|
|
|
|
|
/* (6) Add notification count if not already on page */
|
|
|
|
if( router.app.$route.path != '/inbox' )
|
|
|
|
gstore.data.notif.inbox.count += msg.msg.length;
|
|
|
|
|
|
|
|
/* (7) Remove loader */
|
|
|
|
gstore.data.msg_pending.inbox = false;
|
|
|
|
|
|
|
|
|
|
|
|
}).send({name: _SERVER.session.name});
|