RoomHub
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new RoomHub(
opts):RoomHub
Parameters
Section titled “Parameters”limits?
Section titled “limits?”Partial<Limits>
listRooms?
Section titled “listRooms?”boolean
() => number
onSnapshot?
Section titled “onSnapshot?”(snap) => void | Promise<void>
roomsPerScope?
Section titled “roomsPerScope?”(scope) => number | undefined
saves?
Section titled “saves?”secret
Section titled “secret”string
Returns
Section titled “Returns”RoomHub
Properties
Section titled “Properties”
readonlyboot:string
limits
Section titled “limits”
readonlylimits:Limits
listRooms
Section titled “listRooms”
readonlylistRooms: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
Section titled “loopRecent”loopRecent: {
p99:number; } |null=null
the same over the last 10 s (main.ts), for the half-rate switch
readonlynow: () =>number
Returns
Section titled “Returns”number
pending
Section titled “pending”pending:
number=0
pressure
Section titled “pressure”pressure:
boolean=false
over the data cap or a late loop: bigger rooms at half rate, no new rooms
Methods
Section titled “Methods”closeScope()
Section titled “closeScope()”closeScope(
scope,reason?):void
Close every room of one namespace (a public link stopped).
Parameters
Section titled “Parameters”string
reason?
Section titled “reason?”string = "this game is no longer shared"
Returns
Section titled “Returns”void
connect()
Section titled “connect()”connect(
conn,addr):Session| {reason:string;refused:number; }
A new socket. Null = refused (the caller closes it with the code given).
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Session | { reason: string; refused: number; }
drop()
Section titled “drop()”drop(
s):void
A socket is gone. Its seat stays (offline) for seatHoldMs, without host duty.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
exportRooms()
Section titled “exportRooms()”exportRooms():
RoomsSnapshot
The live rooms as plain JSON: everything a new process needs to carry on (sockets, timers and open actions are not kept).
Returns
Section titled “Returns”flushSaves()
Section titled “flushSaves()”flushSaves():
Promise<void>
Write every changed profile and world now and wait until the store has taken them (a restart, a test).
Returns
Section titled “Returns”Promise<void>
importRooms()
Section titled “importRooms()”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.
Parameters
Section titled “Parameters”unknown
maxAgeMs?
Section titled “maxAgeMs?”number
Returns
Section titled “Returns”number
publicId()
Section titled “publicId()”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.
Parameters
Section titled “Parameters”string
string
Returns
Section titled “Returns”string
receive()
Section titled “receive()”receive(
s,text):void
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”void
scopeStats()
Section titled “scopeStats()”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.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”object
bytesOut
Section titled “bytesOut”bytesOut:
number
online
Section titled “online”online:
number
players
Section titled “players”players:
number
rooms:
number
sent()
Section titled “sent()”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).
Parameters
Section titled “Parameters”number
number
Room | null
Returns
Section titled “Returns”void
shutdown()
Section titled “shutdown()”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.
Returns
Section titled “Returns”Promise<void>
start()
Section titled “start()”start():
void
Returns
Section titled “Returns”void
stats()
Section titled “stats()”stats():
HubStats
Returns
Section titled “Returns”stop()
Section titled “stop()”stop():
void
Returns
Section titled “Returns”void
subTick()
Section titled “subTick()”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.
Returns
Section titled “Returns”void
tick()
Section titled “tick()”tick():
void
Every tickMs: send changes (every second tick in rooms over 8), handle slow readers, timeouts, silent hosts, expired seats.
Returns
Section titled “Returns”void
whenLoaded()
Section titled “whenLoaded()”whenLoaded():
Promise<void>
Resolves once every world save being read now has been read (tests, a bench).
Returns
Section titled “Returns”Promise<void>