2018-03-24 16:51:04 +00:00
|
|
|
/* (1) VueJS data */
|
|
|
|
import VueRouter from 'vue-router'
|
|
|
|
import GlobalStore from './lib/gstore'
|
|
|
|
import routes from './routes'
|
|
|
|
|
|
|
|
/* (2) Custom libs */
|
|
|
|
import Authentication from './lib/authentication.js'
|
|
|
|
import XHRClientDriver from './lib/client/xhr.js'
|
|
|
|
import WebSocketClientDriver from './lib/client/ws.js'
|
2018-03-28 23:26:18 +00:00
|
|
|
import APIClient from './lib/api-client.js'
|
2018-03-24 16:51:04 +00:00
|
|
|
|
2018-04-07 14:22:02 +00:00
|
|
|
export default new Promise( (res, rej) => {
|
2018-03-28 23:26:18 +00:00
|
|
|
|
2018-04-07 14:22:02 +00:00
|
|
|
/* (1) Custom lib accessors
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Field validation */
|
|
|
|
require('./lib/field-manager.js');
|
2018-03-25 11:59:43 +00:00
|
|
|
|
2018-04-07 14:22:02 +00:00
|
|
|
/* (2) Global Store for Vue */
|
|
|
|
window.gs = new GlobalStore();
|
2018-03-25 11:59:43 +00:00
|
|
|
|
2018-04-07 14:22:02 +00:00
|
|
|
/* (3) Authentication token management */
|
|
|
|
window.auth = new Authentication();
|
|
|
|
gs.set('auth', auth);
|
2018-03-24 16:51:04 +00:00
|
|
|
|
2018-04-07 14:22:02 +00:00
|
|
|
/* (4) XHR / WebSocket drivers */
|
|
|
|
window.xhrcd = XHRClientDriver;
|
|
|
|
window.wscd = WebSocketClientDriver;
|
2018-03-27 12:10:00 +00:00
|
|
|
|
2018-04-07 14:22:02 +00:00
|
|
|
/* (5) ClientDriver instances */
|
|
|
|
window.api = new APIClient('api.douscord.xdrm.io');
|
|
|
|
window.ws = new WebSocketClientDriver('ws.douscord.xdrm.io');
|
2018-03-24 16:51:04 +00:00
|
|
|
|
2018-04-07 14:22:02 +00:00
|
|
|
/* (6) Add audio manager */
|
|
|
|
window.AudioManager = new (require('./lib/audio-manager.js').default)();
|
|
|
|
gs.set('audioManager', window.AudioManager);
|
2018-03-28 17:42:29 +00:00
|
|
|
|
|
|
|
|
2018-03-24 16:51:04 +00:00
|
|
|
|
2018-04-07 14:22:02 +00:00
|
|
|
/* (2) Global data
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Get Full URI */
|
|
|
|
gs.set('URI', document.URL.replace(/^(?:[^\/]+\/\/|[^\/]+\/)/, '').split('/').filter(function(v,i){ return !!i && v.length; }));
|
2018-03-24 16:51:04 +00:00
|
|
|
|
2018-04-07 14:22:02 +00:00
|
|
|
/* (2) Store routes */
|
|
|
|
gs.set('routes', routes);
|
2018-04-05 09:44:13 +00:00
|
|
|
|
2018-04-07 14:22:02 +00:00
|
|
|
/* (3) Store if authenticated */
|
|
|
|
gs.set('authed', auth.token !== null);
|
2018-04-05 09:44:13 +00:00
|
|
|
|
2018-04-07 14:22:02 +00:00
|
|
|
/* (4) Init. vue router */
|
|
|
|
gs.set('router', new VueRouter({
|
|
|
|
routes: gs.get.authed ? gs.get.routes['auth'] : gs.get.routes['noauth']
|
|
|
|
}));
|
2018-04-06 15:02:40 +00:00
|
|
|
|
2018-04-07 14:22:02 +00:00
|
|
|
/* (5) refresh page */
|
|
|
|
gs.set('refresh', () => ( document.location = '' ) );
|
2018-04-05 22:54:13 +00:00
|
|
|
|
2018-04-07 14:22:02 +00:00
|
|
|
/* (6) Connection status */
|
|
|
|
gs.set('connection', 1); // null -> normal, 0 -> offline, 1 -> connecting, 2 -> online
|
|
|
|
gs.set('audio_conn', null); // null -> normal, 0 -> connecting, 1 -> listening, 2 -> sharing
|
2018-04-05 22:54:13 +00:00
|
|
|
|
2018-04-07 14:22:02 +00:00
|
|
|
/* (7) Ask for permission API */
|
|
|
|
Notification.requestPermission();
|
2018-03-24 16:51:04 +00:00
|
|
|
|
2018-04-07 14:22:02 +00:00
|
|
|
/* (8) DEBUG MODE */
|
|
|
|
window.DEBUG_MOD = false;
|
2018-03-24 16:51:04 +00:00
|
|
|
|
|
|
|
|
2018-04-07 14:22:02 +00:00
|
|
|
res();
|
2018-03-24 16:51:04 +00:00
|
|
|
|
2018-04-07 14:22:02 +00:00
|
|
|
});
|