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
-
Map<string,EventHandler>↳
Events
Implements
Constructors
constructor
• new Events(): Events
Creates a new instance of the Voxelize event manager.
Returns
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
| Name | Type |
|---|---|
TPayload | EventPayload |
Parameters
| Name | Type | Description |
|---|---|---|
name | string | The name of the event to listen on. Case sensitive. |
handler | EventHandler<TPayload> | What to do when this event is received? |
Returns
void
emit
▸ emit(name, payload?): void
Emit an event to the server.
Parameters
| Name | Type | Description |
|---|---|---|
name | string | The name of the event to emit. |
payload | EventPayload | The payload to send with the event. |
Returns
void
emitSoundEffect
▸ emitSoundEffect(payload): void
Parameters
| Name | Type |
|---|---|
payload | SoundEffectEventPayload |
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
| Name | Type |
|---|---|
TPayload | EventPayload |
Parameters
| Name | Type |
|---|---|
name | string |
handler | EventHandler<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
| Name | Type |
|---|---|
TPayload | EventPayload |
Parameters
| Name | Type | Description |
|---|---|---|
name | string | The name of the event to listen on. Case sensitive. |
handler | EventHandler<TPayload> | What to do when this event is received? |
Returns
void
onSoundEffect
▸ onSoundEffect(handler): void
Parameters
| Name | Type |
|---|---|
handler | SoundEffectEventHandler |
Returns
void
removeEventListener
▸ removeEventListener<TPayload>(name, handler): void
Synonym for off.
Type parameters
| Name | Type |
|---|---|
TPayload | EventPayload |
Parameters
| Name | Type |
|---|---|
name | string |
handler | EventHandler<TPayload> |
Returns
void