[setup] is now an asynchronous Promise()

This commit is contained in:
xdrm-brackets 2018-04-07 16:22:02 +02:00
parent 1baf2b5e06
commit 139184a981
2 changed files with 77 additions and 77 deletions

View File

@ -5,10 +5,10 @@ import noauth_wrapper from './vue/noauth/wrapper.vue'
/* (1) Setup: Vue, VueRouter, Authentication, ClientDriver-s */ /* (1) Setup: Vue, VueRouter, Authentication, ClientDriver-s */
require('./setup.js'); require('./setup.js').default.then(() => {
/* (2) Set router hooks to load page data before loading content */ /* (2) Set router hooks to load page data before loading content */
gs.get.router.beforeEach((to, from, next) => { gs.get.router.beforeEach((to, from, next) => {
// {1} Ignore null name // // {1} Ignore null name //
if( to.name == null ) if( to.name == null )
@ -32,17 +32,19 @@ gs.get.router.beforeEach((to, from, next) => {
// {4} Let VueRouter do the magic // // {4} Let VueRouter do the magic //
// next(); // next();
}); });
/* (3) Select appropriate wrapper */ /* (3) Select appropriate wrapper */
const wrapper = (gs.get.authed) ? auth_wrapper : noauth_wrapper; const wrapper = (gs.get.authed) ? auth_wrapper : noauth_wrapper;
/* (4) Render view */ /* (4) Render view */
Vue.use(VueRouter); Vue.use(VueRouter);
new Vue({ new Vue({
el: '#vue', el: '#vue',
router: gs.get.router, router: gs.get.router,
render(h){ return h(wrapper); } render(h){ return h(wrapper); }
}) });
});

View File

@ -9,66 +9,64 @@ import XHRClientDriver from './lib/client/xhr.js'
import WebSocketClientDriver from './lib/client/ws.js' import WebSocketClientDriver from './lib/client/ws.js'
import APIClient from './lib/api-client.js' import APIClient from './lib/api-client.js'
/* (1) Custom lib accessors export default new Promise( (res, rej) => {
---------------------------------------------------------*/
/* (1) Field validation */
require('./lib/field-manager.js');
/* (2) Global Store for Vue */ /* (1) Custom lib accessors
window.gs = new GlobalStore(); ---------------------------------------------------------*/
/* (1) Field validation */
require('./lib/field-manager.js');
/* (3) Authentication token management */ /* (2) Global Store for Vue */
window.auth = new Authentication(); window.gs = new GlobalStore();
gs.set('auth', auth);
/* (4) XHR / WebSocket drivers */ /* (3) Authentication token management */
window.xhrcd = XHRClientDriver; window.auth = new Authentication();
window.wscd = WebSocketClientDriver; gs.set('auth', auth);
/* (5) ClientDriver instances */ /* (4) XHR / WebSocket drivers */
window.api = new APIClient('api.douscord.xdrm.io'); window.xhrcd = XHRClientDriver;
window.ws = new WebSocketClientDriver('ws.douscord.xdrm.io'); window.wscd = WebSocketClientDriver;
/* (6) Add audio manager */ /* (5) ClientDriver instances */
window.AudioManager = new (require('./lib/audio-manager.js').default)(); window.api = new APIClient('api.douscord.xdrm.io');
gs.set('audioManager', window.AudioManager); window.ws = new WebSocketClientDriver('ws.douscord.xdrm.io');
/* (6) Add audio manager */
window.AudioManager = new (require('./lib/audio-manager.js').default)();
gs.set('audioManager', window.AudioManager);
/* (2) Global data /* (2) Global data
---------------------------------------------------------*/ ---------------------------------------------------------*/
/* (1) Get Full URI */ /* (1) Get Full URI */
gs.set('URI', document.URL.replace(/^(?:[^\/]+\/\/|[^\/]+\/)/, '').split('/').filter(function(v,i){ return !!i && v.length; })); gs.set('URI', document.URL.replace(/^(?:[^\/]+\/\/|[^\/]+\/)/, '').split('/').filter(function(v,i){ return !!i && v.length; }));
/* (2) Store routes */ /* (2) Store routes */
gs.set('routes', routes); gs.set('routes', routes);
/* (3) Store if authenticated */ /* (3) Store if authenticated */
gs.set('authed', auth.token !== null); gs.set('authed', auth.token !== null);
/* (4) Init. vue router */ /* (4) Init. vue router */
gs.set('router', new VueRouter({ gs.set('router', new VueRouter({
routes: gs.get.authed ? gs.get.routes['auth'] : gs.get.routes['noauth'] 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
gs.set('audio_conn', null); // null -> normal, 0 -> connecting, 1 -> listening, 2 -> sharing
/* (7) Ask for permission API */
Notification.requestPermission();
/* (8) DEBUG MODE */
window.DEBUG_MOD = false;
/* (5) refresh page */
gs.set('refresh', () => ( document.location = '' ) );
/* (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
/* (7) Ask for permission API */
Notification.requestPermission();
/* (8) DEBUG MODE */
window.DEBUG_MOD = false;
res();
});