Skip to content

Commit 0d424f9

Browse files
authored
Move heartbeat call into SharedWorker (#433)
feat(shared-worker): move heartbeat call into `SharedWorker` Pass heartbeat request through `SharedWorker` (if used) to optimize the number of requests for clients opened in few tabs and subscribed to the same channels / groups list. refactor(heartbeat): remove redundant `heartbeat` from unsubscribe Don't send `heartbeat` request on unsubscribe.
1 parent f5f9670 commit 0d424f9

File tree

15 files changed

+635
-59
lines changed

15 files changed

+635
-59
lines changed

.pubnub.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
---
22
changelog:
3+
- date: 2025-01-30
4+
version: v8.7.0
5+
changes:
6+
- type: feature
7+
text: "Pass heartbeat request through `SharedWorker` (if used) to optimize the number of requests for clients opened in few tabs and subscribed on same channels / groups list."
8+
- type: improvement
9+
text: "Don't send `heartbeat` request to unsubscribe."
310
- date: 2025-01-21
411
version: v8.6.0
512
changes:
@@ -1111,7 +1118,7 @@ supported-platforms:
11111118
- 'Ubuntu 14.04 and up'
11121119
- 'Windows 7 and up'
11131120
version: 'Pubnub Javascript for Node'
1114-
version: '8.6.0'
1121+
version: '8.7.0'
11151122
sdks:
11161123
- full-name: PubNub Javascript SDK
11171124
short-name: Javascript
@@ -1127,7 +1134,7 @@ sdks:
11271134
- distribution-type: source
11281135
distribution-repository: GitHub release
11291136
package-name: pubnub.js
1130-
location: https://github.com/pubnub/javascript/archive/refs/tags/v8.6.0.zip
1137+
location: https://github.com/pubnub/javascript/archive/refs/tags/v8.7.0.zip
11311138
requires:
11321139
- name: 'agentkeepalive'
11331140
min-version: '3.5.2'
@@ -1798,7 +1805,7 @@ sdks:
17981805
- distribution-type: library
17991806
distribution-repository: GitHub release
18001807
package-name: pubnub.js
1801-
location: https://github.com/pubnub/javascript/releases/download/v8.6.0/pubnub.8.6.0.js
1808+
location: https://github.com/pubnub/javascript/releases/download/v8.7.0/pubnub.8.7.0.js
18021809
requires:
18031810
- name: 'agentkeepalive'
18041811
min-version: '3.5.2'

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## v8.7.0
2+
January 30 2025
3+
4+
#### Added
5+
- Pass heartbeat request through `SharedWorker` (if used) to optimize the number of requests for clients opened in few tabs and subscribed on same channels / groups list.
6+
7+
#### Modified
8+
- Don't send `heartbeat` request to unsubscribe.
9+
110
## v8.6.0
211
January 21 2025
312

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.6.0.js
32-
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.6.0.min.js
31+
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.7.0.js
32+
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.7.0.min.js
3333
3434
2. Configure your keys:
3535

dist/web/pubnub.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,7 +3078,7 @@
30783078
}
30793079
makeSendable(req) {
30803080
// Use default request flow for non-subscribe / presence leave requests.
3081-
if (!req.path.startsWith('/v2/subscribe') && !req.path.endsWith('/leave'))
3081+
if (!req.path.startsWith('/v2/subscribe') && !req.path.endsWith('/heartbeat') && !req.path.endsWith('/leave'))
30823082
return this.configuration.transport.makeSendable(req);
30833083
let controller;
30843084
const sendRequestEvent = {
@@ -3188,6 +3188,7 @@
31883188
clientIdentifier: this.configuration.clientIdentifier,
31893189
subscriptionKey: this.configuration.subscriptionKey,
31903190
userId: this.configuration.userId,
3191+
heartbeatInterval: this.configuration.heartbeatInterval,
31913192
logVerbosity: this.configuration.logVerbosity,
31923193
workerLogVerbosity: this.configuration.workerLogVerbosity,
31933194
}, true);
@@ -3212,7 +3213,7 @@
32123213
else if (data.type === 'shared-worker-console-dir') {
32133214
if (data.message)
32143215
console.log(`[SharedWorker] ${data.message}`);
3215-
console.dir(data.data);
3216+
console.dir(data.data, { depth: 10 });
32163217
}
32173218
else if (data.type === 'shared-worker-ping') {
32183219
const { logVerbosity, subscriptionKey, clientIdentifier } = this.configuration;
@@ -3974,7 +3975,7 @@
39743975
return base.PubNubFile;
39753976
},
39763977
get version() {
3977-
return '8.6.0';
3978+
return '8.7.0';
39783979
},
39793980
getVersion() {
39803981
return this.version;
@@ -4708,9 +4709,16 @@
47084709
this.stopHeartbeatTimer();
47094710
this.reconnectionManager.stopPolling();
47104711
}
4711-
reconnect() {
4712+
/**
4713+
* Restart subscription loop with current state.
4714+
*
4715+
* @param forUnsubscribe - Whether restarting subscription loop as part of channels list change on
4716+
* unsubscribe or not.
4717+
*/
4718+
reconnect(forUnsubscribe = false) {
47124719
this.startSubscribeLoop();
4713-
this.startHeartbeatTimer();
4720+
if (!forUnsubscribe)
4721+
this.startHeartbeatTimer();
47144722
}
47154723
/**
47164724
* Update channels and groups used in subscription loop.
@@ -4809,7 +4817,7 @@
48094817
this.region = null;
48104818
this.reconnectionManager.stopPolling();
48114819
}
4812-
this.reconnect();
4820+
this.reconnect(true);
48134821
}
48144822
unsubscribeAll(isOffline) {
48154823
this.unsubscribe({
@@ -14546,6 +14554,7 @@
1454614554
userId: clientConfiguration.getUserId(),
1454714555
workerUrl: configurationCopy.subscriptionWorkerUrl,
1454814556
sdkVersion: clientConfiguration.getVersion(),
14557+
heartbeatInterval: clientConfiguration.getHeartbeatInterval(),
1454914558
logVerbosity: clientConfiguration.logVerbosity,
1455014559
workerLogVerbosity: platformConfiguration.subscriptionWorkerLogVerbosity,
1455114560
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)