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