0

I want to check the connection state of Pusherjs from $echo in NuxtJs page.

when I use:

mounted(){
   this.connection = this.$echo.connector.pusher.connection.state;
}

It works but it only set the initial connection status which is connecting and it's static.

But when I use:

computed:{
   connection: this.$echo.connector.pusher.connection.state
}

It returns error:

TypeError
Cannot read property '$echo' of undefined

So how can I be notified about connection status real time?

Fred II
  • 581
  • 2
  • 11
  • 23

1 Answers1

0

I found the solution:

this.$echo.connector.pusher.connection.bind("state_change", (states) => {
   // states = {previous: 'oldState', current: 'newState'}
});

Reference: https://pusher.com/docs/channels/using_channels/connection#binding-to-all-state-changes

Fred II
  • 581
  • 2
  • 11
  • 23