RoomHub
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new RoomHub(
opts):RoomHub
Parameters
Section titled “Parameters”bigRooms?
Section titled “bigRooms?”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?”scopeCaps?
Section titled “scopeCaps?”(scope) => ScopeCaps | undefined
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 (LoopMonitor in node.ts sets it once a minute; createGameServer and createRemoteServer start one)
loopRecent
Section titled “loopRecent”loopRecent: {
p99:number; } |null=null
the p99 over the last 10 s (LoopMonitor), 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”addressRetryMs()
Section titled “addressRetryMs()”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)
Parameters
Section titled “Parameters”address
Section titled “address”string
Returns
Section titled “Returns”number
allowAddress()
Section titled “allowAddress()”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.
Parameters
Section titled “Parameters”address
Section titled “address”string
Returns
Section titled “Returns”boolean
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,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.
Parameters
Section titled “Parameters”address
Section titled “address”string
counted?
Section titled “counted?”boolean
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(
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).
Parameters
Section titled “Parameters”scope?
Section titled “scope?”string
unsure?
Section titled “unsure?”boolean = false
Returns
Section titled “Returns”exportScope()
Section titled “exportScope()”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.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<RoomsSnapshot>
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
personOf()
Section titled “personOf()”personOf(
s):Person
The budget a person shares over their sockets (made with the first, gone with the last).
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Person
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
scopeList()
Section titled “scopeList()”scopeList():
object[]
Namespaces with live rooms here and their size (a router’s hand-over list, a dashboard).
Returns
Section titled “Returns”object[]
scopeStats()
Section titled “scopeStats()”scopeStats(
scope):object
slowed: how many times less often its rooms send because the namespace is over its own outBytes cap (1 = full rate).
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
slowed
Section titled “slowed”slowed:
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(
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.
Parameters
Section titled “Parameters”saveMs?
Section titled “saveMs?”number = 10_000
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>