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-11-29 11:29:27 +00:00
|
|
|
|
|
|
|
/* (2) Internal libs */
|
2017-11-28 16:18:56 +00:00
|
|
|
import {API} from './lib/api-es6'
|
2017-11-29 19:36:30 +00:00
|
|
|
import {WSClient,WSClientBuilder} from './lib/ws-client-es6'
|
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);
|
|
|
|
|
|
|
|
/* (4) Render view */
|
2017-11-28 12:37:49 +00:00
|
|
|
new Vue({
|
2017-11-30 15:46:30 +00:00
|
|
|
el: '#main-vue',
|
2017-12-01 14:48:13 +00:00
|
|
|
render: h => h(wrapper_vue),
|
|
|
|
data: {
|
|
|
|
gstore: window.gstore.data
|
2017-11-30 15:46:30 +00:00
|
|
|
}
|
2017-11-28 12:37:49 +00:00
|
|
|
})
|
2017-12-04 10:22:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* (3) Set WebSocket channels
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Connection channel */
|
|
|
|
window.wsc_connect = window.wsc.channel('connect').listen(function(msg, err){
|
|
|
|
|
|
|
|
// {1} Manage error //
|
|
|
|
if( msg == null && err != null ){
|
|
|
|
console.warn(err);
|
|
|
|
/*TEMP*///return;
|
|
|
|
/*TEMP*/msg = {error: 0, connected: ['guest123', 'guest456', 'guest789']};
|
|
|
|
}
|
|
|
|
|
|
|
|
// {2} Manage wsclient error //
|
|
|
|
if( msg.connected == null || msg.error == null || msg.error !== 0 ){
|
|
|
|
console.warn('websocket error: '+msg.error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// {3} Manage notification //
|
|
|
|
window.gstore.data.notif[0].data = window.gstore.data.notif[0].data.concat( msg.connected );
|
|
|
|
|
|
|
|
}).send({name: window._SERVER.session.name});
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) Message channel */
|
|
|
|
window.wsc_chat = window.wsc.channel('chat').listen(function(msg, err){
|
|
|
|
|
|
|
|
// {1} Manage error //
|
|
|
|
if( msg == null && err != null ){
|
|
|
|
console.warn(err);
|
|
|
|
/*TEMP*///return;
|
|
|
|
/*TEMP*/msg = {error: 0, msg: [['guest123', 'message 1'], ['guest456', 'message 2'], ['guest789', 'message 3']]};
|
|
|
|
}
|
|
|
|
|
|
|
|
// {2} Manage wsclient error //
|
|
|
|
if( msg.msg == null || msg.error == null || msg.error !== 0 ){
|
|
|
|
console.warn('websocket error: '+msg.error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// {3} Manage notification //
|
|
|
|
window.gstore.data.notif[1].data = window.gstore.data.notif[1].data.concat( msg.msg );
|
|
|
|
|
2017-12-04 10:48:32 +00:00
|
|
|
}).send({name: window._SERVER.session.name});
|
|
|
|
|
|
|
|
|