discord-client/webpack/setup.js

73 lines
1.8 KiB
JavaScript
Raw Permalink Normal View History

/* (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'
import APIClient from './lib/api-client.js'
/* (1) Custom lib accessors
---------------------------------------------------------*/
/* (1) Field validation */
require('./lib/field-manager.js');
/* (2) Global Store for Vue */
window.gs = new GlobalStore();
2018-03-25 11:59:43 +00:00
/* (3) Authentication token management */
2018-03-25 11:59:43 +00:00
window.auth = new Authentication();
gs.set('auth', auth);
2018-03-25 11:59:43 +00:00
/* (4) XHR / WebSocket drivers */
window.xhrcd = XHRClientDriver;
window.wscd = WebSocketClientDriver;
/* (5) ClientDriver instances */
2018-03-27 12:52:14 +00:00
window.api = new APIClient('api.douscord.xdrm.io');
window.ws = new WebSocketClientDriver('ws.douscord.xdrm.io');
/* (2) Global data
---------------------------------------------------------*/
/* (1) Get Full URI */
gs.set('URI', document.URL.replace(/^(?:[^\/]+\/\/|[^\/]+\/)/, '').split('/').filter(function(v,i){ return !!i && v.length; }));
/* (2) Store routes */
gs.set('routes', routes);
/* (3) Store if authenticated */
gs.set('authed', auth.token !== null);
/* (4) Init. vue router */
gs.set('router', new VueRouter({
routes: gs.get.authed ? gs.get.routes['auth'] : gs.get.routes['noauth']
}));
/* (5) refresh page */
gs.set('refresh', () => ( document.location = '' ) );
/* (6) Connection status */
gs.set('connection', 1); // null -> normal, 0 -> offline, 1 -> connecting, 2 -> online
/* (7) Ask for permission API */
Notification.requestPermission();
/* (8) DEBUG MODE */
window.DEBUG_MOD = false;
2018-04-05 22:54:13 +00:00
// audio management
window.AudioManager = new (require('./lib/audio-manager.js').default)();