Skip to content

Commit

Permalink
fix(shared-worker): fix presence leave request preparation
Browse files Browse the repository at this point in the history
Fix issue because of which leave request modified wrong URL path component with actual channels.

fix(shared-worker): fix channels / groups list modification issues

Fix issue because of which removed channels / groups didn't cancel previous subscribe request to
re-subscribe with new set of channels / groups.

fix(shared-worker): fix requests aggregation issues

Fix issue because of which suitable active PubNub clients subscription not has been used for
aggregation and caused additional connections or wrong set of channels / groups.

refactor(subscription): process messages only for subscribed

Pre-process entries from subscribe response to filter out updates which has been received for
channels and groups which are not part of subscription loop (subscription aggregation in shared
worker).

refactor(package): add `types` entry for Node.js integration

Point to the built-in types definition file when package used with npm / yarn.
  • Loading branch information
parfeon committed Sep 29, 2024
1 parent bc85e1d commit ecfddfb
Show file tree
Hide file tree
Showing 9 changed files with 592 additions and 137 deletions.
7 changes: 6 additions & 1 deletion dist/web/pubnub.js
Original file line number Diff line number Diff line change
Expand Up @@ -5868,7 +5868,12 @@
if (!serviceResponse) {
throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response'));
}
const events = serviceResponse.m.map((envelope) => {
const events = serviceResponse.m
.filter((envelope) => {
const subscribable = envelope.b === undefined ? envelope.c : envelope.b;
return (this.parameters.channels.includes(subscribable) || this.parameters.channelGroups.includes(subscribable));
})
.map((envelope) => {
let { e: eventType } = envelope;
// Resolve missing event type.
eventType !== null && eventType !== void 0 ? eventType : (eventType = envelope.c.endsWith('-pnpres') ? PubNubEventType.Presence : PubNubEventType.Message);
Expand Down
2 changes: 1 addition & 1 deletion dist/web/pubnub.min.js

Large diffs are not rendered by default.

270 changes: 229 additions & 41 deletions dist/web/pubnub.worker.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/web/pubnub.worker.min.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion lib/core/endpoints/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ class BaseSubscribeRequest extends request_1.AbstractRequest {
if (!serviceResponse) {
throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response'));
}
const events = serviceResponse.m.map((envelope) => {
const events = serviceResponse.m
.filter((envelope) => {
const subscribable = envelope.b === undefined ? envelope.c : envelope.b;
return (this.parameters.channels.includes(subscribable) || this.parameters.channelGroups.includes(subscribable));
})
.map((envelope) => {
let { e: eventType } = envelope;
// Resolve missing event type.
eventType !== null && eventType !== void 0 ? eventType : (eventType = envelope.c.endsWith('-pnpres') ? PubNubEventType.Presence : PubNubEventType.Message);
Expand Down
31 changes: 16 additions & 15 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
Expand Up @@ -32,6 +32,7 @@
"contract:test-access-beta": "cucumber-js --require dist/cucumber dist/contract/contract/features --tags '@featureSet=access and not @na=js and @beta'"
},
"main": "./lib/node/index.js",
"types": "./lib/types/node/index.d.ts",
"react-native": "./lib/react_native/index.js",
"metro": "./lib/react_native/index.js",
"nativescript": "./lib/nativescript/index.js",
Expand All @@ -40,7 +41,6 @@
"type": "git",
"url": "git://github.com/pubnub/javascript.git"
},

"keywords": [
"cloud",
"publish",
Expand Down
87 changes: 47 additions & 40 deletions src/core/endpoints/subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,57 +629,64 @@ export class BaseSubscribeRequest extends AbstractRequest<Subscription.Subscript
);
}

const events: Subscription.SubscriptionResponse['messages'] = serviceResponse.m.map((envelope) => {
let { e: eventType } = envelope;
const events: Subscription.SubscriptionResponse['messages'] = serviceResponse.m
.filter((envelope) => {
const subscribable = envelope.b === undefined ? envelope.c : envelope.b;
return (
this.parameters.channels!.includes(subscribable) || this.parameters.channelGroups!.includes(subscribable)
);
})
.map((envelope) => {
let { e: eventType } = envelope;

// Resolve missing event type.
eventType ??= envelope.c.endsWith('-pnpres') ? PubNubEventType.Presence : PubNubEventType.Message;

// Check whether payload is string (potentially encrypted data).
if (eventType != PubNubEventType.Signal && typeof envelope.d === 'string') {
if (eventType == PubNubEventType.Message) {
return {
type: PubNubEventType.Message,
data: this.messageFromEnvelope(envelope),
};
}

// Resolve missing event type.
eventType ??= envelope.c.endsWith('-pnpres') ? PubNubEventType.Presence : PubNubEventType.Message;

// Check whether payload is string (potentially encrypted data).
if (eventType != PubNubEventType.Signal && typeof envelope.d === 'string') {
if (eventType == PubNubEventType.Message) {
return {
type: PubNubEventType.Files,
data: this.fileFromEnvelope(envelope),
};
} else if (eventType == PubNubEventType.Message) {
return {
type: PubNubEventType.Message,
data: this.messageFromEnvelope(envelope),
};
} else if (eventType === PubNubEventType.Presence) {
return {
type: PubNubEventType.Presence,
data: this.presenceEventFromEnvelope(envelope),
};
} else if (eventType == PubNubEventType.Signal) {
return {
type: PubNubEventType.Signal,
data: this.signalFromEnvelope(envelope),
};
} else if (eventType === PubNubEventType.AppContext) {
return {
type: PubNubEventType.AppContext,
data: this.appContextFromEnvelope(envelope),
};
} else if (eventType === PubNubEventType.MessageAction) {
return {
type: PubNubEventType.MessageAction,
data: this.messageActionFromEnvelope(envelope),
};
}

return {
type: PubNubEventType.Files,
data: this.fileFromEnvelope(envelope),
};
} else if (eventType == PubNubEventType.Message) {
return {
type: PubNubEventType.Message,
data: this.messageFromEnvelope(envelope),
};
} else if (eventType === PubNubEventType.Presence) {
return {
type: PubNubEventType.Presence,
data: this.presenceEventFromEnvelope(envelope),
};
} else if (eventType == PubNubEventType.Signal) {
return {
type: PubNubEventType.Signal,
data: this.signalFromEnvelope(envelope),
};
} else if (eventType === PubNubEventType.AppContext) {
return {
type: PubNubEventType.AppContext,
data: this.appContextFromEnvelope(envelope),
};
} else if (eventType === PubNubEventType.MessageAction) {
return {
type: PubNubEventType.MessageAction,
data: this.messageActionFromEnvelope(envelope),
};
}

return {
type: PubNubEventType.Files,
data: this.fileFromEnvelope(envelope),
};
});
});

return {
cursor: { timetoken: serviceResponse.t.t, region: serviceResponse.t.r },
Expand Down
Loading

0 comments on commit ecfddfb

Please sign in to comment.