Skip to content

Commit

Permalink
Fix automatic heartbeatInterval set (#378)
Browse files Browse the repository at this point in the history
fix(configuration): fix automatic `heartbeatInterval` set

Fix issue because of which `heartbeatInterval` wasn't computed if `presenceTimeout` provided
during PubNub client configuration
  • Loading branch information
parfeon authored Jun 5, 2024
1 parent 26c4d73 commit 78744e1
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 18 deletions.
11 changes: 8 additions & 3 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
---
changelog:
- date: 2024-06-05
version: v8.2.2
changes:
- type: bug
text: "Fix issue because of which `heartbeatInterval` wasn't computed if `presenceTimeout` provided during PubNub client configuration."
- date: 2024-05-22
version: v8.2.1
changes:
Expand Down Expand Up @@ -993,7 +998,7 @@ supported-platforms:
- 'Ubuntu 14.04 and up'
- 'Windows 7 and up'
version: 'Pubnub Javascript for Node'
version: '8.2.1'
version: '8.2.2'
sdks:
- full-name: PubNub Javascript SDK
short-name: Javascript
Expand All @@ -1009,7 +1014,7 @@ sdks:
- distribution-type: source
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.1.zip
location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.2.zip
requires:
- name: 'agentkeepalive'
min-version: '3.5.2'
Expand Down Expand Up @@ -1680,7 +1685,7 @@ sdks:
- distribution-type: library
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/releases/download/v8.2.1/pubnub.8.2.1.js
location: https://github.com/pubnub/javascript/releases/download/v8.2.2/pubnub.8.2.2.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 @@
## v8.2.2
June 05 2024

#### Fixed
- Fix issue because of which `heartbeatInterval` wasn't computed if `presenceTimeout` provided during PubNub client configuration.

## v8.2.1
May 22 2024

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,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.8.2.1.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.1.min.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.2.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.2.min.js
2. Configure your keys:
Expand Down
9 changes: 6 additions & 3 deletions dist/web/pubnub.js
Original file line number Diff line number Diff line change
Expand Up @@ -3525,7 +3525,7 @@
* @internal
*/
const setDefaults$1 = (configuration) => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
// Copy configuration.
const configurationCopy = Object.assign({}, configuration);
(_a = configurationCopy.logVerbosity) !== null && _a !== void 0 ? _a : (configurationCopy.logVerbosity = USE_VERBOSE_LOGGING);
Expand Down Expand Up @@ -3560,7 +3560,10 @@
// eslint-disable-next-line no-console
console.log('WARNING: Presence timeout is less than the minimum. Using minimum value: ', PRESENCE_TIMEOUT_MINIMUM);
}
(_q = configurationCopy.presenceTimeout) !== null && _q !== void 0 ? _q : (configurationCopy.presenceTimeout = PRESENCE_TIMEOUT);
if (configurationCopy.presenceTimeout !== undefined)
configurationCopy.heartbeatInterval = configurationCopy.presenceTimeout / 2 - 1;
else
configurationCopy.presenceTimeout = PRESENCE_TIMEOUT;
// Apply extended configuration defaults.
let announceSuccessfulHeartbeats = ANNOUNCE_HEARTBEAT_SUCCESS;
let announceFailedHeartbeats = ANNOUNCE_HEARTBEAT_FAILURE;
Expand Down Expand Up @@ -3810,7 +3813,7 @@
return base.PubNubFile;
},
get version() {
return '8.2.1';
return '8.2.2';
},
getVersion() {
return this.version;
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 @@ -110,7 +110,7 @@ const makeConfiguration = (base, setupCryptoModule) => {
return base.PubNubFile;
},
get version() {
return '8.2.1';
return '8.2.2';
},
getVersion() {
return this.version;
Expand Down
7 changes: 5 additions & 2 deletions lib/core/interfaces/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const PRESENCE_TIMEOUT_MINIMUM = 20;
* @internal
*/
const setDefaults = (configuration) => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
// Copy configuration.
const configurationCopy = Object.assign({}, configuration);
(_a = configurationCopy.logVerbosity) !== null && _a !== void 0 ? _a : (configurationCopy.logVerbosity = USE_VERBOSE_LOGGING);
Expand Down Expand Up @@ -129,7 +129,10 @@ const setDefaults = (configuration) => {
// eslint-disable-next-line no-console
console.log('WARNING: Presence timeout is less than the minimum. Using minimum value: ', PRESENCE_TIMEOUT_MINIMUM);
}
(_q = configurationCopy.presenceTimeout) !== null && _q !== void 0 ? _q : (configurationCopy.presenceTimeout = PRESENCE_TIMEOUT);
if (configurationCopy.presenceTimeout !== undefined)
configurationCopy.heartbeatInterval = configurationCopy.presenceTimeout / 2 - 1;
else
configurationCopy.presenceTimeout = PRESENCE_TIMEOUT;
// Apply extended configuration defaults.
let announceSuccessfulHeartbeats = ANNOUNCE_HEARTBEAT_SUCCESS;
let announceFailedHeartbeats = ANNOUNCE_HEARTBEAT_FAILURE;
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": "8.2.1",
"version": "8.2.2",
"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 @@ -169,7 +169,7 @@ export const makeConfiguration = (
return base.PubNubFile;
},
get version(): string {
return '8.2.1';
return '8.2.2';
},
getVersion(): string {
return this.version;
Expand Down
4 changes: 3 additions & 1 deletion src/core/interfaces/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,9 @@ export const setDefaults = (configuration: UserConfiguration): ExtendedConfigura
console.log('WARNING: Presence timeout is less than the minimum. Using minimum value: ', PRESENCE_TIMEOUT_MINIMUM);
}

configurationCopy.presenceTimeout ??= PRESENCE_TIMEOUT;
if (configurationCopy.presenceTimeout !== undefined)
configurationCopy.heartbeatInterval = configurationCopy.presenceTimeout / 2 - 1;
else configurationCopy.presenceTimeout = PRESENCE_TIMEOUT;

// Apply extended configuration defaults.
let announceSuccessfulHeartbeats = ANNOUNCE_HEARTBEAT_SUCCESS;
Expand Down
22 changes: 22 additions & 0 deletions test/integration/components/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import assert from 'assert';
import PubNub from '../../../src/node/index';
import { PrivateClientConfiguration } from '../../../src/core/interfaces/configuration';

describe('components/config', () => {
describe('AuthKey parameter', () => {
Expand Down Expand Up @@ -82,5 +83,26 @@ describe('components/config', () => {
pubnub.setUUID(' ');
});
});

it('heartbeatInterval not set if presenceTimeout not set', () => {
const pubnub = new PubNub({
subscribeKey: 'mySubKey',
publishKey: 'myPublishKey',
uuid: 'myUUID',
});
assert.equal((pubnub.configuration as PrivateClientConfiguration).getPresenceTimeout(), 300);
assert.equal((pubnub.configuration as PrivateClientConfiguration).getHeartbeatInterval(), undefined);
});

it('heartbeatInterval is set by formula when presenceTimeout is set', () => {
const pubnub = new PubNub({
subscribeKey: 'mySubKey',
publishKey: 'myPublishKey',
presenceTimeout: 30,
uuid: 'myUUID',
});
assert.equal((pubnub.configuration as PrivateClientConfiguration).getPresenceTimeout(), 30);
assert.equal((pubnub.configuration as PrivateClientConfiguration).getHeartbeatInterval(), 30 / 2 - 1);
});
});
});

0 comments on commit 78744e1

Please sign in to comment.