Question

Is there some way to reconnect to Pusher if any error or non-connected state is found?

Here's our connection code:

var pusher = new Pusher('<apikey>', {encrypted: true});
var state = pusher.connection.state;

pusher.connection.bind( 'error', function( err ) { 
  console.log(err);
});

pusher.connection.bind('state_change', function(states) {
  // states = {previous: 'oldState', current: 'newState'}
  console.log(states);
});
Was it helpful?

Solution

The Pusher JavaScript library automatically attempts reconnection. You don't need to add any code to support this.

I can't find this anywhere in the Pusher docs, but I know this for a fact as I worked for Pusher for 2 years.

You can test by going to http://test.pusher.com/ and disconnecting from the Internet and then reconnecting again. The logging will show it is auto-reconnecting.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top