Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pusher auto reconnect when detecting errors / disconnect

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);
});
like image 390
tmartin314 Avatar asked Feb 05 '14 15:02

tmartin314


1 Answers

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.

like image 74
leggetter Avatar answered Nov 07 '22 14:11

leggetter