Skip to content
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

Fix subscribe request aggregation in SharedWorker. #403

Merged
merged 6 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 7 additions & 1 deletion dist/web/pubnub.js
Original file line number Diff line number Diff line change
Expand Up @@ -5868,7 +5868,13 @@
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 && this.parameters.channels.includes(subscribable)) ||
(this.parameters.channelGroups && 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.

274 changes: 233 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.

8 changes: 7 additions & 1 deletion lib/core/endpoints/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,13 @@ 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 && this.parameters.channels.includes(subscribable)) ||
(this.parameters.channelGroups && 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
88 changes: 48 additions & 40 deletions src/core/endpoints/subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,57 +629,65 @@ 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;
mohitpubnub marked this conversation as resolved.
Show resolved Hide resolved
return (
(this.parameters.channels && this.parameters.channels.includes(subscribable)) ||
(this.parameters.channelGroups && 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
Loading