Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
---
changelog:
- date: 2025-12-04
version: v10.2.4
changes:
- type: improvement
text: "Prevent resubscribe to previously subscribed entities."
- date: 2025-11-20
version: v10.2.3
changes:
Expand Down Expand Up @@ -1369,7 +1374,7 @@ supported-platforms:
- 'Ubuntu 14.04 and up'
- 'Windows 7 and up'
version: 'Pubnub Javascript for Node'
version: '10.2.3'
version: '10.2.4'
sdks:
- full-name: PubNub Javascript SDK
short-name: Javascript
Expand All @@ -1385,7 +1390,7 @@ sdks:
- distribution-type: source
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/archive/refs/tags/v10.2.3.zip
location: https://github.com/pubnub/javascript/archive/refs/tags/v10.2.4.zip
requires:
- name: 'agentkeepalive'
min-version: '3.5.2'
Expand Down Expand Up @@ -2056,7 +2061,7 @@ sdks:
- distribution-type: library
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/releases/download/v10.2.3/pubnub.10.2.3.js
location: https://github.com/pubnub/javascript/releases/download/v10.2.4/pubnub.10.2.4.js
requires:
- name: 'agentkeepalive'
min-version: '3.5.2'
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v10.2.4
December 04 2025

#### Modified
- Prevent resubscribe to previously subscribed entities.

