Skip to content

Fix rapid subscribe aggregate #461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"parser" : "typescript",
"parser": "typescript",
"semi": true,
"printWidth": 120,
"singleQuote": true,
Expand Down
5,574 changes: 2,856 additions & 2,718 deletions dist/web/pubnub.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/web/pubnub.min.js

Large diffs are not rendered by default.

347 changes: 278 additions & 69 deletions dist/web/pubnub.worker.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/web/pubnub.worker.min.js

Large diffs are not rendered by default.

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.

9 changes: 9 additions & 0 deletions src/core/constants/categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ enum StatusCategory {
*/
PNMalformedResponseCategory = 'PNMalformedResponseCategory',

/**
* Server can't process request.
*
* There can be few sources of unexpected return with success code:
* - potentially an ongoing incident;
* - proxy server / VPN.
*/
PNServerErrorCategory = 'PNServerErrorCategory',

/**
* Something strange happened; please check the logs.
*/
Expand Down
41 changes: 30 additions & 11 deletions src/core/pubnub-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,27 @@ export class PubNubCore<
*/
protected readonly transport: Transport;

/**
* `userId` change handler.
*
* @internal
*/
protected onUserIdChange?: (userId: string) => void;

/**
* Heartbeat interval change handler.
*
* @internal
*/
protected onHeartbeatIntervalChange?: (interval: number) => void;

/**
* `authKey` or `token` change handler.
*
* @internal
*/
protected onAuthenticationChange?: (auth?: string) => void;

/**
* REST API endpoints access tokens manager.
*
Expand Down Expand Up @@ -676,6 +697,8 @@ export class PubNubCore<
setAuthKey(authKey: string): void {
this.logger.debug('PubNub', `Set auth key: ${authKey}`);
this._configuration.setAuthKey(authKey);

if (this.onAuthenticationChange) this.onAuthenticationChange(authKey);
}

/**
Expand Down Expand Up @@ -706,6 +729,8 @@ export class PubNubCore<

this.logger.debug('PubNub', `Set user ID: ${value}`);
this._configuration.userId = value;

if (this.onUserIdChange) this.onUserIdChange(this._configuration.userId);
}

/**
Expand All @@ -727,15 +752,7 @@ export class PubNubCore<
* @throws Error empty user identifier has been provided.
*/
setUserId(value: string): void {
if (!value || typeof value !== 'string' || value.trim().length === 0) {
const error = new Error('Missing or invalid userId parameter. Provide a valid string userId');
this.logger.error('PubNub', () => ({ messageType: 'error', message: error }));

throw error;
}

this.logger.debug('PubNub', `Set user ID: ${value}`);
this._configuration.userId = value;
this.userId = value;
}

/**
Expand Down Expand Up @@ -812,6 +829,8 @@ export class PubNubCore<
set heartbeatInterval(interval: number) {
this.logger.debug('PubNub', `Set heartbeat interval: ${interval}`);
this._configuration.setHeartbeatInterval(interval);

if (this.onHeartbeatIntervalChange) this.onHeartbeatIntervalChange(this._configuration.getHeartbeatInterval() ?? 0);
}

/**
Expand All @@ -820,7 +839,6 @@ export class PubNubCore<
* @param interval - New presence request heartbeat intervals.
*/
setHeartbeatInterval(interval: number): void {
this.logger.debug('PubNub', `Set heartbeat interval: ${interval}`);
this.heartbeatInterval = interval;
}

Expand Down Expand Up @@ -3016,6 +3034,7 @@ export class PubNubCore<
*/
public set token(token: string | undefined) {
if (this.tokenManager) this.tokenManager.setToken(token);
if (this.onAuthenticationChange) this.onAuthenticationChange(token);
}

/**
Expand Down Expand Up @@ -3269,7 +3288,7 @@ export class PubNubCore<
* configured PubNub client `uuid` if not set.
* @param callback - Request completion handler callback.
*
* @deprecated Use {@link PubNubCore#objects.getUUIDMetadata getUUIDMetadata} method instead.
* @deprecated Use {@link PubNubCore#objects.getUUIDMetadata|getUUIDMetadata} method instead.
*/
public fetchUser<Custom extends AppContext.CustomData = AppContext.CustomData>(
parameters: AppContext.GetUUIDMetadataParameters,
Expand Down
3 changes: 3 additions & 0 deletions src/errors/pubnub-api-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ export class PubNubAPIError extends Error {
} else if (status === 403) {
category = StatusCategory.PNAccessDeniedCategory;
message = 'Access denied';
} else if (status >= 500) {
category = StatusCategory.PNServerErrorCategory;
message = 'Internal server error';
}

if (typeof response === 'object' && Object.keys(response).length === 0) {
Expand Down
Loading