
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
@workadventure/room-api-client
Advanced tools
Easily create a GRPC client to connect your service to the Room API of a WorkAdventure server.
npm install @workadventure/room-api-client
Use the createRoomApiClient
function to create a client.
The client expects an API key as first parameter. See the Authentication section of the Room API documentation to learn how to get your own API key.
const client = createRoomApiClient("MY AWESOME KEY");
By default, the client targets the official WorkAdventure server. If you are using a self-hosted version, you must in addition pass in parameter the domain name and port of your WorkAdventure RoomApi endpoint.
const client = createRoomApiClient("My AWESOME KEY", "play.example.com", "5221");
The Room API client allows you to set, read and track variables in a room using the following methods:
client.saveVariable({ name: string, room: string, value: unknown }): Promise<void>
client.readVariable({ name: string, room: string }): Promise<Value>
client.listenVariable({ name: string, room: string }): AsyncIterable<Value>
[!WARNING]
readVariable
andlistenVariable
return aValue
object. To get the underlying value, you must call theValue.unwrap
function. This is because the functions can return nothing due to an error, and theValue
object allows you to check if the value is an error or not.
import { createRoomApiClient } from "@workadventure/room-api-client";
/**
* By default, the client targets the official WorkAdventure server,
* but you can also define customs domain and port.
* Example :
* const client = createRoomApiClient("My AWESOME KEY", "mydomain.net", "5221");
*/
const client = createRoomApiClient("My AWESOME KEY");
// URL of the room you wish to interact with
const roomUrl = "https://play.workadventu.re/@/my-organization/my-world/my-room";
// Name of the variable with which you want to interact
const variableName = "textField";
async function init() {
// Save a variable
await client.saveVariable({
name: variableName,
room: roomUrl,
value: "Default Value",
});
console.log("Value saved: Default Value");
// Read a variable
const value = await client.readVariable({
name: variableName,
room: roomUrl,
});
console.log("Value read:", Value.unwrap(value));
// Save a variable in 5sec
setTimeout(async () => {
await client.saveVariable({
name: variableName,
room: roomUrl,
value: "New Value",
});
console.log("Value saved: New Value");
}, 5000);
// Listen a variable
const listenVariable = client.listenVariable({
name: variableName,
room: roomUrl,
});
for await (const value of listenVariable) {
console.log("Value listened:", Value.unwrap(value));
break;
}
}
init();
The Room API client allows you to send and listen to events in a room using the following methods:
client.broadcastEvent({ name: string, room: string, data: unknown }): Promise<void>
client.listenToEvent({ name: string, room: string }): AsyncIterable<any>
import { createRoomApiClient } from "@workadventure/room-api-client";
/**
* By default, the client targets the official WorkAdventure server,
* but you can also define customs domain and port.
* Example :
* const client = createRoomApiClient("My AWESOME KEY", "mydomain.net", "5221");
*/
const client = createRoomApiClient("My AWESOME KEY");
// URL of the room you wish to interact with
const roomUrl = "https://play.workadventu.re/@/my-organization/my-world/my-room";
// Name of the event with which you want to interact
const eventName = "my-event";
async function init() {
// Send an event in 5 seconds
setTimeout(async () => {
await client.broadcastEvent({
name: eventName,
room: roomUrl,
data: "Default Value",
});
console.log("Event sent: Default Value");
}, 5000);
// Listen a event
const events = client.listenToEvent({
name: eventName,
room: roomUrl,
});
for await (const event of events) {
console.log("Event received:");
console.log("Sender:", event.senderId);
console.log("Value:", event.data);
break;
}
}
init();
FAQs
Workadventure Room Api Client
We found that @workadventure/room-api-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.