Make socket.init() async

This commit is contained in:
Phan An 2017-08-26 22:42:14 +01:00
parent 9c39ef9e80
commit 75b0200633
2 changed files with 24 additions and 17 deletions

View file

@ -77,7 +77,7 @@ export default {
methods: {
async init () {
showOverlay()
socket.init()
await socket.init()
// Make the most important HTTP request to get all necessary data from the server.
// Afterwards, init all mandatory stores and services.

View file

@ -7,24 +7,31 @@ export const socket = {
pusher: null,
channel: null,
init () {
if (!process.env.PUSHER_APP_KEY) {
return
}
async init () {
return new Promise((resolve, reject) => {
if (!process.env.PUSHER_APP_KEY) {
return resolve()
}
this.pusher = new Pusher(process.env.PUSHER_APP_KEY, {
authEndpoint: '/api/broadcasting/auth',
auth: {
headers: {
Authorization: `Bearer ${ls.get('jwt-token')}`
}
},
cluster: process.env.PUSHER_APP_CLUSTER,
encrypted: true
this.pusher = new Pusher(process.env.PUSHER_APP_KEY, {
authEndpoint: '/api/broadcasting/auth',
auth: {
headers: {
Authorization: `Bearer ${ls.get('jwt-token')}`
}
},
cluster: process.env.PUSHER_APP_CLUSTER,
encrypted: true
})
this.channel = this.pusher.subscribe('private-koel')
this.channel.bind('pusher:subscription_succeeded', () => {
return resolve()
})
this.channel.bind('pusher:subscription_error', () => {
return resolve()
})
})
this.channel = this.pusher.subscribe('private-koel')
return this
},
/**