Skip to content

Commit 0cbe409

Browse files
authored
Add ability to opt-out smart heartbeat (#440)
feat(heartbeat): add ability to opt-out smart heartbeat Add `useSmartHeartbeat` configuration option which allows ignoring implicit heartbeat (with successful subscribe response) and keep sending `heartbeat` calls with fixed intervals. feat(shared-worker): configurable offline detection interval `subscriptionWorkerOfflineClientsCheckInterval` configuration option can be used to configure the interval at which “offline” PubNub clients (when tab closed) detection will be done. feat(shared-worker): configurable unsubscribe for offline clients `subscriptionWorkerUnsubscribeOfflineClients` configuration option can be used to force unsubscribe (presence leave) for “offline” PubNub clients (when tab closed). refactor(shared-worker): debug output on request completion When `subscriptionWorkerLogVerbosity` is set, there will be additional output to the page console with information about which clients will be notified about request completion.
1 parent b36cf02 commit 0cbe409

File tree

19 files changed

+504
-147
lines changed

19 files changed

+504
-147
lines changed

.pubnub.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
---
22
changelog:
3+
- date: 2025-03-06
4+
version: v8.10.0
5+
changes:
6+
- type: feature
7+
text: "Add `useSmartHeartbeat` configuration option which allows ignoring implicit heartbeat (with successful subscribe response) and keep sending `heartbeat` calls with fixed intervals."
8+
- type: feature
9+
text: "`subscriptionWorkerOfflineClientsCheckInterval` configuration option can be used to configure the interval at which “offline” PubNub clients (when tab closed) detection will be done."
10+
- type: feature
11+
text: "`subscriptionWorkerUnsubscribeOfflineClients` configuration option can be used to force unsubscribe (presence leave) for “offline” PubNub clients (when tab closed)."
312
- date: 2025-02-26
413
version: v8.9.1
514
changes:
@@ -1151,7 +1160,7 @@ supported-platforms:
11511160
- 'Ubuntu 14.04 and up'
11521161
- 'Windows 7 and up'
11531162
version: 'Pubnub Javascript for Node'
1154-
version: '8.9.1'
1163+
version: '8.10.0'
11551164
sdks:
11561165
- full-name: PubNub Javascript SDK
11571166
short-name: Javascript
@@ -1167,7 +1176,7 @@ sdks:
11671176
- distribution-type: source
11681177
distribution-repository: GitHub release
11691178
package-name: pubnub.js
1170-
location: https://github.com/pubnub/javascript/archive/refs/tags/v8.9.1.zip
1179+
location: https://github.com/pubnub/javascript/archive/refs/tags/v8.10.0.zip
11711180
requires:
11721181
- name: 'agentkeepalive'
11731182
min-version: '3.5.2'
@@ -1838,7 +1847,7 @@ sdks:
18381847
- distribution-type: library
18391848
distribution-repository: GitHub release
18401849
package-name: pubnub.js
1841-
location: https://github.com/pubnub/javascript/releases/download/v8.9.1/pubnub.8.9.1.js
1850+
location: https://github.com/pubnub/javascript/releases/download/v8.10.0/pubnub.8.10.0.js
18421851
requires:
18431852
- name: 'agentkeepalive'
18441853
min-version: '3.5.2'

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## v8.10.0
2+
March 06 2025
3+
4+
#### Added
5+
- Add `useSmartHeartbeat` configuration option which allows ignoring implicit heartbeat (with successful subscribe response) and keep sending `heartbeat` calls with fixed intervals.
6+
- `subscriptionWorkerOfflineClientsCheckInterval` configuration option can be used to configure the interval at which “offline” PubNub clients (when tab closed) detection will be done.
7+
- `subscriptionWorkerUnsubscribeOfflineClients` configuration option can be used to force unsubscribe (presence leave) for “offline” PubNub clients (when tab closed).
8+
19
## v8.9.1
210
February 26 2025
311

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2
2828
npm install pubnub
2929
```
3030
* or download one of our builds from our CDN:
31-
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.9.1.js
32-
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.9.1.min.js
31+
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.10.0.js
32+
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.10.0.min.js
3333
3434
2. Configure your keys:
3535

dist/web/pubnub.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3261,6 +3261,8 @@
32613261
userId: this.configuration.userId,
32623262
heartbeatInterval: this.configuration.heartbeatInterval,
32633263
logVerbosity: this.configuration.logVerbosity,
3264+
workerOfflineClientsCheckInterval: this.configuration.workerOfflineClientsCheckInterval,
3265+
workerUnsubscribeOfflineClients: this.configuration.workerUnsubscribeOfflineClients,
32643266
workerLogVerbosity: this.configuration.workerLogVerbosity,
32653267
}, true);
32663268
this.subscriptionWorker.port.onmessage = (event) => this.handleWorkerEvent(event);
@@ -3433,6 +3435,10 @@
34333435
* Whether configured user presence state should be maintained by the PubNub client or not.
34343436
*/
34353437
const MAINTAIN_PRESENCE_STATE = true;
3438+
/**
3439+
* Whether heartbeat should be postponed on successful subscribe response or not.
3440+
*/
3441+
const USE_SMART_HEARTBEAT = true;
34363442
/**
34373443
* Whether PubNub client should try to utilize existing TCP connection for new requests or not.
34383444
*/
@@ -3489,7 +3495,7 @@
34893495
* @internal
34903496
*/
34913497
const setDefaults$1 = (configuration) => {
3492-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
3498+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
34933499
// Copy configuration.
34943500
const configurationCopy = Object.assign({}, configuration);
34953501
(_a = configurationCopy.logVerbosity) !== null && _a !== void 0 ? _a : (configurationCopy.logVerbosity = USE_VERBOSE_LOGGING);
@@ -3504,13 +3510,14 @@
35043510
(_k = configurationCopy.autoNetworkDetection) !== null && _k !== void 0 ? _k : (configurationCopy.autoNetworkDetection = AUTO_NETWORK_DETECTION);
35053511
(_l = configurationCopy.enableEventEngine) !== null && _l !== void 0 ? _l : (configurationCopy.enableEventEngine = ENABLE_EVENT_ENGINE);
35063512
(_m = configurationCopy.maintainPresenceState) !== null && _m !== void 0 ? _m : (configurationCopy.maintainPresenceState = MAINTAIN_PRESENCE_STATE);
3507-
(_o = configurationCopy.keepAlive) !== null && _o !== void 0 ? _o : (configurationCopy.keepAlive = KEEP_ALIVE$1);
3513+
(_o = configurationCopy.useSmartHeartbeat) !== null && _o !== void 0 ? _o : (configurationCopy.useSmartHeartbeat = USE_SMART_HEARTBEAT);
3514+
(_p = configurationCopy.keepAlive) !== null && _p !== void 0 ? _p : (configurationCopy.keepAlive = KEEP_ALIVE$1);
35083515
if (configurationCopy.userId && configurationCopy.uuid)
35093516
throw new PubNubError("PubNub client configuration error: use only 'userId'");
3510-
(_p = configurationCopy.userId) !== null && _p !== void 0 ? _p : (configurationCopy.userId = configurationCopy.uuid);
3517+
(_q = configurationCopy.userId) !== null && _q !== void 0 ? _q : (configurationCopy.userId = configurationCopy.uuid);
35113518
if (!configurationCopy.userId)
35123519
throw new PubNubError("PubNub client configuration error: 'userId' not set");
3513-
else if (((_q = configurationCopy.userId) === null || _q === void 0 ? void 0 : _q.trim().length) === 0)
3520+
else if (((_r = configurationCopy.userId) === null || _r === void 0 ? void 0 : _r.trim().length) === 0)
35143521
throw new PubNubError("PubNub client configuration error: 'userId' is empty");
35153522
// Generate default origin subdomains.
35163523
if (!configurationCopy.origin)
@@ -3599,6 +3606,14 @@
35993606
* Whether verbose logging should be enabled for `Subscription` worker to print debug messages or not.
36003607
*/
36013608
const SUBSCRIPTION_WORKER_LOG_VERBOSITY = false;
3609+
/**
3610+
* Interval at which Shared Worker should check whether PubNub instances which used it still active or not.
3611+
*/
3612+
const SUBSCRIPTION_WORKER_OFFLINE_CLIENTS_CHECK_INTERVAL = 10;
3613+
/**
3614+
* Whether `leave` request should be sent for _offline_ PubNub client or not.
3615+
*/
3616+
const SUBSCRIPTION_WORKER_UNSUBSCRIBE_OFFLINE_CLIENTS = false;
36023617
/**
36033618
* Use modern Web Fetch API for network requests by default.
36043619
*/
@@ -3615,13 +3630,13 @@
36153630
* @internal
36163631
*/
36173632
const setDefaults = (configuration) => {
3618-
var _a, _b, _c, _d;
3633+
var _a, _b, _c, _d, _e, _f;
36193634
// Force disable service workers if environment doesn't support them.
36203635
if (configuration.subscriptionWorkerUrl && typeof SharedWorker === 'undefined')
36213636
configuration.subscriptionWorkerUrl = null;
36223637
return Object.assign(Object.assign({}, setDefaults$1(configuration)), {
36233638
// Set platform-specific options.
3624-
listenToBrowserNetworkEvents: (_a = configuration.listenToBrowserNetworkEvents) !== null && _a !== void 0 ? _a : LISTEN_TO_BROWSER_NETWORK_EVENTS, subscriptionWorkerUrl: configuration.subscriptionWorkerUrl, subscriptionWorkerLogVerbosity: (_b = configuration.subscriptionWorkerLogVerbosity) !== null && _b !== void 0 ? _b : SUBSCRIPTION_WORKER_LOG_VERBOSITY, transport: (_c = configuration.transport) !== null && _c !== void 0 ? _c : TRANSPORT, keepAlive: (_d = configuration.keepAlive) !== null && _d !== void 0 ? _d : KEEP_ALIVE });
3639+
listenToBrowserNetworkEvents: (_a = configuration.listenToBrowserNetworkEvents) !== null && _a !== void 0 ? _a : LISTEN_TO_BROWSER_NETWORK_EVENTS, subscriptionWorkerUrl: configuration.subscriptionWorkerUrl, subscriptionWorkerOfflineClientsCheckInterval: (_b = configuration.subscriptionWorkerOfflineClientsCheckInterval) !== null && _b !== void 0 ? _b : SUBSCRIPTION_WORKER_OFFLINE_CLIENTS_CHECK_INTERVAL, subscriptionWorkerUnsubscribeOfflineClients: (_c = configuration.subscriptionWorkerUnsubscribeOfflineClients) !== null && _c !== void 0 ? _c : SUBSCRIPTION_WORKER_UNSUBSCRIBE_OFFLINE_CLIENTS, subscriptionWorkerLogVerbosity: (_d = configuration.subscriptionWorkerLogVerbosity) !== null && _d !== void 0 ? _d : SUBSCRIPTION_WORKER_LOG_VERBOSITY, transport: (_e = configuration.transport) !== null && _e !== void 0 ? _e : TRANSPORT, keepAlive: (_f = configuration.keepAlive) !== null && _f !== void 0 ? _f : KEEP_ALIVE });
36253640
};
36263641

36273642
var uuid = {exports: {}};
@@ -3803,7 +3818,7 @@
38033818
return base.PubNubFile;
38043819
},
38053820
get version() {
3806-
return '8.9.1';
3821+
return '8.10.0';
38073822
},
38083823
getVersion() {
38093824
return this.version;
@@ -4930,7 +4945,7 @@
49304945
*/
49314946
reconnect(forUnsubscribe = false) {
49324947
this.startSubscribeLoop();
4933-
if (!forUnsubscribe)
4948+
if (!forUnsubscribe && this.configuration.useSmartHeartbeat)
49344949
this.startHeartbeatTimer();
49354950
}
49364951
/**
@@ -14565,6 +14580,8 @@
1456514580
workerUrl: configurationCopy.subscriptionWorkerUrl,
1456614581
sdkVersion: clientConfiguration.getVersion(),
1456714582
heartbeatInterval: clientConfiguration.getHeartbeatInterval(),
14583+
workerOfflineClientsCheckInterval: platformConfiguration.subscriptionWorkerOfflineClientsCheckInterval,
14584+
workerUnsubscribeOfflineClients: platformConfiguration.subscriptionWorkerUnsubscribeOfflineClients,
1456814585
logVerbosity: clientConfiguration.logVerbosity,
1456914586
workerLogVerbosity: platformConfiguration.subscriptionWorkerLogVerbosity,
1457014587
transport,

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.

0 commit comments

Comments
 (0)