Skip to content

socketContract

function socketContract<T extends Record<string, WebSocketDescriptor>>(descriptor: T): TypedContract<"ws", T>

Defines a typed WebSocket contract - the "ws" kind of the generic contract core, the WS sibling of httpContract. A descriptor map keyed by route name, each value a WebSocketDescriptor. Attach an entry to a route via host.ws.route(path, { contract: MySocket.chat }), or spell the descriptor fields loose in the options instead.

descriptor T

returns TypedContract<"ws", T>

Example:

const Chat = socketContract({
chat: { incoming: MsgIn, outgoing: MsgOut, params: { room: str } },
});

Learn: Contracts

Last updated: