How to reconnect Pubnub after internet reconnect in javascript?

末鹿安然 提交于 2020-04-14 05:47:07

问题


I have a Pubnub instance, I want to know how to handle reconnection when internet does down and comes back up with like a given number of retries? The documentation definitely gives the appropriate docs but I am unable to put it into code.

Help would be greatly appreciated. my code:

this.pubnub = new PubNub({
  subscribeKey: this.serverDetails.authInfo.subscribeKey,
  authKey: this.serverDetails.authInfo.authKey,
  uuid,
  restore: true,
  ssl: true
});

this.listeners = {
  message: msgEvent => {
    console.log(msgEvent);
  },
  status: statusEvent => {

  }
};

this.pubnub.addListener(this.listeners);

回答1:


Set restore:true in your init code.

this.pubnub = new PubNub({
  subscribeKey: this.serverDetails.authInfo.subscribeKey,
  authKey: this.serverDetails.authInfo.authKey,
  uuid,
  ssl: true,
  restore: true // this allows reconnect to restore your channel subscription
});


来源:https://stackoverflow.com/questions/61061509/how-to-reconnect-pubnub-after-internet-reconnect-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!