ctx.network.packets.
Example
Methods
on()
on<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).T>(packet,listener): () =>void
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 orvalidate.
read()
read<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.T>(packet): (ServerPacketInfo&object)[]
Type Parameters
T
T
Parameters
packet
PacketDefinition<T>
Returns
(ServerPacketInfo & object)[]
Throws
When another definition with the same name has another channel orvalidate.
sendToAll()
sendToAll<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 anotherT>(packet, …args):void
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, ordata cannot be
encoded as JSON.
sendToClient()
sendToClient<Defined in: modules/network/src/server/network-server-context.type.ts:55 Send a packet to one client, on the definition’s channel unless anotherT>(clientId,packet, …args):void
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, ordata cannot be
encoded as JSON.