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

Support channel from Publication (can differ in case of wildcard subscriptions) #294

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion src/centrifuge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1699,8 +1699,12 @@ export class Centrifuge extends (EventEmitter as new () => TypedEventEmitter<Cli
private _getPublicationContext(channel: string, pub: any) {
const ctx: any = {
channel: channel,
data: pub.data
data: pub.data,
publicationChannel: channel
};
if (pub.channel) {
ctx.publicationChannel = pub.channel;
}
if (pub.offset) {
ctx.offset = pub.offset;
}
Expand Down
4 changes: 4 additions & 0 deletions src/client.proto.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@
"time": {
"type": "int64",
"id": 9
},
"channel": {
"type": "string",
"id": 10
}
},
"reserved": [
Expand Down
12 changes: 11 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ export interface PublicationContext {
offset?: number;
// tags is an extra key-value attached to publication, tags may be set when calling server publish API.
tags?: Record<string, string>;
// publicationChannel may be used to find out the real channel of publication, in most cases it
// matches channel field, but when wildcard subscriptions are used it may be different and contain
// a channel to which publication was published, thus differ from channel field (which is always a
// channel to which client subscribed to).
publicationChannel: string;
}

export interface ClientInfo {
Expand Down Expand Up @@ -260,7 +265,7 @@ export interface UnsubscribedContext {
}

export interface ServerPublicationContext {
// channel from which publication was received.
// subscription channel from which publication was received.
channel: string;
// data contains publication payload.
data: any;
Expand All @@ -273,6 +278,11 @@ export interface ServerPublicationContext {
offset?: number;
// tags is an extra key-value attached to publication, tags may be set when calling server publish API.
tags?: Record<string, string>;
// publicationChannel may be used to find out the real channel of publication, in most cases it
// matches channel field, but when wildcard subscriptions are used it may be different and contain
// a channel to which publication was published, thus differ from channel field (which is always a
// channel to which client subscribed to).
publicationChannel: string;
}

export interface ServerJoinContext {
Expand Down