Skip to main content
Defined in: modules/network/src/server/network-server-context.type.ts:19 Typed packets of the server, exposed as ctx.network.packets.

Example

Methods

on()

on<T>(packet, listener): () => void
Defined in: modules/network/src/server/network-server-context.type.ts:28 Be notified of every packet of a type, each tick before the ECS systems (not while paused).

Type Parameters

T
T

Parameters

packet
PacketDefinition<T>
listener
PacketListener<NoInfer<T>, ServerPacketInfo>

Returns

A function that removes the listener. () => void

Throws

When another definition with the same name has another channel or validate.

read()

read<T>(packet): (ServerPacketInfo & object)[]
Defined in: modules/network/src/server/network-server-context.type.ts:38 Return the packets of a type received this tick, for an ECS system.

Type Parameters

T
T

Parameters

packet
PacketDefinition<T>

Returns

(ServerPacketInfo & object)[]

Throws

When another definition with the same name has another channel or validate.

sendToAll()

sendToAll<T>(packet, …args): void
Defined in: modules/network/src/server/network-server-context.type.ts:47 Send a packet to every client reachable on the definition’s channel, unless another channel is given. data is left out for a packet without payload: sendToAll(Start).

Type Parameters

T
T

Parameters

packet
PacketDefinition<T>
args
…PacketArgs<NoInfer<T>>

Returns

void

Throws

When the channel’s port was not configured, or data cannot be encoded as JSON.

sendToClient()

sendToClient<T>(clientId, packet, …args): void
Defined in: modules/network/src/server/network-server-context.type.ts:55 Send a packet to one client, on the definition’s channel unless another channel is given.

Type Parameters

T
T

Parameters

clientId
string
packet
PacketDefinition<T>
args
…PacketArgs<NoInfer<T>>

Returns

void

Throws

When the channel’s port was not configured, or data cannot be encoded as JSON.