Skip to main content

Class: Network

Constructors​

constructor​

• new Network(options?): Network

Parameters​

NameType
optionsPartial<NetworkOptions>

Returns​

Network

Properties​

clientInfo​

• clientInfo: Object

Type declaration​

NameType
idstring
metadata?Record<string, any>
usernamestring

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​
NameType
worldstring
Returns​

void


onLeave​

• onLeave: (world: string) => void

Type declaration​

▸ (world): void

Parameters​
NameType
worldstring
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​

NameType
typestring
data?any

Returns​

Promise<void>


connect​

▸ connect(serverURL, options?): Promise<Network>

Parameters​

NameType
serverURLstring
optionsNetworkConnectionOptions

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​

NameType
packetMessageProtocol

Returns​

boolean


join​

▸ join(world): Promise<Network>

Parameters​

NameType
worldstring

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​

NameType
...interceptsNetIntercept[]

Returns​

Network


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​

NameType
eventany

Returns​

boolean


setID​

▸ setID(id): void

Parameters​

NameType
idstring

Returns​

void


setMetadata​

▸ setMetadata(metadata): void

Parameters​

NameType
metadataRecord<string, any>

Returns​

void


setUsername​

▸ setUsername(username): void

Parameters​

NameType
usernamestring

Returns​

void


sync​

▸ sync(): void

Returns​

void


unregister​

▸ unregister(...intercepts): Network

Parameters​

NameType
...interceptsNetIntercept[]

Returns​

Network