Skip to content

Global Net Api

The net api extends EventEmitter2 and uses wildcards with ”:” as a delimiter.

The following events are emitted:

// fired when data is recieved on a certain channel
net.on("CHANNEL", (data, editFn) => {})
// fired when data is sent on a certain channel
net.on("send:CHANNEL", (data, editFn) => {})
// you can also use wildcards, eg
net.on("send:*", () => {})

get gamemode(): string

The id of the gamemode the player is currently playing

string


get isHost(): boolean

Whether the user is the one hosting the current game

boolean


get room(): any

The room that the client is connected to, or null if there is no connection

any


get type(): ConnectionType

Which type of server the client is currently connected to

ConnectionType

modifyFetchRequest(id, path, callback): () => void

Runs a callback when a request is made that matches a certain path (can have wildcards)

ParameterType
idstring
pathstring
callback(options) => any

Function

void


modifyFetchResponse(id, path, callback): () => void

Runs a callback when a response is recieved for a request under a certain path (can have wildcards)

ParameterType
idstring
pathstring
callback(response) => any

Function

void


offLoad(id): void

Cancels any calls to onLoad with the same id

ParameterType
idstring

void


onLoad(id, callback, gamemode?): () => void

Runs a callback when the game is loaded, or runs it immediately if the game has already loaded

ParameterType
idstring
callback(type, gamemode) => void
gamemode?string | string[]

Function

A function to cancel waiting for load

void


send(channel, message?): void

Sends a message to the server on a specific channel

ParameterType
channelstring
message?any

void


stopModifyRequest(id): void

Stops any modifications made by modifyFetchRequest with the same id

ParameterType
idstring

void


stopModifyResponse(id): void

Stops any modifications made by modifyFetchResponse with the same id

ParameterType
idstring

void