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 Callbacks(): any

Colyseus’s Callbacks function for listening to state changes

any


get gamemode(): null | string

The id of the gamemode the player is currently playing

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

addListener(event, listener): void

Parameter Type
event string | string[]
listener (…data) => void

void


emit(event, …args): void

Parameter Type
event string | string[]
args any[]

void


emitAsync(event, …args): Promise<any[]>

Parameter Type
event string | string[]
args any[]

Promise<any[]>


eventNames(nsAsArray?): (string | symbol | event[])[]

Parameter Type
nsAsArray? boolean

(string | symbol | event[])[]


getMaxListeners(): number

number


hasListeners(event): Boolean

Parameter Type
event string | string[]

Boolean


listenerCount(event): number

Parameter Type
event string | string[]

number


listeners(event): ListenerFn[]

Parameter Type
event string | string[]

ListenerFn[]


listenersAny(): ListenerFn[]

ListenerFn[]


listenTo(target, events, options?): EventEmitter2

Parameter Type
target GeneralEventEmitter
events string | string[]
options? ListenToOptions

EventEmitter2

BaseNetApi.listenTo

listenTo(target, events, options?): EventEmitter2

Parameter Type
target GeneralEventEmitter
events Record<string, string>
options? ListenToOptions

EventEmitter2

BaseNetApi.listenTo


many(event, timesToListen, listener): void

Parameter Type
event string | string[]
timesToListen number
listener (…data) => void

void


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

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

Parameter Type
path string
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)

Parameter Type
path string
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";
});

off(event, listener): void

Parameter Type
event string | string[]
listener (…data) => void

void


offAny(listener): void

Parameter Type
listener (event, …data) => void

void


on(event, listener): void

Parameter Type
event string | string[]
listener (…data) => void

void


onAny(listener): void

Parameter Type
listener (event, …data) => void

void


once(event, listener): void

Parameter Type
event string | string[]
listener (…data) => void

void


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.

Parameter Type
callback (type, gamemode) => void
gamemode? string | readonly string[]

Function

A function to cancel waiting for load

void


prependAny(listener): void

Parameter Type
listener (event, …data) => void

void


prependListener(event, listener): void

Parameter Type
event string | string[]
listener (…data) => void

void


prependMany(event, timesToListen, listener): void

Parameter Type
event string | string[]
timesToListen number
listener (…data) => void

void


prependOnceListener(event, listener): void

Parameter Type
event string | string[]
listener (…data) => void

void


removeAllListeners(event?): void

Parameter Type
event? string | string[]

void


removeListener(event, listener): void

Parameter Type
event string | string[]
listener (…data) => void

void


send(channel, message?): void

Sends a message to the server on a specific channel

Parameter Type
channel string
message? any

void


setMaxListeners(amount): void

Parameter Type
amount number

void


stopListeningTo(target, event?): Boolean

Parameter Type
target GeneralEventEmitter
event? string | string[]

Boolean


waitFor(event, timeout?): CancelablePromise<any[]>

Parameter Type
event string | string[]
timeout? number

CancelablePromise<any[]>

BaseNetApi.waitFor

waitFor(event, filter?): CancelablePromise<any[]>

Parameter Type
event string | string[]
filter? WaitForFilter

CancelablePromise<any[]>

BaseNetApi.waitFor

waitFor(event, options?): CancelablePromise<any[]>

Parameter Type
event string | string[]
options? WaitForOptions

CancelablePromise<any[]>

BaseNetApi.waitFor