How to reconnect Pubnub after internet reconnect in javascript?

Viewed 184

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 Answers

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
});
Related