## v10.2.3
November 20 2025

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2
npm install pubnub
```
* or download one of our builds from our CDN:
* https://cdn.pubnub.com/sdk/javascript/pubnub.10.2.3.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.10.2.3.min.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.10.2.4.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.10.2.4.min.js

2. Configure your keys:

Expand Down
31 changes: 29 additions & 2 deletions dist/web/pubnub.js
Original file line number Diff line number Diff line change
Expand Up @@ -5436,7 +5436,7 @@
return base.PubNubFile;
},
get version() {
return '10.2.3';
return '10.2.4';
},
getVersion() {
return this.version;
Expand Down Expand Up @@ -9566,6 +9566,11 @@
return subscriptionTimetokenFromReference(currentTimetoken, referenceTimetoken !== null && referenceTimetoken !== void 0 ? referenceTimetoken : '0');
}
subscribe({ channels, channelGroups, timetoken, withPresence, }) {
var _a;
// check if the channels and groups are already subscribed
const hasNewChannels = channels === null || channels === void 0 ? void 0 : channels.some((channel) => !this.channels.includes(channel));
const hasNewGroups = channelGroups === null || channelGroups === void 0 ? void 0 : channelGroups.some((group) => !this.groups.includes(group));
const hasNewSubscriptions = hasNewChannels || hasNewGroups;
this.channels = [...this.channels, ...(channels !== null && channels !== void 0 ? channels : [])];
this.groups = [...this.groups, ...(channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])];
if (withPresence) {
Expand All @@ -9576,7 +9581,29 @@
this.engine.transition(restore(Array.from(new Set([...this.channels, ...(channels !== null && channels !== void 0 ? channels : [])])), Array.from(new Set([...this.groups, ...(channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])])), timetoken));
}
else {
this.engine.transition(subscriptionChange(Array.from(new Set([...this.channels, ...(channels !== null && channels !== void 0 ? channels : [])])), Array.from(new Set([...this.groups, ...(channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])]))));
if (hasNewSubscriptions) {
this.engine.transition(subscriptionChange(Array.from(new Set([...this.channels, ...(channels !== null && channels !== void 0 ? channels : [])])), Array.from(new Set([...this.groups, ...(channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])]))));
}
else {
this.dependencies.config
.logger()
.debug('EventEngine', 'Skipping state transition - all channels/groups already subscribed. Emitting SubscriptionChanged event.');
// Get current timetoken from state context
const currentState = this.engine.currentState;
const currentContext = this.engine.currentContext;
let currentTimetoken = '0';
if ((currentState === null || currentState === void 0 ? void 0 : currentState.label) === ReceivingState.label && currentContext) {
const receivingContext = currentContext;
currentTimetoken = (_a = receivingContext.cursor) === null || _a === void 0 ? void 0 : _a.timetoken;
}
// Manually emit SubscriptionChanged status event
this.dependencies.emitStatus({
category: StatusCategory$1.PNSubscriptionChangedCategory,
affectedChannels: Array.from(new Set(this.channels)),
affectedChannelGroups: Array.from(new Set(this.groups)),
currentTimetoken,
});
}
}
if (this.dependencies.join) {
this.dependencies.join({
Expand Down
4 changes: 2 additions & 2 deletions dist/web/pubnub.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/core/components/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const makeConfiguration = (base, setupCryptoModule) => {
return base.PubNubFile;
},
get version() {
return '10.2.3';
return '10.2.4';
},
getVersion() {
return this.version;
Expand Down
33 changes: 32 additions & 1 deletion lib/event-engine/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ var __importStar = (this && this.__importStar) || (function () {
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.EventEngine = void 0;
const receiving_1 = require("./states/receiving");
const dispatcher_1 = require("./dispatcher");
const utils_1 = require("../core/utils");
const unsubscribed_1 = require("./states/unsubscribed");
const core_1 = require("./core");
const categories_1 = __importDefault(require("../core/constants/categories"));
const utils = __importStar(require("../core/utils"));
const events = __importStar(require("./events"));
/**
Expand Down Expand Up @@ -88,6 +92,11 @@ class EventEngine {
return (0, utils_1.subscriptionTimetokenFromReference)(currentTimetoken, referenceTimetoken !== null && referenceTimetoken !== void 0 ? referenceTimetoken : '0');
}
subscribe({ channels, channelGroups, timetoken, withPresence, }) {
var _a;
// check if the channels and groups are already subscribed
const hasNewChannels = channels === null || channels === void 0 ? void 0 : channels.some((channel) => !this.channels.includes(channel));
const hasNewGroups = channelGroups === null || channelGroups === void 0 ? void 0 : channelGroups.some((group) => !this.groups.includes(group));
const hasNewSubscriptions = hasNewChannels || hasNewGroups;
this.channels = [...this.channels, ...(channels !== null && channels !== void 0 ? channels : [])];
this.groups = [...this.groups, ...(channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])];
if (withPresence) {
Expand All @@ -98,7 +107,29 @@ class EventEngine {
this.engine.transition(events.restore(Array.from(new Set([...this.channels, ...(channels !== null && channels !== void 0 ? channels : [])])), Array.from(new Set([...this.groups, ...(channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])])), timetoken));
}
else {
this.engine.transition(events.subscriptionChange(Array.from(new Set([...this.channels, ...(channels !== null && channels !== void 0 ? channels : [])])), Array.from(new Set([...this.groups, ...(channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])]))));
if (hasNewSubscriptions) {
this.engine.transition(events.subscriptionChange(Array.from(new Set([...this.channels, ...(channels !== null && channels !== void 0 ? channels : [])])), Array.from(new Set([...this.groups, ...(channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])]))));
}
else {
this.dependencies.config
.logger()
.debug('EventEngine', 'Skipping state transition - all channels/groups already subscribed. Emitting SubscriptionChanged event.');
// Get current timetoken from state context
const currentState = this.engine.currentState;
const currentContext = this.engine.currentContext;
let currentTimetoken = '0';
if ((currentState === null || currentState === void 0 ? void 0 : currentState.label) === receiving_1.ReceivingState.label && currentContext) {
const receivingContext = currentContext;
currentTimetoken = (_a = receivingContext.cursor) === null || _a === void 0 ? void 0 : _a.timetoken;
}
// Manually emit SubscriptionChanged status event
this.dependencies.emitStatus({
category: categories_1.default.PNSubscriptionChangedCategory,
affectedChannels: Array.from(new Set(this.channels)),
affectedChannelGroups: Array.from(new Set(this.groups)),
currentTimetoken,
});
}
}
if (this.dependencies.join) {
this.dependencies.join({
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pubnub",
"version": "10.2.3",
"version": "10.2.4",
"author": "PubNub <support@pubnub.com>",
"description": "Publish & Subscribe Real-time Messaging with PubNub",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export const makeConfiguration = (
return base.PubNubFile;
},
get version(): string {
return '10.2.3';
return '10.2.4';
},
getVersion(): string {
return this.version;
Expand Down
44 changes: 38 additions & 6 deletions src/event-engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Dependencies, EventEngineDispatcher } from './dispatcher';
import { subscriptionTimetokenFromReference } from '../core/utils';
import { UnsubscribedState } from './states/unsubscribed';
import { Dispatcher, Engine } from './core';
import categoryConstants from '../core/constants/categories';
import * as utils from '../core/utils';
import * as effects from './effects';
import * as events from './events';
Expand Down Expand Up @@ -79,6 +80,11 @@ export class EventEngine {
timetoken?: string | number;
withPresence?: boolean;
}): void {
// check if the channels and groups are already subscribed
const hasNewChannels = channels?.some((channel) => !this.channels.includes(channel));
const hasNewGroups = channelGroups?.some((group) => !this.groups.includes(group));
const hasNewSubscriptions = hasNewChannels || hasNewGroups;

this.channels = [...this.channels, ...(channels ?? [])];
this.groups = [...this.groups, ...(channelGroups ?? [])];

Expand All @@ -95,12 +101,38 @@ export class EventEngine {
),
);
} else {
this.engine.transition(
events.subscriptionChange(
Array.from(new Set([...this.channels, ...(channels ?? [])])),
Array.from(new Set([...this.groups, ...(channelGroups ?? [])])),
),
);
if (hasNewSubscriptions) {
this.engine.transition(
events.subscriptionChange(
Array.from(new Set([...this.channels, ...(channels ?? [])])),
Array.from(new Set([...this.groups, ...(channelGroups ?? [])])),
),
);
} else {
this.dependencies.config
.logger()
.debug(
'EventEngine',
'Skipping state transition - all channels/groups already subscribed. Emitting SubscriptionChanged event.',
);
// Get current timetoken from state context
const currentState = this.engine.currentState;
const currentContext = this.engine.currentContext;
let currentTimetoken: string | undefined = '0';

if (currentState?.label === ReceivingState.label && currentContext) {
const receivingContext = currentContext as ReceivingStateContext;
currentTimetoken = receivingContext.cursor?.timetoken;
}

// Manually emit SubscriptionChanged status event
this.dependencies.emitStatus({
category: categoryConstants.PNSubscriptionChangedCategory,
affectedChannels: Array.from(new Set(this.channels)),
affectedChannelGroups: Array.from(new Set(this.groups)),
currentTimetoken,
});
}
}
if (this.dependencies.join) {
this.dependencies.join({
Expand Down
Loading
Loading