0% found this document useful (0 votes)
2 views1 page

Event - WorkAdventure Documentation

The document provides an overview of the WorkAdventure event system, which enables real-time message exchange between players on the same map. It details how to broadcast events using the WA.event.broadcast method and how to listen for events with WA.event.on, including the structure of the ScriptingEvent. Additionally, it includes example code for both broadcasting and subscribing to events.

Uploaded by

raziq.brown
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Event - WorkAdventure Documentation

The document provides an overview of the WorkAdventure event system, which enables real-time message exchange between players on the same map. It details how to broadcast events using the WA.event.broadcast method and how to listen for events with WA.event.on, including the structure of the ScriptingEvent. Additionally, it includes example code for both broadcasting and subscribing to events.

Uploaded by

raziq.brown
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Map Building Admin User Developer Tutorials Login Get Started Search ctrl K

WorkAdventure APIs Map Scripting API Api Reference Event


Broadcasting an event to all players of the map
Inbound API
Listening to events
Map Scripting API Event
Variables
The WorkAdventure event system allows to exchange messages between players of a same map, in real-time.
Events

Api Reference See the events documentation for an introduction to the "events" concept.

Camera

Chat Broadcasting an event to all players of the map


Controls
To broadcast an event to all players of the map, use the WA.event.broadcast method:
Event

Map Editor API WA.event.broadcast(key: string, data: unknown): Promise<void>


Metadata

Navigation key (type: string ): the name of the event

data (type: unknown ): the payload of the event. Can be any JSON-serializable value (including objects, arrays, strings, numbers,
Player
booleans, undefined, etc.).
Players
The dispatchEvent method returns a promise that will be resolved when the event has successfully reached the server.
Room

Sound Example usage:

Start
WA.event.broadcast("my-event", "my payload");
State

UI

Deprecated Functions
Listening to events
Extended utility functions
Events can be listened to using WA.event.on .
Scripting Internals

Using Typescript
import type { Observable } from "rxjs";
Map Storage API
type ScriptingEvent = {
Room API name: string;
data: unknown;
senderId: number | undefined;
}

WA.event.on(name: string): Observable<ScriptingEvent>

on returns an RxJS Observable. You can use the subscribe method to listen to events. The subscribe method takes a callback
function that will be called each time an event is received. The callback function takes a single argument: the event object of type
ScriptingEvent .

The ScriptingEvent contains the following fields:

data (type: unknown ): the payload of the event

name (type: string ): the name of the event

senderId (type: number ): the ID of the player that sent the event (or undefined if the event was sent by the system)

The subscribe method returns a Subscription object. You can use the unsubscribe method of this object to stop listening to
events.

const subscription = WA.event.on("my-event").subscribe((event) => {


console.log("Event received", event.data);
});

// ...

subscription.unsubscribe();

Edit this page

Previous Next
« Controls Map Editor API »

Docs Need help ? Follow us

Map Building Book a demo Linkedin


Admin Discord Twitter
Developer GitHub Facebook

Copyright © 2024 workadventu.re - All Rights Reserved

You might also like