Skip to main content

Interface: NetIntercept

An interceptor for the network layer. When registered to a network instance, the network instance will run through all network packets through the interceptor, and also allowing the interceptor to send packets to the server.

Implemented by​

Properties​

onMessage​

• Optional onMessage: (message: MessageProtocol, clientInfo: { id: string ; metadata?: Record<string, any> ; username: string }) => void

A listener to be implemented to handle incoming packets.

Type declaration​

▸ (message, clientInfo): void

Parameters​
NameTypeDescription
messageMessageProtocolThe message received from the server.
clientInfoObjectThe client information.
clientInfo.idstringThe client's ID.
clientInfo.metadata?Record<string, any>The client's metadata (device info, etc.).
clientInfo.usernamestringThe client's username.
Returns​

void


onPacketsSent​

• Optional onPacketsSent: (packets: MessageProtocol[]) => void

Called by network.flush() with the packets from packets that were actually handed to an open socket, right after they were. A packet queued in packets may wait for the next flush and for the main thread to be free; this is where a sender learns when it truly left.

Type declaration​

▸ (packets): void

Parameters​
NameType
packetsMessageProtocol[]
Returns​

void


packets​

• Optional packets: MessageProtocol[]

An array of packets to be sent to the server. These packets will be sent to the server after every network.flush() call.


wantsMessagesOnArrival​

• Optional wantsMessagesOnArrival: () => boolean

True while this intercept is waiting on what arrives next and nothing it draws could be stalled by handling it at once (a world waiting on its spawn window). The network then decodes each packet on its own thread the moment it arrives instead of in a decode worker on its next sync tick. Polled per packet, so it must be cheap.

Type declaration​

▸ (): boolean

Returns​

boolean