Context
This documents the old v1 API. See Middleware for the current version.
Context (ctx) persists for the lifetime of a WebSocket connection.
Creating Context
Section titled “Creating Context”const zo = zocket.create({ headers: z.object({ authorization: z.string().optional(), }), onConnect: async (headers, clientId) => { const user = headers.authorization ? await verifyToken(headers.authorization) : null; return { user, connectedAt: new Date() }; },});Built-in Context
Section titled “Built-in Context”| Property | Type | Description |
|---|---|---|
clientId | string | Unique identifier for the connection |
rooms | RoomOperations | Helper to join/leave rooms |
Rooms API
Section titled “Rooms API”join(roomId)— Add the connection to a roomleave(roomId)— Remove from a roomhas(roomId)— Check membershipcurrent—ReadonlySet<string>of joined rooms