main/view/main.js

64 lines
1.7 KiB
JavaScript
Executable File

/* (1) Imports
---------------------------------------------------------*/
/* (1) NPM libs */
import Vue from 'vue'
import VueRouter from 'vue-router'
/* (2) Internal libs */
import {API} from './lib/api-es6'
import {InfoBox} from './lib/infobox-es6'
import {WSClient,WSClientBuilder} from './lib/ws-client-es6'
import routes from './routes'
/* (3) Vues */
import wrapper_vue from './vue/wrapper.vue'
/* (2) Initialisation
---------------------------------------------------------*/
/* (1) global store init */
require('./vue-config');
window.gstore.add('server', window._SERVER);
window.infobox = new InfoBox(gstore.data.info);
/* (2) API */
window.api = new API(gstore.data.is_local ? 'http://ndli1718/api/v/1.0/' : 'https://ndli1718.xdrm.io/api/v/1.0/');
/* (3) wsclient */
window.wsc = new WSClientBuilder(gstore.data.is_local ? 'ws://localhost:9999' : 'wss://websocket.xdrm.io');
/* (4) Init vue router */
Vue.use(VueRouter);
const router = new VueRouter({
mode: 'history',
routes: routes[0]
});
/* (5) Render view */
new Vue({
el: '#main-vue',
router,
render: h => h(wrapper_vue)
});
/* (6) Navigate at page load (to update notifications count) */
gstore.data.func.nav(router, null);
/* (3) Set WebSocket channels
---------------------------------------------------------*/
/* (1) Make router globally available */
window._router_ = router;
/* (2) Create/Manage web socket clients */
require('./websocket');
/* (3) Remove global ref to router */
delete window._router_;
/* (4) Get geolocation
---------------------------------------------------------*/
navigator.geolocation && navigator.geolocation.getCurrentPosition(function(a, b){ console.log(this, a, b); }, null);