Skip to content

RoomHub

new RoomHub(opts): RoomHub

BigRoomPlugin

Partial<Limits>

boolean

() => number

(snap) => void | Promise<void>

(scope) => number | undefined

SavePort

(scope) => ScopeCaps | undefined

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 (LoopMonitor in node.ts sets it once a minute; createGameServer and createRemoteServer start one)


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

the p99 over the last 10 s (LoopMonitor), 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

addressRetryMs(address): number

ms until an address’s new-socket window turns (the retry hint in the close reason; relay.js waits at least that long)

string

number


allowAddress(address): boolean

New-socket budget of one address (addressKey), connectsPerAddress per 10 s. Adapters may call it before costly work on an upgrade (a lookup): false = refuse now. The window map is pruned when it grows, so random addresses cannot grow it without end.

string

boolean


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, address, o?): Session | { reason: string; refused: number; }

counted: the adapter already spent this socket’s allowAddress before its upgrade, so it is not counted twice.

Conn

string

boolean

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


drop(s): void

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

Session

void


exportRooms(scope?, unsure?): RoomsSnapshot

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

string

boolean = false

RoomsSnapshot


exportScope(scope): Promise<RoomsSnapshot>

Blue/green hand-over of one namespace to another process: its pending changes go out, open actions fail (“server restarting”), saves are written, its rooms are exported, its sockets hear 1012 (a router in front re-joins them on the other process over the same page socket; a page on its own reconnects) and its rooms close here, giving up their save leases. Joins to it are refused with 1012 meanwhile. Resolves once every save is in the store, so the other process may take the snapshot (importRooms) and write the same saves.

string

Promise<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


personOf(s): Person

The budget a person shares over their sockets (made with the first, gone with the last).

Session

Person


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


scopeList(): object[]

Namespaces with live rooms here and their size (a router’s hand-over list, a dashboard).

object[]


scopeStats(scope): object

slowed: how many times less often its rooms send because the namespace is over its own outBytes cap (1 = full rate).

string

object

bytesOut: number

online: number

players: number

rooms: number

slowed: 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(saveMs?): Promise<void>

Server shutdown: pending changes and saves are written, every player hears 1012 and reconnects, and the live rooms go to onSnapshot (the next process takes them back). Without onSnapshot a restart ends every match. Saves get saveMs to land (a store that hangs cannot hold the snapshot back); the snapshot is taken after that, so a world whose write failed or is still on its way is written again by the next process.

number = 10_000

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>