API reference / @chanx-js/server / core / ConsumerOptions
Interface: ConsumerOptions<Path, State, User, Emits>
Defined in: packages/server/src/consumer.ts:119
Options for consumer().
Extends
ErrorHooks<Context<Path,State,User,MessageOf<Emits>>>
Type Parameters
| Type Parameter |
|---|
Path extends string |
State |
User |
Emits extends AnyMessageDefinition |
Properties
authenticate?
optional authenticate?: (request) =>
| false
| User
| Promise<false | User | null | undefined>
| null
| undefined;Defined in: packages/server/src/consumer.ts:146
Runs after the socket is accepted. Return the user, or false (or throw an AuthenticationError) to reject; the client gets an authentication message either way. request is the connection it authenticates, the same object as ctx.conn later.
Parameters
| Parameter | Type |
|---|---|
request | ConnectRequest<Path> |
Returns
| false | User | Promise<false | User | null | undefined> | null | undefined
credentials?
optional credentials?: readonly Credential[];Defined in: packages/server/src/consumer.ts:156
Where authenticate reads credentials, documented as AsyncAPI security schemes.
description?
optional description?: string;Defined in: packages/server/src/consumer.ts:128
The AsyncAPI channel's description.
emits?
optional emits?: readonly Emits[];Defined in: packages/server/src/consumer.ts:132
Messages pushed through ctx rather than returned by a handler.
groups?
optional groups?: readonly string[] | ((conn) => readonly string[]);Defined in: packages/server/src/consumer.ts:138
Groups to join once connected.
layer?
optional layer?: string;Defined in: packages/server/src/consumer.ts:136
The channel layer to use, by its name in createChanx({ layers }). Defaults to default.
name
name: string;Defined in: packages/server/src/consumer.ts:126
The AsyncAPI channel name, also naming the consumer in errors.
onConnect?
optional onConnect?: (ctx) => void | Promise<void>;Defined in: packages/server/src/consumer.ts:158
Runs once authenticated and the groups are joined.
Parameters
| Parameter | Type |
|---|---|
ctx | Context<Path, State, User, MessageOf<Emits>> |
Returns
void | Promise<void>
onDisconnect?
optional onDisconnect?: (ctx) => void | Promise<void>;Defined in: packages/server/src/consumer.ts:160
Runs when the socket closes, before the groups are left.
Parameters
| Parameter | Type |
|---|---|
ctx | Context<Path, State, User, MessageOf<Emits>> |
Returns
void | Promise<void>
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 | Context |
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 | Context |
Returns
void | Promise<void>
Inherited from
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 | Context |
Returns
void | Promise<void>
Inherited from
rejectBeforeUpgrade?
optional rejectBeforeUpgrade?: boolean;Defined in: packages/server/src/consumer.ts:154
Run authenticate before accepting the socket, and refuse it with an HTTP status instead of an authentication message: for server-to-server clients, or to hold no socket for anonymous traffic. A browser cannot read why its upgrade failed.
state?
optional state?: (conn) => State;Defined in: packages/server/src/consumer.ts:140
Per-connection state, available as ctx.state.
Parameters
| Parameter | Type |
|---|---|
conn | Connection<Path, User> |
Returns
State
tags?
optional tags?: string[];Defined in: packages/server/src/consumer.ts:130
Tags on the AsyncAPI channel.
topics?
optional topics?: readonly TopicLike[];Defined in: packages/server/src/consumer.ts:134
Topics clients can subscribe to on this connection: topic() builders or Topic classes.