Class: Network
Constructors
constructor
• new Network(options?): Network
Parameters
| Name | Type |
|---|---|
options | Partial<NetworkOptions> |
Returns
Properties
clientInfo
• clientInfo: Object
Type declaration
| Name | Type |
|---|---|
id | string |
metadata? | Record<string, any> |
username | string |
connected
• connected: boolean = false
disconnectReason
• disconnectReason: string = ""
intercepts
• intercepts: NetIntercept[] = []
joined
• joined: boolean = false
onConnect
• onConnect: () => void
Type declaration
▸ (): void
Returns
void
onDisconnect
• onDisconnect: () => void
Type declaration
▸ (): void
Returns
void
onJoin
• onJoin: (world: string) => void
Type declaration
▸ (world): void
Parameters
| Name | Type |
|---|---|
world | string |
Returns
void
onLeave
• onLeave: (world: string) => void
Type declaration
▸ (world): void
Parameters
| Name | Type |
|---|---|
world | string |
Returns
void
options
• options: NetworkOptions
socket
• socket: URL
url
• url: Url<{ [key: string]: any; }>
world
• world: string
ws
• ws: ProtocolWS = null
Accessors
concurrentWorkers
• get concurrentWorkers(): number
Returns
number
droppedCommandCount
• get droppedCommandCount(): number
Command packets dropped for good, with an error logged for each batch.
Returns
number
droppedPacketCount
• get droppedPacketCount(): number
Inbound packets dropped unprocessed this session, each reported in an error log (see NetworkOptions.maxQueuedPackets).
Returns
number
isClientOutdated
• get isClientOutdated(): boolean
Terminal protocol rejection: only a fresh client build can reconnect.
Returns
boolean
isJoinPending
• get isJoinPending(): boolean
True between a (re)join request and its INIT: reads of world state are answered from a map the server may no longer agree with.
Returns
boolean
joinGeneration
• get joinGeneration(): number
Completed INIT handshakes so far; bumps on first join, every rejoin, and every world switch.
Returns
number
packetQueueLength
• get packetQueueLength(): number
Returns
number
pendingCommandCount
• get pendingCommandCount(): number
Command packets waiting for a live session to retry on.
Returns
number
rtcConnected
• get rtcConnected(): boolean
Returns
boolean
serverUrl
• get serverUrl(): string
Returns
string
Methods
action
▸ action(type, data?): Promise<void>
Parameters
| Name | Type |
|---|---|
type | string |
data? | any |
Returns
Promise<void>
connect
▸ connect(serverURL, options?): Promise<Network>
Parameters
| Name | Type |
|---|---|
serverURL | string |
options | NetworkConnectionOptions |
Returns
Promise<Network>
connectWebRTC
▸ connectWebRTC(): Promise<void>
Returns
Promise<void>
disconnect
▸ disconnect(): void
Returns
void
flush
▸ flush(): void
Returns
void
isPacketPendingSend
▸ isPacketPendingSend(packet): boolean
Whether this exact packet object is still waiting in the command retry queue. Together with the packet's absence from its intercept queue this lets a caller prove a command was handed to an OPEN socket.
Parameters
| Name | Type |
|---|---|
packet | MessageProtocol |
Returns
boolean
join
▸ join(world): Promise<Network>
Parameters
| Name | Type |
|---|---|
world | string |
Returns
Promise<Network>
leave
▸ leave(): void
Returns
void
offerRegistry
▸ offerRegistry(entry): boolean
Hand the network a block registry from elsewhere (an HTTP fetch made while the page loaded, say) for the next JOIN to name, exactly as a registry read back from storage is. The digest must be the one the server gave with that text; the network never computes one.
Taken only while it can still serve a JOIN: before one is sent, it replaces whatever storage had brought back (a fetch answers for the server's registry now, storage for an earlier one); with a JOIN in flight, only the registry that JOIN named. Returns whether the network now holds this registry.
Parameters
| Name | Type |
|---|---|
entry | CachedRegistry |
Returns
boolean
parseHeldRegistry
▸ parseHeldRegistry(): ParsedRegistry
The registry this client holds for its next INIT, parsed now, once, instead of when that INIT arrives. An INIT that leaves the registry out is then completed with these very objects, so anything built from them ahead of it (the world loading its blocks early) is built from what the INIT carries. Null while no registry is held, or when its text does not parse. Call it before the INIT lands; the objects belong to that INIT.
Returns
ParsedRegistry
reconnectNow
▸ reconnectNow(): boolean
Trigger an immediate reconnect attempt, bypassing the periodic backoff. Returns false when there is nothing to do: already connected, never connected, or terminally rejected (outdated client build).
Returns
boolean
register
▸ register(...intercepts): Network
Parameters
| Name | Type |
|---|---|
...intercepts | NetIntercept[] |
Returns
send
▸ send(event): boolean
Hand one event to the socket. Returns whether the packet was actually
given to an OPEN socket: false means it was NOT sent (no socket, still
connecting, closing, or closed). Callers that carry one-shot intent must
check the answer; flush does this for every intercept packet.
Parameters
| Name | Type |
|---|---|
event | any |
Returns
boolean
setID
▸ setID(id): void
Parameters
| Name | Type |
|---|---|
id | string |
Returns
void
setMetadata
▸ setMetadata(metadata): void
Parameters
| Name | Type |
|---|---|
metadata | Record<string, any> |
Returns
void
setUsername
▸ setUsername(username): void
Parameters
| Name | Type |
|---|---|
username | string |
Returns
void
sync
▸ sync(): void
Returns
void
unregister
▸ unregister(...intercepts): Network
Parameters
| Name | Type |
|---|---|
...intercepts | NetIntercept[] |
Returns
whenRegistryHeld
▸ whenRegistryHeld(timeoutMs): Promise<CachedRegistry>
Resolves with the registry this client holds once it holds one (read
back from storage or offered), or null after timeoutMs. Never rejects.
Parameters
| Name | Type |
|---|---|
timeoutMs | number |
Returns
Promise<CachedRegistry>