Skip to content

Scoped 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) => {})
// fired when the game loads with a certain type
net.on(load:TYPE, (type) => {})
// 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

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

Runs a callback when the game is loaded, or runs it immediately if the game has already loaded. If the @gamemode header is set the callback will only fire if the gamemode matches one of the provided gamemodes.

ParameterType
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
messageany

void