Skip to content

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

Interface: TopicContext<Pattern, User, Emits, State> ​

Defined in: packages/server/src/topic.ts:22

What a topic's handlers and hooks get as ctx.

Type Parameters ​

Type ParameterDefault type
Pattern extends string-
User-
Emits extends Message-
Stateunknown

Properties ​

conn ​

ts
readonly conn: Connection<string, User>;

Defined in: packages/server/src/topic.ts:28


params ​

ts
readonly params: PathParams<Pattern>;

Defined in: packages/server/src/topic.ts:30

Params parsed from the topic: room:{room_name} subscribed as room:lobby gives lobby.


ref ​

ts
readonly ref: string | undefined;

Defined in: packages/server/src/topic.ts:36

The ref of the frame being handled; absent in lifecycle hooks and events.


signal ​

ts
readonly signal: AbortSignal;

Defined in: packages/server/src/topic.ts:38

Aborts when the connection closes, so long-running work can stop.


state ​

ts
readonly state: State;

Defined in: packages/server/src/topic.ts:34

This subscription's state, from the state option.


topic ​

ts
readonly topic: string;

Defined in: packages/server/src/topic.ts:32

The topic string, such as room:lobby.

Methods ​

publish() ​

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

Defined in: packages/server/src/topic.ts:44

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/topic.ts:42

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

Parameters ​

ParameterType
messageEmits

Returns ​

Promise<void>


send() ​

ts
send(message): Promise<void>;

Defined in: packages/server/src/topic.ts:40

Send on this topic, stamped with the frame's ref.

Parameters ​

ParameterType
messageEmits

Returns ​

Promise<void>

MIT licensed