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;
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];
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];
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 } }));
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)
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,
0 commit comments