Skip to content

Instantly share code, notes, and snippets.

@bayareawebpro
Created September 18, 2019 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bayareawebpro/fd959943f691bf13a0c07361ff75a70d to your computer and use it in GitHub Desktop.
Save bayareawebpro/fd959943f691bf13a0c07361ff75a70d to your computer and use it in GitHub Desktop.
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