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: App context event handling for channel and membership #362

Merged
merged 8 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
23 changes: 12 additions & 11 deletions dist/web/pubnub.js
Original file line number Diff line number Diff line change
Expand Up @@ -6533,7 +6533,7 @@
var messages = [];
serverResponse.m.forEach(function (rawMessage) {
var publishMetaData = {
publishTimetoken: rawMessage.p.t,
timetoken: rawMessage.p.t,
region: rawMessage.p.r,
};
var parsedMessage = {
Expand Down Expand Up @@ -6659,6 +6659,7 @@
issuingClientId: envelope.i,
subscribeKey: envelope.k,
originationTimetoken: envelope.o,
userMetadata: envelope.u,
publishMetaData: {
timetoken: envelope.p.t,
region: envelope.p.r,
Expand Down Expand Up @@ -7640,10 +7641,10 @@
}
};
EventEngine.prototype.getSubscribedChannels = function () {
return this.channels.slice(0);
return Array.from(new Set(this.channels));
};
EventEngine.prototype.getSubscribedChannelGroups = function () {
return this.groups.slice(0);
return Array.from(new Set(this.groups));
};
EventEngine.prototype.dispose = function () {
this.disconnect();
Expand Down Expand Up @@ -8107,7 +8108,7 @@
}
announce.action = e.payload.action;
announce.state = e.payload.data;
announce.timetoken = publishMetaData.publishTimetoken;
announce.timetoken = publishMetaData.timetoken;
announce.occupancy = e.payload.occupancy;
announce.uuid = e.payload.uuid;
announce.timestamp = e.payload.timestamp;
Expand All @@ -8133,7 +8134,7 @@
announce.subscription = null;
announce.channel = channel;
announce.subscription = subscriptionMatch;
announce.timetoken = publishMetaData.publishTimetoken;
announce.timetoken = publishMetaData.timetoken;
announce.publisher = e.issuingClientId;
if (e.userMetadata) {
announce.userMetadata = e.userMetadata;
Expand All @@ -8148,7 +8149,7 @@
announce.subscription = null;
announce.channel = channel;
announce.subscription = subscriptionMatch;
announce.timetoken = publishMetaData.publishTimetoken;
announce.timetoken = publishMetaData.timetoken;
announce.publisher = e.issuingClientId;
if (e.userMetadata) {
announce.userMetadata = e.userMetadata;
Expand All @@ -8166,13 +8167,13 @@
this.listenerManager.announceUser(userEvent);
this._announce('user', userEvent, announce.channel, announce.subscription);
}
else if (message.payload.type === 'channel') {
else if (e.payload.type === 'channel') {
var eventData = this._renameChannelField(announce);
var spaceEvent = __assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'space' }) });
this.listenerManager.announceSpace(spaceEvent);
this._announce('space', spaceEvent, announce.channel, announce.subscription);
}
else if (message.payload.type === 'membership') {
else if (e.payload.type === 'membership') {
var eventData = this._renameChannelField(announce);
var _a = eventData.message.data, user = _a.uuid, space = _a.channel, membershipData = __rest(_a, ["uuid", "channel"]);
membershipData.user = user;
Expand All @@ -8186,7 +8187,7 @@
var announce = {};
announce.channel = channel;
announce.subscription = subscriptionMatch;
announce.timetoken = publishMetaData.publishTimetoken;
announce.timetoken = publishMetaData.timetoken;
announce.publisher = e.issuingClientId;
announce.data = {
messageTimetoken: e.payload.data.messageTimetoken,
Expand All @@ -8203,7 +8204,7 @@
var announce = {};
announce.channel = channel;
announce.subscription = subscriptionMatch;
announce.timetoken = publishMetaData.publishTimetoken;
announce.timetoken = publishMetaData.timetoken;
announce.publisher = e.issuingClientId;
var msgPayload = e.payload;
if (this.modules.cryptoModule) {
Expand Down Expand Up @@ -8243,7 +8244,7 @@
announce.subscription = null;
announce.channel = channel;
announce.subscription = subscriptionMatch;
announce.timetoken = publishMetaData.publishTimetoken;
announce.timetoken = publishMetaData.timetoken;
announce.publisher = e.issuingClientId;
if (e.userMetadata) {
announce.userMetadata = e.userMetadata;
Expand Down
2 changes: 1 addition & 1 deletion dist/web/pubnub.min.js

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions lib/core/components/eventEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var EventEmitter = /** @class */ (function () {
}
announce.action = e.payload.action;
announce.state = e.payload.data;
announce.timetoken = publishMetaData.publishTimetoken;
announce.timetoken = publishMetaData.timetoken;
announce.occupancy = e.payload.occupancy;
announce.uuid = e.payload.uuid;
announce.timestamp = e.payload.timestamp;
Expand All @@ -77,7 +77,7 @@ var EventEmitter = /** @class */ (function () {
announce.subscription = null;
announce.channel = channel;
announce.subscription = subscriptionMatch;
announce.timetoken = publishMetaData.publishTimetoken;
announce.timetoken = publishMetaData.timetoken;
announce.publisher = e.issuingClientId;
if (e.userMetadata) {
announce.userMetadata = e.userMetadata;
Expand All @@ -92,7 +92,7 @@ var EventEmitter = /** @class */ (function () {
announce.subscription = null;
announce.channel = channel;
announce.subscription = subscriptionMatch;
announce.timetoken = publishMetaData.publishTimetoken;
announce.timetoken = publishMetaData.timetoken;
announce.publisher = e.issuingClientId;
if (e.userMetadata) {
announce.userMetadata = e.userMetadata;
Expand All @@ -110,13 +110,13 @@ var EventEmitter = /** @class */ (function () {
this.listenerManager.announceUser(userEvent);
this._announce('user', userEvent, announce.channel, announce.subscription);
}
else if (message.payload.type === 'channel') {
else if (e.payload.type === 'channel') {
var eventData = this._renameChannelField(announce);
var spaceEvent = __assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'space' }) });
this.listenerManager.announceSpace(spaceEvent);
this._announce('space', spaceEvent, announce.channel, announce.subscription);
}
else if (message.payload.type === 'membership') {
else if (e.payload.type === 'membership') {
var eventData = this._renameChannelField(announce);
var _a = eventData.message.data, user = _a.uuid, space = _a.channel, membershipData = __rest(_a, ["uuid", "channel"]);
membershipData.user = user;
Expand All @@ -130,7 +130,7 @@ var EventEmitter = /** @class */ (function () {
var announce = {};
announce.channel = channel;
announce.subscription = subscriptionMatch;
announce.timetoken = publishMetaData.publishTimetoken;
announce.timetoken = publishMetaData.timetoken;
announce.publisher = e.issuingClientId;
announce.data = {
messageTimetoken: e.payload.data.messageTimetoken,
Expand All @@ -147,7 +147,7 @@ var EventEmitter = /** @class */ (function () {
var announce = {};
announce.channel = channel;
announce.subscription = subscriptionMatch;
announce.timetoken = publishMetaData.publishTimetoken;
announce.timetoken = publishMetaData.timetoken;
announce.publisher = e.issuingClientId;
var msgPayload = e.payload;
if (this.modules.cryptoModule) {
Expand Down Expand Up @@ -187,7 +187,7 @@ var EventEmitter = /** @class */ (function () {
announce.subscription = null;
announce.channel = channel;
announce.subscription = subscriptionMatch;
announce.timetoken = publishMetaData.publishTimetoken;
announce.timetoken = publishMetaData.timetoken;
announce.publisher = e.issuingClientId;
if (e.userMetadata) {
announce.userMetadata = e.userMetadata;
Expand Down
2 changes: 1 addition & 1 deletion lib/core/endpoints/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function handleResponse(modules, serverResponse) {
var messages = [];
serverResponse.m.forEach(function (rawMessage) {
var publishMetaData = {
publishTimetoken: rawMessage.p.t,
timetoken: rawMessage.p.t,
region: rawMessage.p.r,
};
var parsedMessage = {
Expand Down
1 change: 1 addition & 0 deletions lib/core/endpoints/subscriptionUtils/receiveMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var endpoint = {
issuingClientId: envelope.i,
subscribeKey: envelope.k,
originationTimetoken: envelope.o,
userMetadata: envelope.u,
publishMetaData: {
timetoken: envelope.p.t,
region: envelope.p.r,
Expand Down
4 changes: 2 additions & 2 deletions lib/event-engine/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ var EventEngine = /** @class */ (function () {
}
};
EventEngine.prototype.getSubscribedChannels = function () {
return this.channels.slice(0);
return Array.from(new Set(this.channels));
};
EventEngine.prototype.getSubscribedChannelGroups = function () {
return this.groups.slice(0);
return Array.from(new Set(this.groups));
};
EventEngine.prototype.dispose = function () {
this.disconnect();
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions src/core/components/eventEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class EventEmitter {

announce.action = e.payload.action;
announce.state = e.payload.data;
announce.timetoken = publishMetaData.publishTimetoken;
announce.timetoken = publishMetaData.timetoken;
announce.occupancy = e.payload.occupancy;
announce.uuid = e.payload.uuid;
announce.timestamp = e.payload.timestamp;
Expand Down Expand Up @@ -66,7 +66,7 @@ export default class EventEmitter {

announce.channel = channel;
announce.subscription = subscriptionMatch;
announce.timetoken = publishMetaData.publishTimetoken;
announce.timetoken = publishMetaData.timetoken;
announce.publisher = e.issuingClientId;
if (e.userMetadata) {
announce.userMetadata = e.userMetadata;
Expand All @@ -82,7 +82,7 @@ export default class EventEmitter {
announce.subscription = null;
announce.channel = channel;
announce.subscription = subscriptionMatch;
announce.timetoken = publishMetaData.publishTimetoken;
announce.timetoken = publishMetaData.timetoken;
announce.publisher = e.issuingClientId;
if (e.userMetadata) {
announce.userMetadata = e.userMetadata;
Expand All @@ -106,7 +106,7 @@ export default class EventEmitter {
};
this.listenerManager.announceUser(userEvent);
this._announce('user', userEvent, announce.channel, announce.subscription);
} else if (message.payload.type === 'channel') {
} else if (e.payload.type === 'channel') {
const eventData = this._renameChannelField(announce);
const spaceEvent = {
...eventData,
Expand All @@ -118,7 +118,7 @@ export default class EventEmitter {
};
this.listenerManager.announceSpace(spaceEvent);
this._announce('space', spaceEvent, announce.channel, announce.subscription);
} else if (message.payload.type === 'membership') {
} else if (e.payload.type === 'membership') {
const eventData = this._renameChannelField(announce);
const { uuid: user, channel: space, ...membershipData } = eventData.message.data;
membershipData.user = user;
Expand All @@ -138,7 +138,7 @@ export default class EventEmitter {
const announce = {};
announce.channel = channel;
announce.subscription = subscriptionMatch;
announce.timetoken = publishMetaData.publishTimetoken;
announce.timetoken = publishMetaData.timetoken;
announce.publisher = e.issuingClientId;
announce.data = {
messageTimetoken: e.payload.data.messageTimetoken,
Expand All @@ -154,7 +154,7 @@ export default class EventEmitter {
const announce = {};
announce.channel = channel;
announce.subscription = subscriptionMatch;
announce.timetoken = publishMetaData.publishTimetoken;
announce.timetoken = publishMetaData.timetoken;
announce.publisher = e.issuingClientId;

let msgPayload = e.payload;
Expand Down Expand Up @@ -199,7 +199,7 @@ export default class EventEmitter {

announce.channel = channel;
announce.subscription = subscriptionMatch;
announce.timetoken = publishMetaData.publishTimetoken;
announce.timetoken = publishMetaData.timetoken;
announce.publisher = e.issuingClientId;

if (e.userMetadata) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/endpoints/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function handleResponse(modules, serverResponse) {

serverResponse.m.forEach((rawMessage) => {
const publishMetaData = {
publishTimetoken: rawMessage.p.t,
timetoken: rawMessage.p.t,
region: rawMessage.p.r,
};
const parsedMessage = {
Expand Down
1 change: 1 addition & 0 deletions src/core/endpoints/subscriptionUtils/receiveMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const endpoint = {
issuingClientId: envelope.i,
subscribeKey: envelope.k,
originationTimetoken: envelope.o,
userMetadata: envelope.u,
publishMetaData: {
timetoken: envelope.p.t,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to rename field? It is alsready inside of publishMetaData and it doesn't look like that we need to clarify once again that it is publishTimetoken. Is there other reason for it?

Copy link
Contributor Author

@mohitpubnub mohitpubnub Feb 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was typo before.
In eventEmitter (the same code was there in subscriptionManager before) while creating event information object, this was the way we used to assign.

so instead of changing property name in all places (which may be error prone like we have now with channel/membership) I rename it here in subscription utility method.. same as older endpoint implementation here

in short, It's renaming to make is compatible with old implementation logic in event handling

Copy link
Contributor Author

@mohitpubnub mohitpubnub Feb 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be refactored other way around than as it's there!
For consistent naming, Renamed property name in old subscribe endpoint definition as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@parfeon refactored!

region: envelope.p.r,
Expand Down
4 changes: 2 additions & 2 deletions src/event-engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ export class EventEngine {
}

getSubscribedChannels(): string[] {
return this.channels.slice(0);
return Array.from(new Set(this.channels));
}

getSubscribedChannelGroups(): string[] {
return this.groups.slice(0);
return Array.from(new Set(this.groups));
}

dispose(): void {
Expand Down
Loading
Loading