Skip to content

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 ​

Type Parameters ​

Type Parameter
Path extends string
State
User
Emits extends AnyMessageDefinition

Properties ​

authenticate? ​

ts
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 ​

ParameterType
requestConnectRequest<Path>

Returns ​

| false | User | Promise<false | User | null | undefined> | null | undefined


credentials? ​

ts
optional credentials?: readonly Credential[];

Defined in: packages/server/src/consumer.ts:156

Where authenticate reads credentials, documented as AsyncAPI security schemes.


description? ​

ts
optional description?: string;

Defined in: packages/server/src/consumer.ts:128

The AsyncAPI channel's description.


emits? ​

ts
optional emits?: readonly Emits[];

Defined in: packages/server/src/consumer.ts:132

Messages pushed through ctx rather than returned by a handler.


groups? ​

ts
optional groups?: readonly string[] | ((conn) => readonly string[]);

Defined in: packages/server/src/consumer.ts:138

Groups to join once connected.


layer? ​

ts
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 ​

ts
name: string;

Defined in: packages/server/src/consumer.ts:126

The AsyncAPI channel name, also naming the consumer in errors.


onConnect? ​

ts
optional onConnect?: (ctx) => void | Promise<void>;

Defined in: packages/server/src/consumer.ts:158

Runs once authenticated and the groups are joined.

Parameters ​

ParameterType
ctxContext<Path, State, User, MessageOf<Emits>>

Returns ​

void | Promise<void>


onDisconnect? ​

ts
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 ​

ParameterType
ctxContext<Path, State, User, MessageOf<Emits>>

Returns ​

void | Promise<void>


onEventError? ​

ts
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 ​

ParameterType
errorunknown
eventMessage
ctxContext

Returns ​

void | Promise<void>

Inherited from ​

ErrorHooks.onEventError


onHandlerError? ​

ts
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 ​

ParameterType
errorunknown
messageMessage
ctxContext

Returns ​

void | Promise<void>

Inherited from ​

ErrorHooks.onHandlerError


onValidationError? ​

ts
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 ​

ParameterType
issuesValidationIssue[]
ctxContext

Returns ​

void | Promise<void>

Inherited from ​

ErrorHooks.onValidationError


rejectBeforeUpgrade? ​

ts
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? ​

ts
optional state?: (conn) => State;

Defined in: packages/server/src/consumer.ts:140

Per-connection state, available as ctx.state.

Parameters ​

ParameterType
connConnection<Path, User>

Returns ​

State


tags? ​

ts
optional tags?: string[];

Defined in: packages/server/src/consumer.ts:130

Tags on the AsyncAPI channel.


topics? ​

ts
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.

MIT licensed