Skip to content

Net Api

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

// fired when data is recieved on a certain channel
api.net.on("CHANNEL", (data, editFn) => {
editFn("new data"); // Replace the data with "new data" before Gimkit processes it
});
// fired when data is sent on a certain channel
api.net.on("send:CHANNEL", (data, editFn) => {
editFn(null); // Cancel the data being sent
});
// you can also use wildcards, eg
api.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 state(): GimkitSchema

Gimkit’s internal Colyseus state

GimkitSchema


get type(): ConnectionType

Which type of server the client is currently connected to

ConnectionType

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

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

ParameterType
pathstring
callback(options) => any

Function

A function to stop the modification

void

api.net.modifyFetchRequest("/api/experiences", (request) => {
console.log(request.data);
request.data.modified = true;
return null; // Cancel the request
});

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

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

ParameterType
pathstring
callback(response) => any

Function

A function to stop the modification

void

api.net.modifyFetchResponse("/api/experience/map/hooks", (data) => {
console.log(data);
return "modified data";
});

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 | readonly 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