Skip to content

Commit 2320af1

Browse files
Mohit TejaniMohit Tejani
authored andcommitted
revert changes for unsubscribe
1 parent cec5220 commit 2320af1

6 files changed

Lines changed: 67 additions & 9 deletions

File tree

dist/web/pubnub.js

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7045,10 +7045,16 @@
70457045
return subscriptionTimetokenFromReference(this.currentTimetoken, (_a = this.referenceTimetoken) !== null && _a !== void 0 ? _a : '0');
70467046
}
70477047
get subscribedChannels() {
7048-
return Object.keys(this.channels);
7048+
const regularChannels = Object.keys(this.channels);
7049+
const presenceChannels = Object.keys(this.presenceChannels).map(channel => `${channel}-pnpres`);
7050+
// Return both regular channels and presence channels
7051+
return [...regularChannels, ...presenceChannels];
70497052
}
70507053
get subscribedChannelGroups() {
7051-
return Object.keys(this.channelGroups);
7054+
const regularChannelGroups = Object.keys(this.channelGroups);
7055+
const presenceChannelGroups = Object.keys(this.presenceChannelGroups).map(group => `${group}-pnpres`);
7056+
// Return both regular channel groups and presence channel groups
7057+
return [...regularChannelGroups, ...presenceChannelGroups];
70527058
}
70537059
get abort() {
70547060
return this._subscribeAbort;
@@ -7119,6 +7125,10 @@
71197125
actualChannels.add(channel);
71207126
if (channel in this.heartbeatChannels)
71217127
delete this.heartbeatChannels[channel];
7128+
// Auto-remove corresponding presence channel when unsubscribing from regular channel
7129+
if (channel in this.presenceChannels) {
7130+
delete this.presenceChannels[channel];
7131+
}
71227132
}
71237133
if (channel in this.presenceState)
71247134
delete this.presenceState[channel];
@@ -7133,6 +7143,10 @@
71337143
actualChannelGroups.add(group);
71347144
if (group in this.heartbeatChannelGroups)
71357145
delete this.heartbeatChannelGroups[group];
7146+
// Auto-remove corresponding presence channel group when unsubscribing from regular channel group
7147+
if (group in this.presenceChannelGroups) {
7148+
delete this.presenceChannelGroups[group];
7149+
}
71367150
}
71377151
if (group in this.presenceState)
71387152
delete this.presenceState[group];
@@ -16102,6 +16116,13 @@
1610216116
message: Object.assign({}, parameters),
1610316117
details: 'Subscribe with parameters:',
1610416118
}));
16119+
// For legacy subscribe/unsubscribe API, go directly to the subscription manager
16120+
// to handle individual channel management properly
16121+
if (this.subscriptionManager) {
16122+
this.subscriptionManager.subscribe(parameters);
16123+
return;
16124+
}
16125+
// Fallback to global subscription set logic for event engine or other modes
1610516126
// The addition of a new subscription set into the subscribed global subscription set will update the active
1610616127
// subscription loop with new channels and groups.
1610716128
const subscriptionSet = this.subscriptionSet(Object.assign(Object.assign({}, parameters), { subscriptionOptions: { receivePresenceEvents: parameters.withPresence } }));
@@ -16156,6 +16177,13 @@
1615616177
message: Object.assign({}, parameters),
1615716178
details: 'Unsubscribe with parameters:',
1615816179
}));
16180+
// For legacy subscribe/unsubscribe API, bypass the global subscription set
16181+
// and go directly to the subscription manager to handle individual channel removal
16182+
if (this.subscriptionManager) {
16183+
this.subscriptionManager.unsubscribe(parameters);
16184+
return;
16185+
}
16186+
// Fallback to global subscription set logic for event engine or other modes
1615916187
if (!this._globalSubscriptionSet) {
1616016188
this.logger.debug('PubNub', 'There are no active subscriptions. Ignore.');
1616116189
return;
@@ -16165,12 +16193,14 @@
1616516193
const subscriptionInput = subscription.subscriptionInput(false);
1616616194
if (subscriptionInput.isEmpty)
1616716195
return false;
16196+
// For non-legacy API, we need to check if ANY of the channels/groups match
1616816197
for (const channel of (_a = parameters.channels) !== null && _a !== void 0 ? _a : [])
1616916198
if (subscriptionInput.contains(channel))
1617016199
return true;
1617116200
for (const group of (_b = parameters.channelGroups) !== null && _b !== void 0 ? _b : [])
1617216201
if (subscriptionInput.contains(group))
1617316202
return true;
16203+
return false;
1617416204
});
1617516205
// Removal from the active subscription also will cause `unsubscribe`.
1617616206
if (subscriptions.length > 0)
@@ -18093,9 +18123,7 @@
1809318123
userId: clientConfiguration.getUserId(),
1809418124
workerUrl: configurationCopy.subscriptionWorkerUrl,
1809518125
sdkVersion: clientConfiguration.getVersion(),
18096-
// TODO: USE NEXT LINE INSTEAD
18097-
// heartbeatInterval: clientConfiguration.getHeartbeatInterval(),
18098-
heartbeatInterval: 10,
18126+
heartbeatInterval: clientConfiguration.getHeartbeatInterval(),
1809918127
announceSuccessfulHeartbeats: clientConfiguration.announceSuccessfulHeartbeats,
1810018128
announceFailedHeartbeats: clientConfiguration.announceFailedHeartbeats,
1810118129
workerOfflineClientsCheckInterval: platformConfiguration.subscriptionWorkerOfflineClientsCheckInterval,

