API reference / @chanx-js/server / core / TopicOptions
Interface: TopicOptions<Pattern, User, State>
Defined in: packages/server/src/topic.ts:62
Options for topic().
Extends
ErrorHooks<TopicContext<Pattern,User,Message,State>>
Type Parameters
| Type Parameter | Default type |
|---|---|
Pattern extends string | - |
User | - |
State | Record<never, never> |
Properties
authorize?
optional authorize?: (subscription) => boolean | Promise<boolean>;Defined in: packages/server/src/topic.ts:79
Decide whether this connection may subscribe.
Parameters
| Parameter | Type |
|---|---|
subscription | { conn: Connection<string, User>; params: PathParams<Pattern>; state: State; topic: string; } |
subscription.conn | Connection<string, User> |
subscription.params | PathParams<Pattern> |
subscription.state | State |
subscription.topic | string |
Returns
boolean | Promise<boolean>
description?
optional description?: string;Defined in: packages/server/src/topic.ts:73
The AsyncAPI channel's description.
layer?
optional layer?: string;Defined in: packages/server/src/topic.ts:75
The channel layer to publish on. Defaults to default.
name?
optional name?: string;Defined in: packages/server/src/topic.ts:71
Name of the topic's channel layer group namespace: two servers sharing a layer must agree on it. Defaults to RoomTopic for room:{...}.
onEventError?
optional onEventError?: (error, event, ctx) => void | Promise<void>;Defined in: packages/server/src/consumer.ts:172
An event handler threw. Default: log it; the client is told nothing.
Parameters
| Parameter | Type |
|---|---|
error | unknown |
event | Message |
ctx | TopicContext |
Returns
void | Promise<void>
Inherited from
onHandlerError?
optional onHandlerError?: (error, message, ctx) => void | Promise<void>;Defined in: packages/server/src/consumer.ts:170
A message handler threw. Default: log it, and an error frame naming the action.
Parameters
| Parameter | Type |
|---|---|
error | unknown |
message | Message |
ctx | TopicContext |
Returns
void | Promise<void>
Inherited from
onSubscribe?
optional onSubscribe?: (ctx) => void | Promise<void>;Defined in: packages/server/src/topic.ts:86
Once subscribed; what it sends is state, not a reply, so it carries no ref.
Parameters
| Parameter | Type |
|---|---|
ctx | TopicContext<Pattern, User, Message<string, unknown>, State> |
Returns
void | Promise<void>
onUnsubscribe?
optional onUnsubscribe?: (ctx) => void | Promise<void>;Defined in: packages/server/src/topic.ts:90
Before leaving, on unsubscribe and on disconnect.
Parameters
| Parameter | Type |
|---|---|
ctx | TopicContext<Pattern, User, Message<string, unknown>, State> |
Returns
void | Promise<void>
onValidationError?
optional onValidationError?: (issues, ctx) => void | Promise<void>;Defined in: packages/server/src/consumer.ts:168
A frame failed validation. Default: an error frame listing the issues.
Parameters
| Parameter | Type |
|---|---|
issues | ValidationIssue[] |
ctx | TopicContext |
Returns
void | Promise<void>
Inherited from
state?
optional state?: (subscription) => State;Defined in: packages/server/src/topic.ts:77
Per-subscription state, available as ctx.state; built before authorize.
Parameters
| Parameter | Type |
|---|---|
subscription | Subscription<User> |
Returns
State