atmoky Engage Server SDK is now available! Check out the documentation to learn more.
Documentation
Real-time Communication
Data Messages

Data Messages

You can send arbitrary data messages to participants in a room using the LocalParticipant's publishData method. Data can be sent to all participants in the room or to specific participants and can be sent reliably or unreliably.
import { RoomEvent, DataPacket_Kind, RemoteParticipant } from "@atmokyaudio/engage-client"
 
const room = space.rooms[0];
const localParticipant = room.localParticipant;
 
const encoder = new TextEncoder();
const decoder = new TextDecoder();
 
const textData = JSON.stringify({welcome: "Hello World!"});
const data = encoder.encode(textData);
 
// Send data to all participants in the room
localParticipant.publishData(data, DataPacket_Kind.LOSSY);
 
// Send data to a specific participant in the room
localParticipant.publishData(data, DataPacket_Kind.RELIABLE, ['participantSid']);
 
// Receive data from other participants in the room
room.on(RoomEvent.DataReceived, (payload: Uint8Array, participant?: RemoteParticipant, kind?: DataPacket_Kind, topic?: string)  => {
  const receivedData = decoder.decode(payload);
  console.log("Received ", receivedData, "from ", participant?.identity, "with kind ", kind, "on topic ", topic);
})

atmoky Logo

© 2024 atmoky, GmbH.
All rights reserved.

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