method IWebSocketService.peek
Since 0.4.0
IWebSocketService.peek(name: string): WebSocketRoom | undefined

Returns the named room if one already exists, without creating it.

The non-allocating counterpart to IWebSocketService.room. A presence or dashboard endpoint that reports size for a name taken from a request must use this: room(name) registers one room per distinct name polled, and a room nobody has joined is reclaimed only when some other connection disconnects — so an idle application never reclaims them.

Examples

Example 1

const present = ws.peek(`board:${boardId}`)?.size ?? 0;

Parameters

name: string

Room name

Return Type

WebSocketRoom | undefined

The room, or undefined when no room of that name exists

Usage

import { type IWebSocketService } from "common/src/index.ts";