Skip to main content

A manager for any events interacting with the Voxelize server. This is useful for any defined game events that are sent from or needs to be broadcasted to the server.

Example

const events = new VOXELIZE.Events();

// Define the behavior to handle a game-over event. Keep in mind that this
// event is most likely sent from the server, so check out the documentations
// for creating and emitting custom events fullstack.
events.on("game-over", (payload) => {
// Do something about the game over event.
});

// Register the interceptor with the network.
network.register(events);

TODO-DOC

Hierarchy

Implements

Constructors

constructor

new Events(): Events

Creates a new instance of the Voxelize event manager.

Returns

Events

Overrides

Map<string, EventHandler>.constructor

Methods

addEventListener

addEventListener(name, handler): void

Synonym for on, adds a listener to a Voxelize server event. If the payload cannot be parsed by JSON, null is set.

Parameters

NameTypeDescription
namestringThe name of the event to listen on. Case sensitive.
handlerEventHandlerWhat to do when this event is received?

Returns

void


emit

emit(name, payload?): void

Emit an event to the server.

Parameters

NameTypeDescription
namestringThe name of the event to emit.
payloadanyThe payload to send with the event.

Returns

void


on

on(name, handler): void

Synonym for addEventListener, adds a listener to a Voxelize server event. If the payload cannot be parsed by JSON, null is set.

Parameters

NameTypeDescription
namestringThe name of the event to listen on. Case sensitive.
handlerEventHandlerWhat to do when this event is received?

Returns

void