atmoky Engage Server SDK is now available! Check out the documentation to learn more.
Documentation
Room Management

Room Management & Moderation

The server SDK, especially the RoomServiceClient class, provides a set of methods to manage rooms.
These methods include:
Rooms
  • list, create, and delete rooms
  • update room metadata
Participants
  • list participants in a room
  • remove participants from a room
  • mute published tracks of participants in a room
  • update participant metadata and permissions
Data Messages
  • broadcast data messages to participants in a room

Room Service Client

All these methods are part of the RoomServiceClient class which is instantiated with the server URL and API secrets of your project.
import { RoomServiceClient } from "@atmokyaudio/engage-server-sdk";
 
const rsc = new RoomServiceClient(
    process.env.ENGAGE_SERVER_URL!,
    process.env.ENGAGE_API_KEY!,
    process.env.ENGAGE_API_SECRET!
);
It's recommended to store secrets in environment variables and not in your source code.
All methods of the RoomServiceClient are async as they are calling the server API. The following examples assume that the methods are called from an async function.

List, Create, and Update Rooms

// list all rooms
const rooms = await rsc.listRooms();
 
// create a new empty room
const room = await rsc.createRoom({ name: "my-room" });
 
// update the room's metadata
const updatedRoom = await rsc.updateRoomMetadata("my-room", "some metadata");
 
// delete the room
await rsc.deleteRoom("my-room");

List and moderate participants

// list all participants in a room
const participants = await rsc.listParticipants("my-room");
 
// remove a participant from a room
await rsc.removeParticipant("my-room", "participant-identity");
 
// update participant metadata
await rsc.updateParticipant("my-room", "participant-identity", "some metadata");
 
// mute published tracks of a participant
const shouldMute = true;
await rsc.mutePublishedTrack(
    "my-room",
    "participant-identity",
    "track-sid",
    shouldMute
);

Broadcast data messages

// data object to send
const data = { payload: "my-data", more: 42 };
 
const encoder = new TextEncoder();
 
// broadcast a data message to all participants in a room
await rsc.sendData(
    "my-room",
    encoder.encode(JSON.stringify(data)),
    DataPacket_Kind.RELIABLE
);
 
// alternatively, send a data message to a subset of participants
await rsc.sendData(
    "my-room",
    encoder.encode(JSON.stringify(data)),
    DataPacket_Kind.RELIABLE,
    ["participant-identity-1", "participant-identity-2"]
);

atmoky Logo

© 2024 atmoky, GmbH.
All rights reserved.

We use cookies to measure and improve your browsing experience, and serve personalized ads or content.