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 Parameter | Default type |
|---|---|
Pattern extends string | - |
User | - |
Emits extends Message | - |
State | unknown |
Properties
conn
readonly conn: Connection<string, User>;Defined in: packages/server/src/topic.ts:28
params
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
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
readonly signal: AbortSignal;Defined in: packages/server/src/topic.ts:38
Aborts when the connection closes, so long-running work can stop.
state
readonly state: State;Defined in: packages/server/src/topic.ts:34
This subscription's state, from the state option.
topic
readonly topic: string;Defined in: packages/server/src/topic.ts:32
The topic string, such as room:lobby.
Methods
publish()
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
| Parameter | Type |
|---|---|
event | Message |
options? | PublishOptions |
Returns
Promise<void>
push()
push(message): Promise<void>;Defined in: packages/server/src/topic.ts:42
Send on this topic as a server push, without a ref.
Parameters
| Parameter | Type |
|---|---|
message | Emits |
Returns
Promise<void>
send()
send(message): Promise<void>;Defined in: packages/server/src/topic.ts:40
Send on this topic, stamped with the frame's ref.
Parameters
| Parameter | Type |
|---|---|
message | Emits |
Returns
Promise<void>