Skip to content

API reference / @chanx-js/server / core / Topic

Abstract Class: Topic<User> ​

Defined in: packages/server/src/classes.ts:281

Base class for topics written as classes: set static pattern; the class name names its layer group. One instance serves one subscription.

Type Parameters ​

Type ParameterDefault type
Userunknown

Constructors ​

Constructor ​

ts
new Topic<User>(subscription): Topic<User>;

Defined in: packages/server/src/classes.ts:291

Parameters ​

ParameterType
subscriptionSubscription<User>

Returns ​

Topic<User>

Properties ​

subscription ​

ts
protected readonly subscription: Subscription<User>;

Defined in: packages/server/src/classes.ts:291


description? ​

ts
static optional description?: string;

Defined in: packages/server/src/classes.ts:285

The AsyncAPI channel's description.


layer? ​

ts
static optional layer?: string;

Defined in: packages/server/src/classes.ts:287

The channel layer to publish on. Defaults to default.


passthrough? ​

ts
static optional passthrough?: readonly AnyMessageDefinition[];

Defined in: packages/server/src/classes.ts:289

Events forwarded to the client unchanged.


pattern ​

ts
static pattern: string;

Defined in: packages/server/src/classes.ts:283

The topic pattern, such as room:{room_name}.

Accessors ​

conn ​

Get Signature ​

ts
get conn(): Connection<string, User>;

Defined in: packages/server/src/classes.ts:293

Returns ​

Connection<string, User>


params ​

Get Signature ​

ts
get params(): Readonly<Record<string, string>>;

Defined in: packages/server/src/classes.ts:297

Returns ​

Readonly<Record<string, string>>


topic ​

Get Signature ​

ts
get topic(): string;

Defined in: packages/server/src/classes.ts:301

Returns ​

string

Methods ​

authorize() ​

ts
authorize(): boolean | Promise<boolean>;

Defined in: packages/server/src/classes.ts:316

Decide whether this connection may subscribe.

Returns ​

boolean | Promise<boolean>


onEventError()? ​

ts
optional onEventError(
   error, 
   event, 
   ctx
): void | Promise<void>;

Defined in: packages/server/src/classes.ts:338

Override to change how a failing event handler is reported.

Parameters ​

ParameterType
errorunknown
eventMessage
ctxTopicClassContext

Returns ​

void | Promise<void>


onHandlerError()? ​

ts
optional onHandlerError(
   error, 
   message, 
   ctx
): void | Promise<void>;

Defined in: packages/server/src/classes.ts:332

Override to change how a failing message handler is reported.

Parameters ​

ParameterType
errorunknown
messageMessage
ctxTopicClassContext

Returns ​

void | Promise<void>


onSubscribe() ​

ts
onSubscribe(): void | Promise<void>;

Defined in: packages/server/src/classes.ts:321

Once subscribed; what it sends is state, not a reply.

Returns ​

void | Promise<void>


onUnsubscribe() ​

ts
onUnsubscribe(): void | Promise<void>;

Defined in: packages/server/src/classes.ts:324

Before leaving, on unsubscribe and on disconnect.

Returns ​

void | Promise<void>


onValidationError()? ​

ts
optional onValidationError(issues, ctx): void | Promise<void>;

Defined in: packages/server/src/classes.ts:327

Override to change how a frame that failed validation is answered.

Parameters ​

ParameterType
issuesValidationIssue[]
ctxTopicClassContext

Returns ​

void | Promise<void>


publish() ​

ts
publish(event, options?): Promise<void>;

Defined in: packages/server/src/classes.ts:311

Publish an event to everyone subscribed to this topic, across processes.

Parameters ​

ParameterType
eventMessage
options?PublishOptions

Returns ​

Promise<void>


push() ​

ts
push(message): Promise<void>;

Defined in: packages/server/src/classes.ts:306

Send on this topic as a server push, without a ref.

Parameters ​

ParameterType
messageMessage

Returns ​

Promise<void>

MIT licensed