Created
September 18, 2019 23:47
-
-
Save bayareawebpro/fd959943f691bf13a0c07361ff75a70d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
name: 'broadcasting', | |
data() { | |
return { | |
broadcasting: this.$broadcasting | |
} | |
}, | |
computed: { | |
...mapState('auth', { | |
currentUser: (state) => state.currentUser, | |
}), | |
}, | |
watch: { | |
currentUser:{ | |
deep: true, | |
immediate: true, | |
handler(){ | |
this.attemptConnect() | |
} | |
} | |
}, | |
methods: { | |
attemptConnect(){ | |
if(this.broadcasting){ | |
if(!this.$auth.loggedIn && this.broadcasting.isConnected){ | |
this.broadcasting.disconnect() | |
}else if(this.$auth.loggedIn && !this.broadcasting.isConnected){ | |
this.broadcasting.connect() | |
} | |
} | |
}, | |
confirm(){ | |
// this.$q.dialog({ | |
// title: 'Realtime Sync', | |
// message: 'Realtime synchronization enables notifications and live job updates.', | |
// color: 'green', | |
// ok: (this.broadcasting.isConnected ? 'Ok' : 'Enable'), | |
// preventClose: true, | |
// }).then(()=>{ | |
// if(!this.broadcasting.isConnected){ | |
// this.broadcasting.connect() | |
// } | |
// }).catch(()=>{ | |
// }) | |
}, | |
}, | |
created(){ | |
this.$events.$on('broadcasting:connect', this.broadcasting.connect) | |
this.$events.$on('broadcasting:disconnect', this.broadcasting.disconnect) | |
}, | |
beforeDestroy(){ | |
this.broadcasting.disconnect() | |
this.$events.$off('broadcasting:connect', this.broadcasting.connect) | |
this.$events.$off('broadcasting:disconnect', this.broadcasting.disconnect) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment