如何在javascript中重新连接互联网后重新连接Pubnub? [英] How to reconnect Pubnub after internet reconnect in javascript?

查看:72
本文介绍了如何在javascript中重新连接互联网后重新连接Pubnub?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Pubnub 实例,我想知道如何在互联网出现故障时重新连接并像给定的重试次数一样重新连接?该文档绝对提供了适当的 docs 但我是无法将其放入代码中.

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

推荐答案

在您的初始化代码中设置 restore:true.

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

这篇关于如何在javascript中重新连接互联网后重新连接Pubnub?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