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
13 changes: 10 additions & 3 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
---
changelog:
- date: 2025-03-19
version: v9.2.0
changes:
- type: feature
text: "On `pagehide` without `bfcache` client on page will send `terminate` to Shared Worker for early long-poll request termination and `leave` request sending (if configured)."
- type: bug
text: "Fix an issue with the client's state update in Shared Worker caused by `-pnpres` suffixed entries being removed from heartbeat / leave request channels and groups."
- date: 2025-03-13
version: v9.1.0
changes:
Expand Down Expand Up @@ -1178,7 +1185,7 @@ supported-platforms:
- 'Ubuntu 14.04 and up'
- 'Windows 7 and up'
version: 'Pubnub Javascript for Node'
version: '9.1.0'
version: '9.2.0'
sdks:
- full-name: PubNub Javascript SDK
short-name: Javascript
Expand All @@ -1194,7 +1201,7 @@ sdks:
- distribution-type: source
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/archive/refs/tags/v9.1.0.zip
location: https://github.com/pubnub/javascript/archive/refs/tags/v9.2.0.zip
requires:
- name: 'agentkeepalive'
min-version: '3.5.2'
Expand Down Expand Up @@ -1865,7 +1872,7 @@ sdks:
- distribution-type: library
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/releases/download/v9.1.0/pubnub.9.1.0.js
location: https://github.com/pubnub/javascript/releases/download/v9.2.0/pubnub.9.2.0.js
requires:
- name: 'agentkeepalive'
min-version: '3.5.2'
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## v9.2.0
March 19 2025

#### Added
- On `pagehide` without `bfcache` client on page will send `terminate` to Shared Worker for early long-poll request termination and `leave` request sending (if configured).

#### Fixed
- Fix an issue with the client's state update in Shared Worker caused by `-pnpres` suffixed entries being removed from heartbeat / leave request channels and groups.

## v9.1.0
March 13 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.9.1.0.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.9.1.0.min.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.9.2.0.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.9.2.0.min.js

2. Configure your keys:

Expand Down
48 changes: 37 additions & 11 deletions dist/web/pubnub.js
Original file line number Diff line number Diff line change
Expand Up @@ -3179,6 +3179,17 @@
this.callbacks = new Map();
this.setupSubscriptionWorker();
}
/**
* Terminate all ongoing long-poll requests.
*/
terminate() {
this.scheduleEventPost({
type: 'client-unregister',
clientIdentifier: this.configuration.clientIdentifier,
subscriptionKey: this.configuration.subscriptionKey,
logVerbosity: this.configuration.logVerbosity,
});
}
makeSendable(req) {
// Use default request flow for non-subscribe / presence leave requests.
if (!req.path.startsWith('/v2/subscribe') && !req.path.endsWith('/heartbeat') && !req.path.endsWith('/leave'))
Expand Down Expand Up @@ -3430,7 +3441,7 @@
.join('|');
if (typeof crypto !== 'undefined' && crypto.subtle) {
const hash = yield crypto.subtle.digest('SHA-256', new TextEncoder().encode(accessToken));
accessToken = String.fromCharCode(...new Uint8Array(hash));
accessToken = String.fromCharCode(...Array.from(new Uint8Array(hash)));
}
return [token, typeof btoa !== 'undefined' ? btoa(accessToken) : accessToken];
});
Expand Down Expand Up @@ -3891,6 +3902,10 @@
getUseRandomIVs() {
return base.useRandomIVs;
},
getKeepPresenceChannelsInPresenceRequests() {
// @ts-expect-error: Access field from web-based SDK configuration.
return base.sdkFamily === 'Web' && base['subscriptionWorkerUrl'];
},
setPresenceTimeout(value) {
this.heartbeatInterval = value / 2 - 1;
this.presenceTimeout = value;
Expand All @@ -3917,7 +3932,7 @@
return base.PubNubFile;
},
get version() {
return '9.1.0';
return '9.2.0';
},
getVersion() {
return this.version;
Expand Down Expand Up @@ -13593,10 +13608,13 @@
{
// Filtering out presence channels and groups.
let { channels, channelGroups } = parameters;
if (channelGroups)
channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres'));
if (channels)
channels = channels.filter((channel) => !channel.endsWith('-pnpres'));
// Remove `-pnpres` channels / groups if they not acceptable in current PubNub client configuration.
if (!this._configuration.getKeepPresenceChannelsInPresenceRequests()) {
if (channelGroups)
channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres'));
if (channels)
channels = channels.filter((channel) => !channel.endsWith('-pnpres'));
}
// Complete immediately request only for presence channels.
if ((channelGroups !== null && channelGroups !== void 0 ? channelGroups : []).length === 0 && (channels !== null && channels !== void 0 ? channels : []).length === 0) {
return callback({
Expand Down Expand Up @@ -13959,10 +13977,13 @@
{
// Filtering out presence channels and groups.
let { channels, channelGroups } = parameters;
if (channelGroups)
channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres'));
if (channels)
channels = channels.filter((channel) => !channel.endsWith('-pnpres'));
// Remove `-pnpres` channels / groups if they not acceptable in current PubNub client configuration.
if (!this._configuration.getKeepPresenceChannelsInPresenceRequests()) {
if (channelGroups)
channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres'));
if (channels)
channels = channels.filter((channel) => !channel.endsWith('-pnpres'));
}
// Complete immediately request only for presence channels.
if ((channelGroups !== null && channelGroups !== void 0 ? channelGroups : []).length === 0 && (channels !== null && channels !== void 0 ? channels : []).length === 0) {
const responseStatus = {
Expand Down Expand Up @@ -14789,7 +14810,7 @@
{
if (configurationCopy.subscriptionWorkerUrl) {
// Inject subscription worker into transport provider stack.
transport = new SubscriptionWorkerMiddleware({
const middleware = new SubscriptionWorkerMiddleware({
clientIdentifier: clientConfiguration._instanceId,
subscriptionKey: clientConfiguration.subscribeKey,
userId: clientConfiguration.getUserId(),
Expand All @@ -14803,6 +14824,11 @@
tokenManager,
transport,
});
transport = middleware;
window.onpagehide = (event) => {
if (!event.persisted)
middleware.terminate();
};
}
}
const transportMiddleware = new PubNubMiddleware({
Expand Down
4 changes: 2 additions & 2 deletions dist/web/pubnub.min.js

Large diffs are not rendered by default.

Loading
Loading