Skip to content

Commit

Permalink
Add file upload and download timeout configuration (#430)
Browse files Browse the repository at this point in the history
feat(file-share): add file upload and download timeout configuration

Add `fileRequestTimeout` client configuration option which is specific only for requests which
upload and download files.

fix: fix `instanceId` query parameter

Fix issue with `instanceId` set to `undefined` for requests with `useInstanceId` configuration
flag set to `true`.
  • Loading branch information
parfeon authored Jan 15, 2025
1 parent 1a2ddeb commit 875e44b
Show file tree
Hide file tree
Showing 16 changed files with 140 additions and 46 deletions.
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-01-15
version: v8.5.0
changes:
- type: feature
text: "Add `fileRequestTimeout` client configuration option which is specific only for requests which upload and download files."
- type: bug
text: "Fix issue with `instanceId` set to `undefined` for requests with `useInstanceId` configuration flag set to `true`."
- date: 2025-01-02
version: v8.4.1
changes:
Expand Down Expand Up @@ -1099,7 +1106,7 @@ supported-platforms:
- 'Ubuntu 14.04 and up'
- 'Windows 7 and up'
version: 'Pubnub Javascript for Node'
version: '8.4.1'
version: '8.5.0'
sdks:
- full-name: PubNub Javascript SDK
short-name: Javascript
Expand All @@ -1115,7 +1122,7 @@ sdks:
- distribution-type: source
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/archive/refs/tags/v8.4.1.zip
location: https://github.com/pubnub/javascript/archive/refs/tags/v8.5.0.zip
requires:
- name: 'agentkeepalive'
min-version: '3.5.2'
Expand Down Expand Up @@ -1786,7 +1793,7 @@ sdks:
- distribution-type: library
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/releases/download/v8.4.1/pubnub.8.4.1.js
location: https://github.com/pubnub/javascript/releases/download/v8.5.0/pubnub.8.5.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 @@
## v8.5.0
January 15 2025

#### Added
- Add `fileRequestTimeout` client configuration option which is specific only for requests which upload and download files.

#### Fixed
- Fix issue with `instanceId` set to `undefined` for requests with `useInstanceId` configuration flag set to `true`.

## v8.4.1
January 02 2025

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.4.1.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.4.1.min.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.5.0.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.5.0.min.js
2. Configure your keys:
Expand Down
46 changes: 30 additions & 16 deletions dist/web/pubnub.js
Original file line number Diff line number Diff line change
Expand Up @@ -3644,6 +3644,10 @@
* Subscription request timeout.
*/
const SUBSCRIBE_REQUEST_TIMEOUT = 310;
/**
* File upload / download request timeout.
*/
const FILE_REQUEST_TIMEOUT = 300;
/**
* Default user presence timeout.
*/
Expand All @@ -3660,27 +3664,28 @@
* @internal
*/
const setDefaults$1 = (configuration) => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
// Copy configuration.
const configurationCopy = Object.assign({}, configuration);
(_a = configurationCopy.logVerbosity) !== null && _a !== void 0 ? _a : (configurationCopy.logVerbosity = USE_VERBOSE_LOGGING);
(_b = configurationCopy.ssl) !== null && _b !== void 0 ? _b : (configurationCopy.ssl = USE_SSL);
(_c = configurationCopy.transactionalRequestTimeout) !== null && _c !== void 0 ? _c : (configurationCopy.transactionalRequestTimeout = TRANSACTIONAL_REQUEST_TIMEOUT);
(_d = configurationCopy.subscribeRequestTimeout) !== null && _d !== void 0 ? _d : (configurationCopy.subscribeRequestTimeout = SUBSCRIBE_REQUEST_TIMEOUT);
(_e = configurationCopy.restore) !== null && _e !== void 0 ? _e : (configurationCopy.restore = RESTORE);
(_f = configurationCopy.useInstanceId) !== null && _f !== void 0 ? _f : (configurationCopy.useInstanceId = USE_INSTANCE_ID);
(_g = configurationCopy.suppressLeaveEvents) !== null && _g !== void 0 ? _g : (configurationCopy.suppressLeaveEvents = SUPPRESS_LEAVE_EVENTS);
(_h = configurationCopy.requestMessageCountThreshold) !== null && _h !== void 0 ? _h : (configurationCopy.requestMessageCountThreshold = DEDUPE_CACHE_SIZE);
(_j = configurationCopy.autoNetworkDetection) !== null && _j !== void 0 ? _j : (configurationCopy.autoNetworkDetection = AUTO_NETWORK_DETECTION);
(_k = configurationCopy.enableEventEngine) !== null && _k !== void 0 ? _k : (configurationCopy.enableEventEngine = ENABLE_EVENT_ENGINE);
(_l = configurationCopy.maintainPresenceState) !== null && _l !== void 0 ? _l : (configurationCopy.maintainPresenceState = MAINTAIN_PRESENCE_STATE);
(_m = configurationCopy.keepAlive) !== null && _m !== void 0 ? _m : (configurationCopy.keepAlive = KEEP_ALIVE$1);
(_e = configurationCopy.fileRequestTimeout) !== null && _e !== void 0 ? _e : (configurationCopy.fileRequestTimeout = FILE_REQUEST_TIMEOUT);
(_f = configurationCopy.restore) !== null && _f !== void 0 ? _f : (configurationCopy.restore = RESTORE);
(_g = configurationCopy.useInstanceId) !== null && _g !== void 0 ? _g : (configurationCopy.useInstanceId = USE_INSTANCE_ID);
(_h = configurationCopy.suppressLeaveEvents) !== null && _h !== void 0 ? _h : (configurationCopy.suppressLeaveEvents = SUPPRESS_LEAVE_EVENTS);
(_j = configurationCopy.requestMessageCountThreshold) !== null && _j !== void 0 ? _j : (configurationCopy.requestMessageCountThreshold = DEDUPE_CACHE_SIZE);
(_k = configurationCopy.autoNetworkDetection) !== null && _k !== void 0 ? _k : (configurationCopy.autoNetworkDetection = AUTO_NETWORK_DETECTION);
(_l = configurationCopy.enableEventEngine) !== null && _l !== void 0 ? _l : (configurationCopy.enableEventEngine = ENABLE_EVENT_ENGINE);
(_m = configurationCopy.maintainPresenceState) !== null && _m !== void 0 ? _m : (configurationCopy.maintainPresenceState = MAINTAIN_PRESENCE_STATE);
(_o = configurationCopy.keepAlive) !== null && _o !== void 0 ? _o : (configurationCopy.keepAlive = KEEP_ALIVE$1);
if (configurationCopy.userId && configurationCopy.uuid)
throw new PubNubError("PubNub client configuration error: use only 'userId'");
(_o = configurationCopy.userId) !== null && _o !== void 0 ? _o : (configurationCopy.userId = configurationCopy.uuid);
(_p = configurationCopy.userId) !== null && _p !== void 0 ? _p : (configurationCopy.userId = configurationCopy.uuid);
if (!configurationCopy.userId)
throw new PubNubError("PubNub client configuration error: 'userId' not set");
else if (((_p = configurationCopy.userId) === null || _p === void 0 ? void 0 : _p.trim().length) === 0)
else if (((_q = configurationCopy.userId) === null || _q === void 0 ? void 0 : _q.trim().length) === 0)
throw new PubNubError("PubNub client configuration error: 'userId' is empty");
// Generate default origin subdomains.
if (!configurationCopy.origin)
Expand Down Expand Up @@ -3894,6 +3899,11 @@
return this._instanceId;
return undefined;
},
getInstanceId() {
if (this.useInstanceId)
return this._instanceId;
return undefined;
},
getUserId() {
return this.userId;
},
Expand Down Expand Up @@ -3957,11 +3967,14 @@
getSubscribeTimeout() {
return this.subscribeRequestTimeout;
},
getFileTimeout() {
return this.fileRequestTimeout;
},
get PubNubFile() {
return base.PubNubFile;
},
get version() {
return '8.4.1';
return '8.5.0';
},
getVersion() {
return this.version;
Expand Down Expand Up @@ -4270,7 +4283,7 @@
req.queryParameters = {};
// Modify request with required information.
if (clientConfiguration.useInstanceId)
req.queryParameters['instanceid'] = clientConfiguration.instanceId;
req.queryParameters['instanceid'] = clientConfiguration.getInstanceId();
if (!req.queryParameters['uuid'])
req.queryParameters['uuid'] = clientConfiguration.userId;
if (clientConfiguration.useRequestId)
Expand Down Expand Up @@ -13037,9 +13050,10 @@
}
// Complete request configuration.
const transportRequest = request.request();
if (transportRequest.formData && transportRequest.formData.length > 0) {
// Set 300 seconds file upload request delay.
transportRequest.timeout = 300;
if ((transportRequest.formData && transportRequest.formData.length > 0) ||
request.operation() === RequestOperation$1.PNDownloadFileOperation) {
// Set file upload / download request delay.
transportRequest.timeout = this._configuration.getFileTimeout();
}
else {
if (request.operation() === RequestOperation$1.PNSubscribeOperation)
Expand Down
4 changes: 2 additions & 2 deletions dist/web/pubnub.min.js

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion lib/core/components/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ const makeConfiguration = (base, setupCryptoModule) => {
return this._instanceId;
return undefined;
},
getInstanceId() {
if (this.useInstanceId)
return this._instanceId;
return undefined;
},
getUserId() {
return this.userId;
},
Expand Down Expand Up @@ -108,11 +113,14 @@ const makeConfiguration = (base, setupCryptoModule) => {
getSubscribeTimeout() {
return this.subscribeRequestTimeout;
},
getFileTimeout() {
return this.fileRequestTimeout;
},
get PubNubFile() {
return base.PubNubFile;
},
get version() {
return '8.4.1';
return '8.5.0';
},
getVersion() {
return this.version;
Expand Down
27 changes: 16 additions & 11 deletions lib/core/interfaces/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ const TRANSACTIONAL_REQUEST_TIMEOUT = 15;
* Subscription request timeout.
*/
const SUBSCRIBE_REQUEST_TIMEOUT = 310;
/**
* File upload / download request timeout.
*/
const FILE_REQUEST_TIMEOUT = 300;
/**
* Default user presence timeout.
*/
Expand All @@ -94,27 +98,28 @@ const PRESENCE_TIMEOUT_MINIMUM = 20;
* @internal
*/
const setDefaults = (configuration) => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
// Copy configuration.
const configurationCopy = Object.assign({}, configuration);
(_a = configurationCopy.logVerbosity) !== null && _a !== void 0 ? _a : (configurationCopy.logVerbosity = USE_VERBOSE_LOGGING);
(_b = configurationCopy.ssl) !== null && _b !== void 0 ? _b : (configurationCopy.ssl = USE_SSL);
(_c = configurationCopy.transactionalRequestTimeout) !== null && _c !== void 0 ? _c : (configurationCopy.transactionalRequestTimeout = TRANSACTIONAL_REQUEST_TIMEOUT);
(_d = configurationCopy.subscribeRequestTimeout) !== null && _d !== void 0 ? _d : (configurationCopy.subscribeRequestTimeout = SUBSCRIBE_REQUEST_TIMEOUT);
(_e = configurationCopy.restore) !== null && _e !== void 0 ? _e : (configurationCopy.restore = RESTORE);
(_f = configurationCopy.useInstanceId) !== null && _f !== void 0 ? _f : (configurationCopy.useInstanceId = USE_INSTANCE_ID);
(_g = configurationCopy.suppressLeaveEvents) !== null && _g !== void 0 ? _g : (configurationCopy.suppressLeaveEvents = SUPPRESS_LEAVE_EVENTS);
(_h = configurationCopy.requestMessageCountThreshold) !== null && _h !== void 0 ? _h : (configurationCopy.requestMessageCountThreshold = DEDUPE_CACHE_SIZE);
(_j = configurationCopy.autoNetworkDetection) !== null && _j !== void 0 ? _j : (configurationCopy.autoNetworkDetection = AUTO_NETWORK_DETECTION);
(_k = configurationCopy.enableEventEngine) !== null && _k !== void 0 ? _k : (configurationCopy.enableEventEngine = ENABLE_EVENT_ENGINE);
(_l = configurationCopy.maintainPresenceState) !== null && _l !== void 0 ? _l : (configurationCopy.maintainPresenceState = MAINTAIN_PRESENCE_STATE);
(_m = configurationCopy.keepAlive) !== null && _m !== void 0 ? _m : (configurationCopy.keepAlive = KEEP_ALIVE);
(_e = configurationCopy.fileRequestTimeout) !== null && _e !== void 0 ? _e : (configurationCopy.fileRequestTimeout = FILE_REQUEST_TIMEOUT);
(_f = configurationCopy.restore) !== null && _f !== void 0 ? _f : (configurationCopy.restore = RESTORE);
(_g = configurationCopy.useInstanceId) !== null && _g !== void 0 ? _g : (configurationCopy.useInstanceId = USE_INSTANCE_ID);
(_h = configurationCopy.suppressLeaveEvents) !== null && _h !== void 0 ? _h : (configurationCopy.suppressLeaveEvents = SUPPRESS_LEAVE_EVENTS);
(_j = configurationCopy.requestMessageCountThreshold) !== null && _j !== void 0 ? _j : (configurationCopy.requestMessageCountThreshold = DEDUPE_CACHE_SIZE);
(_k = configurationCopy.autoNetworkDetection) !== null && _k !== void 0 ? _k : (configurationCopy.autoNetworkDetection = AUTO_NETWORK_DETECTION);
(_l = configurationCopy.enableEventEngine) !== null && _l !== void 0 ? _l : (configurationCopy.enableEventEngine = ENABLE_EVENT_ENGINE);
(_m = configurationCopy.maintainPresenceState) !== null && _m !== void 0 ? _m : (configurationCopy.maintainPresenceState = MAINTAIN_PRESENCE_STATE);
(_o = configurationCopy.keepAlive) !== null && _o !== void 0 ? _o : (configurationCopy.keepAlive = KEEP_ALIVE);
if (configurationCopy.userId && configurationCopy.uuid)
throw new pubnub_error_1.PubNubError("PubNub client configuration error: use only 'userId'");
(_o = configurationCopy.userId) !== null && _o !== void 0 ? _o : (configurationCopy.userId = configurationCopy.uuid);
(_p = configurationCopy.userId) !== null && _p !== void 0 ? _p : (configurationCopy.userId = configurationCopy.uuid);
if (!configurationCopy.userId)
throw new pubnub_error_1.PubNubError("PubNub client configuration error: 'userId' not set");
else if (((_p = configurationCopy.userId) === null || _p === void 0 ? void 0 : _p.trim().length) === 0)
else if (((_q = configurationCopy.userId) === null || _q === void 0 ? void 0 : _q.trim().length) === 0)
throw new pubnub_error_1.PubNubError("PubNub client configuration error: 'userId' is empty");
// Generate default origin subdomains.
if (!configurationCopy.origin)
Expand Down
7 changes: 4 additions & 3 deletions lib/core/pubnub-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,10 @@ class PubNubCore {
}
// Complete request configuration.
const transportRequest = request.request();
if (transportRequest.formData && transportRequest.formData.length > 0) {
// Set 300 seconds file upload request delay.
transportRequest.timeout = 300;
if ((transportRequest.formData && transportRequest.formData.length > 0) ||
request.operation() === operations_1.default.PNDownloadFileOperation) {
// Set file upload / download request delay.
transportRequest.timeout = this._configuration.getFileTimeout();
}
else {
if (request.operation() === operations_1.default.PNSubscribeOperation)
Expand Down
2 changes: 1 addition & 1 deletion lib/transport/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class PubNubMiddleware {
req.queryParameters = {};
// Modify request with required information.
if (clientConfiguration.useInstanceId)
req.queryParameters['instanceid'] = clientConfiguration.instanceId;
req.queryParameters['instanceid'] = clientConfiguration.getInstanceId();
if (!req.queryParameters['uuid'])
req.queryParameters['uuid'] = clientConfiguration.userId;
if (clientConfiguration.useRequestId)
Expand Down
9 changes: 9 additions & 0 deletions lib/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2497,6 +2497,15 @@ declare namespace PubNub {
* @default `310` seconds
*/
subscribeRequestTimeout?: number;
/**
* File upload / download request timeout in milliseconds.
*
* Maximum duration for which PubNub client should wait for file upload / download request
* completion.
*
* @default `300` seconds
*/
fileRequestTimeout?: number;
/**
* `true` to allow catch up on the front-end applications.
*
Expand Down
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.4.1",
"version": "8.5.0",
"author": "PubNub <[email protected]>",
"description": "Publish & Subscribe Real-time Messaging with PubNub",
"scripts": {
Expand Down
9 changes: 8 additions & 1 deletion src/core/components/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ export const makeConfiguration = (
if (this.useInstanceId) return this._instanceId;
return undefined;
},
getInstanceId(): string | undefined {
if (this.useInstanceId) return this._instanceId;
return undefined;
},
getUserId() {
return this.userId!;
},
Expand Down Expand Up @@ -167,11 +171,14 @@ export const makeConfiguration = (
getSubscribeTimeout(): number {
return this.subscribeRequestTimeout!;
},
getFileTimeout(): number {
return this.fileRequestTimeout!;
},
get PubNubFile(): PubNubFileConstructor<PubNubFileInterface, unknown> | undefined {
return base.PubNubFile;
},
get version(): string {
return '8.4.1';
return '8.5.0';
},
getVersion(): string {
return this.version;
Expand Down
31 changes: 31 additions & 0 deletions src/core/interfaces/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ const TRANSACTIONAL_REQUEST_TIMEOUT = 15;
*/
const SUBSCRIBE_REQUEST_TIMEOUT = 310;

/**
* File upload / download request timeout.
*/
const FILE_REQUEST_TIMEOUT = 300;

/**
* Default user presence timeout.
*/
Expand Down Expand Up @@ -218,6 +223,16 @@ export type UserConfiguration = {
*/
subscribeRequestTimeout?: number;

/**
* File upload / download request timeout in milliseconds.
*
* Maximum duration for which PubNub client should wait for file upload / download request
* completion.
*
* @default `300` seconds
*/
fileRequestTimeout?: number;

/**
* `true` to allow catch up on the front-end applications.
*
Expand Down Expand Up @@ -617,6 +632,14 @@ export interface PrivateClientConfiguration
*/
getSubscribeTimeout(): number;

/**
* File requests timeout.
*
* @returns Maximum duration in milliseconds for which PubNub client should wait for
* file upload / download request completion.
*/
getFileTimeout(): number;

/**
* PubNub file object constructor.
*/
Expand All @@ -629,6 +652,13 @@ export interface PrivateClientConfiguration
*/
get instanceId(): string | undefined;

/**
* Get PubNub client instance identifier.
*
* @returns Current PubNub client instance identifier.
*/
getInstanceId(): string | undefined;

/**
* Get SDK family identifier.
*
Expand Down Expand Up @@ -698,6 +728,7 @@ export const setDefaults = (configuration: UserConfiguration): ExtendedConfigura
configurationCopy.ssl ??= USE_SSL;
configurationCopy.transactionalRequestTimeout ??= TRANSACTIONAL_REQUEST_TIMEOUT;
configurationCopy.subscribeRequestTimeout ??= SUBSCRIBE_REQUEST_TIMEOUT;
configurationCopy.fileRequestTimeout ??= FILE_REQUEST_TIMEOUT;
configurationCopy.restore ??= RESTORE;
configurationCopy.useInstanceId ??= USE_INSTANCE_ID;
configurationCopy.suppressLeaveEvents ??= SUPPRESS_LEAVE_EVENTS;
Expand Down
Loading

0 comments on commit 875e44b

Please sign in to comment.