Skip to main content
Defined in: modules/network/src/client/network-client-context.type.ts:57 Public surface of NetworkClientLibrary, exposed on Context.network.

Remarks

Every method takes an optional { channel }. Reliable channels need SERVER_TCP_PORT, unreliable ones SERVER_UDP_PORT; using a channel whose port is not configured throws.

Properties

clientId

readonly clientId: string | undefined
Defined in: modules/network/src/client/network-client-context.type.ts:61 Client id assigned by the server, shared by TCP and UDP. undefined until welcomed.
readonly inviteLink: string | undefined
Defined in: modules/network/src/client/network-client-context.type.ts:65 Link to send to other players so they join this peer-to-peer game, undefined otherwise.

packets

readonly packets: ClientPacketsApi
Defined in: modules/network/src/client/network-client-context.type.ts:59 Typed packets: per-type listeners, read and send.

roomCode

readonly roomCode: string | undefined
Defined in: modules/network/src/client/network-client-context.type.ts:63 Code of the peer-to-peer game this player hosts or joined, undefined otherwise.

Methods

getReceivedPackets()

getReceivedPackets(options?): NetworkData[]
Defined in: modules/network/src/client/network-client-context.type.ts:76 Return the packets received since the last call, from channel or from every configured channel. Call it once per frame: packets left unread for a whole tick are dropped.

Parameters

options?
ChannelOptions

Returns

NetworkData[]

isConnected()

isConnected(options?): boolean
Defined in: modules/network/src/client/network-client-context.type.ts:78 Return true when channel, or every configured channel, is connected.

Parameters

options?
ChannelOptions

Returns

boolean

sendData()

sendData(data, options?): void
Defined in: modules/network/src/client/network-client-context.type.ts:70 Send bytes, a string or a JSON value to the server, on Channel.ReliableOrdered unless another channel is given.

Parameters

data
NetworkPayload
options?
ChannelOptions

Returns

void