dist/web/pubnub.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/web/pubnub.worker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,8 @@
435435
hbRequests.response = response;
436436
// Notify each PubNub client which awaited for response.
437437
notifyRequestProcessingResult(clients, fetchRequest, response, event.request);
438-
if (response[0].status >= 400)
438+
// Stop heartbeat timer on client error status codes.
439+
if (response[0].status >= 400 && response[0].status < 500)
439440
stopHeartbeatTimer(client);
440441
}, (clients, fetchRequest, error) => {
441442
// Notify each PubNub client which awaited for response.

dist/web/pubnub.worker.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/components/subscription-manager.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,11 @@ export class SubscriptionManager {
272272
actualChannels.add(channel);
273273

274274
if (channel in this.heartbeatChannels) delete this.heartbeatChannels[channel];
275+
276+
// Auto-remove corresponding presence channel when unsubscribing from regular channel
277+
if (channel in this.presenceChannels) {
278+
delete this.presenceChannels[channel];
279+
}
275280
}
276281

277282
if (channel in this.presenceState) delete this.presenceState[channel];
@@ -287,6 +292,11 @@ export class SubscriptionManager {
287292
actualChannelGroups.add(group);
288293

289294
if (group in this.heartbeatChannelGroups) delete this.heartbeatChannelGroups[group];
295+
296+
// Auto-remove corresponding presence channel group when unsubscribing from regular channel group
297+
if (group in this.presenceChannelGroups) {
298+
delete this.presenceChannelGroups[group];
299+
}
290300
}
291301

292302
if (group in this.presenceState) delete this.presenceState[group];

src/core/pubnub-common.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,14 @@ export class PubNubCore<
16241624
details: 'Subscribe with parameters:',
16251625
}));
16261626

1627+
// For legacy subscribe/unsubscribe API, go directly to the subscription manager
1628+
// to handle individual channel management properly
1629+
if (this.subscriptionManager) {
1630+
this.subscriptionManager.subscribe(parameters);
1631+
return;
1632+
}
1633+
1634+
// Fallback to global subscription set logic for event engine or other modes
16271635
// The addition of a new subscription set into the subscribed global subscription set will update the active
16281636
// subscription loop with new channels and groups.
16291637
const subscriptionSet = this.subscriptionSet({
@@ -1696,6 +1704,14 @@ export class PubNubCore<
16961704
details: 'Unsubscribe with parameters:',
16971705
}));
16981706

1707+
// For legacy subscribe/unsubscribe API, bypass the global subscription set
1708+
// and go directly to the subscription manager to handle individual channel removal
1709+
if (this.subscriptionManager) {
1710+
this.subscriptionManager.unsubscribe(parameters);
1711+
return;
1712+
}
1713+
1714+
// Fallback to global subscription set logic for event engine or other modes
16991715
if (!this._globalSubscriptionSet) {
17001716
this.logger.debug('PubNub', 'There are no active subscriptions. Ignore.');
17011717
return;
@@ -1705,8 +1721,11 @@ export class PubNubCore<
17051721
const subscriptionInput = subscription.subscriptionInput(false);
17061722
if (subscriptionInput.isEmpty) return false;
17071723

1724+
// For non-legacy API, we need to check if ANY of the channels/groups match
17081725
for (const channel of parameters.channels ?? []) if (subscriptionInput.contains(channel)) return true;
17091726
for (const group of parameters.channelGroups ?? []) if (subscriptionInput.contains(group)) return true;
1727+
1728+
return false;
17101729
});
17111730

17121731
// Removal from the active subscription also will cause `unsubscribe`.

0 commit comments

Comments
 (0)