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
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
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[] |