Skip to content

RoomHub

new RoomHub(opts): RoomHub

Partial<Limits>

boolean

() => number

(snap) => void | Promise<void>

(scope) => number | undefined

SavePort

string

RoomHub

readonly boot: string


readonly limits: Limits


readonly listRooms: boolean

the room list (rooms {}) is answered; off: the answer is {off: true}


loop: { max: number; p50: number; p99: number; } | null = null

event-loop delay from the host process (main.ts sets it once a minute)


loopRecent: { p99: number; } | null = null

the same over the last 10 s (main.ts), for the half-rate switch


readonly now: () => number

number


pending: number = 0


pressure: boolean = false

over the data cap or a late loop: bigger rooms at half rate, no new rooms

closeScope(scope, reason?): void

Close every room of one namespace (a public link stopped).

string

string = "this game is no longer shared"

void


connect(conn, addr): Session | { reason: string; refused: number; }

A new socket. Null = refused (the caller closes it with the code given).

Conn

string

Session | { reason: string; refused: number; }


drop(s): void

A socket is gone. Its seat stays (offline) for seatHoldMs, without host duty.

Session

void


exportRooms(): RoomsSnapshot

The live rooms as plain JSON: everything a new process needs to carry on (sockets, timers and open actions are not kept).

RoomsSnapshot


flushSaves(): Promise<void>

Write every changed profile and world now and wait until the store has taken them (a restart, a test).

Promise<void>


importRooms(snap, o?): number

Take back rooms from exportRooms() after a restart: every seat offline (held 60 s for its player to come back), no host until one is back, a new term, save leases taken again. A snapshot older than maxAgeMs or of another format is ignored. Returns how many rooms came back.

unknown

number

number


publicId(scope, seat): string

A short public id for a seat in one namespace; the seat key itself (a user id or guest pass id) is never shown to others.

string

string

string


receive(s, text): void

Session

string

void


scopeStats(scope): object

One namespace’s use right now: rooms, seats, connected players and bytes out a second (over the last second). For per-customer caps.

string

object

bytesOut: number

online: number

players: number

rooms: number


sent(len, n, room?): void

Meter: n copies of a text of len bytes (UTF-8, as on the wire) went out (to one room’s sockets when given).

number

number

Room | null

void


shutdown(): Promise<void>

Server shutdown: pending changes and saves are written, the live rooms go to onSnapshot (the next process takes them back), then every player hears 1012 and reconnects. Without onSnapshot a restart ends every match.

Promise<void>


start(): void

void


stats(): HubStats

HubStats


stop(): void

void


subTick(): void

Called every tickMs / 5 by start(). Housekeeping once per tickMs; each room sends on its own phase (every 5 sub-ticks, every 10 in rooms over 8 players, effects every 5), so 2,000 sockets are not written in one burst. tick() stays the one-call form for tests and simple hosts.

void


tick(): void

Every tickMs: send changes (every second tick in rooms over 8), handle slow readers, timeouts, silent hosts, expired seats.

void


whenLoaded(): Promise<void>

Resolves once every world save being read now has been read (tests, a bench).

Promise<void>