2017-11-29 11:29:27 +00:00
|
|
|
/* (1) Imports
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) NPM libs */
|
2017-11-28 12:37:49 +00:00
|
|
|
import Vue from 'vue'
|
2017-12-04 23:00:22 +00:00
|
|
|
import VueRouter from 'vue-router'
|
2017-11-29 11:29:27 +00:00
|
|
|
|
|
|
|
/* (2) Internal libs */
|
2017-12-04 23:00:22 +00:00
|
|
|
import {API} from './lib/api-es6'
|
|
|
|
import {InfoBox} from './lib/infobox-es6'
|
2017-11-29 19:36:30 +00:00
|
|
|
import {WSClient,WSClientBuilder} from './lib/ws-client-es6'
|
2017-12-04 23:00:22 +00:00
|
|
|
import routes from './routes'
|
2017-11-28 12:37:49 +00:00
|
|
|
|
2017-11-29 11:29:27 +00:00
|
|
|
/* (3) Vues */
|
2017-12-01 14:48:13 +00:00
|
|
|
import wrapper_vue from './vue/wrapper.vue'
|
2017-11-29 11:29:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* (2) Initialisation
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) API */
|
|
|
|
window.api = new API("http://ndli1718/api/v/1.0/");
|
|
|
|
|
|
|
|
/* (2) wsclient */
|
2017-11-29 19:36:30 +00:00
|
|
|
window.wsc = new WSClientBuilder("wss://websocket.xdrm.io");
|
2017-11-29 11:29:27 +00:00
|
|
|
|
2017-12-01 14:48:13 +00:00
|
|
|
/* (3) global store init */
|
|
|
|
require('./vue-config');
|
|
|
|
window.gstore.add('server', window._SERVER);
|
2017-12-05 17:41:39 +00:00
|
|
|
window.infobox = new InfoBox(gstore.data.info);
|
2017-12-01 14:48:13 +00:00
|
|
|
|
2017-12-04 23:00:22 +00:00
|
|
|
/* (4) Init vue router */
|
|
|
|
Vue.use(VueRouter);
|
2017-12-05 07:39:24 +00:00
|
|
|
const router = new VueRouter({
|
2017-12-04 23:00:22 +00:00
|
|
|
mode: 'history',
|
|
|
|
routes: routes[0]
|
|
|
|
});
|
|
|
|
|
2017-12-05 07:39:24 +00:00
|
|
|
|
2017-12-04 23:00:22 +00:00
|
|
|
/* (5) Render view */
|
2017-11-28 12:37:49 +00:00
|
|
|
new Vue({
|
2017-12-05 07:39:24 +00:00
|
|
|
el: '#main-vue',
|
|
|
|
router,
|
2017-12-04 23:00:22 +00:00
|
|
|
render: h => h(wrapper_vue)
|
2017-12-05 07:39:24 +00:00
|
|
|
});
|
2017-12-04 10:22:10 +00:00
|
|
|
|
2017-12-05 17:55:07 +00:00
|
|
|
gstore.data.func.nav(router, null);
|
|
|
|
|
2017-12-04 10:22:10 +00:00
|
|
|
|
|
|
|
/* (3) Set WebSocket channels
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Connection channel */
|
2017-12-05 17:58:27 +00:00
|
|
|
/*NO_WS_CONNECT*//*window.wsc_connect = wsc.channel('connect').listen(function(msg, err){
|
2017-12-04 10:22:10 +00:00
|
|
|
|
|
|
|
// {1} Manage error //
|
2017-12-04 16:30:33 +00:00
|
|
|
if( msg == null && err != null )
|
2017-12-05 17:41:39 +00:00
|
|
|
return infobox.show('Erreur de connexion WebSocket@connect ('+err+')', 'error', 3000);
|
2017-12-04 10:22:10 +00:00
|
|
|
|
|
|
|
// {2} Manage wsclient error //
|
2017-12-04 16:30:33 +00:00
|
|
|
if( typeof msg.error != 'boolean' || msg.error !== false )
|
2017-12-05 17:41:39 +00:00
|
|
|
return infobox.show('Erreur de connexion WebSocket@connect', 'warning', 3000);
|
2017-12-04 10:22:10 +00:00
|
|
|
|
|
|
|
// {3} Manage notification //
|
2017-12-04 16:30:33 +00:00
|
|
|
if( msg.connected != null ){
|
|
|
|
console.log('Detected '+msg.connected.length+' new user(s)');
|
2017-12-05 17:41:39 +00:00
|
|
|
gstore.data.notif[0].data = gstore.data.notif[0].data.concat( msg.connected );
|
|
|
|
gstore.data.notif[0].count += msg.connected.length;
|
2017-12-04 16:30:33 +00:00
|
|
|
}
|
2017-12-04 10:22:10 +00:00
|
|
|
|
2017-12-05 17:55:07 +00:00
|
|
|
// {4} Reset notification count if already on page //
|
|
|
|
gstore.data.func.nav(router, null);
|
|
|
|
|
2017-12-05 17:58:27 +00:00
|
|
|
}).send({name: _SERVER.session.name}); */
|
2017-12-04 10:22:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* (2) Message channel */
|
2017-12-05 17:41:39 +00:00
|
|
|
window.wsc_chat = wsc.channel('chat').listen(function(msg, err){
|
2017-12-04 10:22:10 +00:00
|
|
|
|
|
|
|
// {1} Manage error //
|
2017-12-04 16:30:33 +00:00
|
|
|
if( msg == null && err != null )
|
2017-12-05 17:41:39 +00:00
|
|
|
return infobox.show('Erreur de connexion WebSocket@chat ('+err+')', 'error', 3000);
|
2017-12-04 10:22:10 +00:00
|
|
|
|
|
|
|
// {2} Manage wsclient error //
|
2017-12-04 16:30:33 +00:00
|
|
|
if( typeof msg.error != 'boolean' || msg.error !== false )
|
2017-12-05 17:41:39 +00:00
|
|
|
return infobox.show('Erreur de connexion WebSocket@chat', 'warning', 3000);
|
2017-12-04 10:22:10 +00:00
|
|
|
|
|
|
|
// {3} Manage notification //
|
2017-12-04 16:30:33 +00:00
|
|
|
if( msg.msg != null ){
|
|
|
|
console.log('Received '+msg.msg.length+' new message(s)');
|
2017-12-05 17:41:39 +00:00
|
|
|
gstore.data.notif[1].data = gstore.data.notif[1].data.concat( msg.msg );
|
|
|
|
gstore.data.notif[1].count += msg.msg.length
|
2017-12-04 16:30:33 +00:00
|
|
|
}
|
2017-12-04 10:22:10 +00:00
|
|
|
|
2017-12-05 17:55:07 +00:00
|
|
|
// {4} Reset notification count if already on page //
|
|
|
|
gstore.data.func.nav(router, null);
|
|
|
|
|
|
|
|
|
2017-12-05 17:41:39 +00:00
|
|
|
}).send({name: _SERVER.session.name});
|
2017-12-04 10:48:32 +00:00
|
|
|
|
|
|
|
|
2017-12-04 18:44:30 +00:00
|
|
|
|
|
|
|
/* (4) Clean sockets before page quit
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
window.onbeforeunload = function() {
|
2017-12-05 17:41:39 +00:00
|
|
|
wsc_chat.send('{"close": true}');
|
2017-12-05 17:58:27 +00:00
|
|
|
/*NO_WS_CONNECT*///wsc_connect.send('{"close": true}');
|
2017-12-04 18:44:30 +00:00
|
|
|
};
|