检测到错误/断开时,Pusher自动重新连接

tma*_*314 6 connection state reconnect pusher

如果发现任何错误或非连接状态,是否有某种方法可以重新连接到Pusher?

这是我们的连接代码:

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);
});
Run Code Online (Sandbox Code Playgroud)

leg*_*ter 8

Pusher JavaScript库会自动尝试重新连接.您无需添加任何代码来支持此功能.

我在Pusher文档的任何地方都找不到这个,但我知道这是因为我为Pusher工作了2年.

您可以通过访问http://test.pusher.com/并断开Internet连接然后重新连接来进行测试.日志记录将显示它是自动重新连接.