Skip to content

Commit 3ab96d7

Browse files
embbnuxkirill-konshin
authored andcommitted
restore pubnub when network is back online (#86)
* restore pubnub when network is back online * fix typo
1 parent 8e235ba commit 3ab96d7

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

demo/core.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ <h1>
100100
subscription.on(subscription.events.notification, function(msg) {
101101
cb(msg.body);
102102
});
103+
subscription.on(subscription.events.renewError, function() {
104+
subscription.reset();
105+
subscription = null;
106+
getPresenceSubscription(event, cb);
107+
});
108+
subscription.on(subscription.events.subscribeError, function() {
109+
subscription.reset();
110+
subscription = null;
111+
getPresenceSubscription(event, cb);
112+
});
103113

104114
subscription
105115
.restore([event])

src/subscription/Subscription.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ Subscription.prototype.subscribe = function() {
212212
}.bind(this)).catch(function(e) {
213213

214214
e = this._platform.client().makeError(e);
215-
215+
// `reset` will remove pubnub instance.
216+
// so if network is broken for a long time, pubnub will be removed. And client can not receive notification anymore.
216217
this.reset()
217218
.emit(this.events.subscribeError, e);
218219

@@ -251,7 +252,8 @@ Subscription.prototype.renew = function() {
251252
}.bind(this)).catch(function(e) {
252253

253254
e = this._platform.client().makeError(e);
254-
255+
// `reset` will remove pubnub instance.
256+
// so if network is broken for a long time, pubnub will be removed. And client can not receive notification anymore.
255257
this.reset()
256258
.emit(this.events.renewError, e);
257259

@@ -450,6 +452,7 @@ Subscription.prototype._subscribeAtPubnub = function() {
450452

451453
this._pubnub = new PubNub({
452454
ssl: true,
455+
restore: true,
453456
subscribeKey: deliveryMode.subscriberKey
454457
});
455458

0 commit comments

Comments
 (0)