Skip to main content

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

Multiple listeners may register for the same event name; each is called when that event arrives. Use off to remove a specific listener.

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<TPayload>(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.

Type parameters

NameType
TPayloadEventPayload

Parameters

NameTypeDescription
namestringThe name of the event to listen on. Case sensitive.
handlerEventHandler<TPayload>What 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.
payloadEventPayloadThe payload to send with the event.

Returns

void


emitSoundEffect

emitSoundEffect(payload): void

Parameters

NameType
payloadSoundEffectEventPayload

Returns

void


off

off<TPayload>(name, handler): void

Remove a previously registered listener. No-op if the handler was not registered for this name.

Type parameters

NameType
TPayloadEventPayload

Parameters

NameType
namestring
handlerEventHandler<TPayload>

Returns

void


on

on<TPayload>(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.

Multiple handlers may share the same event name; later registrations are no longer canceled.

Type parameters

NameType
TPayloadEventPayload

Parameters

NameTypeDescription
namestringThe name of the event to listen on. Case sensitive.
handlerEventHandler<TPayload>What to do when this event is received?

Returns

void


onSoundEffect

onSoundEffect(handler): void

Parameters

NameType
handlerSoundEffectEventHandler

Returns

void


removeEventListener

removeEventListener<TPayload>(name, handler): void

Synonym for off.

Type parameters

NameType
TPayloadEventPayload

Parameters

NameType
namestring
handlerEventHandler<TPayload>

Returns

void