[setup] is now an asynchronous Promise()
This commit is contained in:
parent
1baf2b5e06
commit
139184a981
|
@ -5,44 +5,46 @@ import noauth_wrapper from './vue/noauth/wrapper.vue'
|
|||
|
||||
|
||||
/* (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 */
|
||||
gs.get.router.beforeEach((to, from, next) => {
|
||||
/* (2) Set router hooks to load page data before loading content */
|
||||
gs.get.router.beforeEach((to, from, next) => {
|
||||
|
||||
// {1} Ignore null name //
|
||||
if( to.name == null )
|
||||
return next();
|
||||
// {1} Ignore null name //
|
||||
if( to.name == null )
|
||||
return next();
|
||||
|
||||
// {2} Get appropriate page location //
|
||||
let auth_folder = (gs.get.authed) ? 'auth' : 'noauth';
|
||||
let page_file = to.name || gs.get.routes[auth_folder][0].name;
|
||||
let fullpath = `${auth_folder}/${page_file}`;
|
||||
// {2} Get appropriate page location //
|
||||
let auth_folder = (gs.get.authed) ? 'auth' : 'noauth';
|
||||
let page_file = to.name || gs.get.routes[auth_folder][0].name;
|
||||
let fullpath = `${auth_folder}/${page_file}`;
|
||||
|
||||
// {3} Load page script //
|
||||
if( fullpath === 'noauth/login')
|
||||
return require('./page/noauth/login.js').default.then(next);
|
||||
// {3} Load page script //
|
||||
if( fullpath === 'noauth/login')
|
||||
return require('./page/noauth/login.js').default.then(next);
|
||||
|
||||
if( fullpath === 'noauth/register')
|
||||
return require('./page/noauth/register.js').default.then(next);
|
||||
if( fullpath === 'noauth/register')
|
||||
return require('./page/noauth/register.js').default.then(next);
|
||||
|
||||
if( fullpath === 'auth/channel')
|
||||
return require('./page/auth/channel.js').default.then(next);
|
||||
if( fullpath === 'auth/channel')
|
||||
return require('./page/auth/channel.js').default.then(next);
|
||||
|
||||
// {4} Let VueRouter do the magic //
|
||||
// next();
|
||||
// {4} Let VueRouter do the magic //
|
||||
// next();
|
||||
|
||||
});
|
||||
|
||||
|
||||
/* (3) Select appropriate wrapper */
|
||||
const wrapper = (gs.get.authed) ? auth_wrapper : noauth_wrapper;
|
||||
|
||||
|
||||
/* (4) Render view */
|
||||
Vue.use(VueRouter);
|
||||
new Vue({
|
||||
el: '#vue',
|
||||
router: gs.get.router,
|
||||
render(h){ return h(wrapper); }
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
/* (3) Select appropriate wrapper */
|
||||
const wrapper = (gs.get.authed) ? auth_wrapper : noauth_wrapper;
|
||||
|
||||
|
||||
/* (4) Render view */
|
||||
Vue.use(VueRouter);
|
||||
new Vue({
|
||||
el: '#vue',
|
||||
router: gs.get.router,
|
||||
render(h){ return h(wrapper); }
|
||||
})
|
||||
|
|
|
@ -9,66 +9,64 @@ 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');
|
||||
export default new Promise( (res, rej) => {
|
||||
|
||||
/* (2) Global Store for Vue */
|
||||
window.gs = new GlobalStore();
|
||||
/* (1) Custom lib accessors
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Field validation */
|
||||
require('./lib/field-manager.js');
|
||||
|
||||
/* (3) Authentication token management */
|
||||
window.auth = new Authentication();
|
||||
gs.set('auth', auth);
|
||||
/* (2) Global Store for Vue */
|
||||
window.gs = new GlobalStore();
|
||||
|
||||
/* (4) XHR / WebSocket drivers */
|
||||
window.xhrcd = XHRClientDriver;
|
||||
window.wscd = WebSocketClientDriver;
|
||||
/* (3) Authentication token management */
|
||||
window.auth = new Authentication();
|
||||
gs.set('auth', auth);
|
||||
|
||||
/* (5) ClientDriver instances */
|
||||
window.api = new APIClient('api.douscord.xdrm.io');
|
||||
window.ws = new WebSocketClientDriver('ws.douscord.xdrm.io');
|
||||
/* (4) XHR / WebSocket drivers */
|
||||
window.xhrcd = XHRClientDriver;
|
||||
window.wscd = WebSocketClientDriver;
|
||||
|
||||
/* (6) Add audio manager */
|
||||
window.AudioManager = new (require('./lib/audio-manager.js').default)();
|
||||
gs.set('audioManager', window.AudioManager);
|
||||
/* (5) ClientDriver instances */
|
||||
window.api = new APIClient('api.douscord.xdrm.io');
|
||||
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
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Get Full URI */
|
||||
gs.set('URI', document.URL.replace(/^(?:[^\/]+\/\/|[^\/]+\/)/, '').split('/').filter(function(v,i){ return !!i && v.length; }));
|
||||
/* (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
|
||||
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;
|
||||
/* (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
|
||||
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();
|
||||
|
||||
});
|
Loading…
Reference in New Issue