-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboost.js
73 lines (56 loc) · 1.56 KB
/
boost.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const Vue = require('vue');
const Router = require('vue-router');
const io = require('socket.io-client');
const hash = require('object-hash');
const path = require('path');
const Stream = require('./store/client-stream');
// const resource = require('vue-resource');
Vue.use(Router);
class Boost {
constructor() {
this.vue = Vue;
this.socket = io.connect('/application', {transports: ['websocket']});
this.registerListeners();
}
start(routes) {
let router = new Router({
mode: 'history',
history: true,
routes,
});
new Vue({
router,
}).$mount('#app');
this.router.beforeEach(function(transition) {
window.scrollTo(0, 0);
// if (!transition.to.matched) {
// transition.redirect('/404');
// }
transition.next();
});
}
subscribe(path) {
let ret = {};
ret.data = null;
let stream = new Stream(path).start(ret);
return ret;
}
registerListeners() {
console.log('listening');
// Any WebSocket listeners here...
this.socket.on('connect', socket => {
console.log('app:ready!');
});
}
login() {
}
logout() {
let token = localStorage.token;
console.log('auth:logging-out');
this.socket.emit('auth.logout', token, () => {
console.log('auth:logged-out');
localStorage.removeItem('token');
});
}
}
module.exports = new Boost();