brash-wire-35118
09/08/2025, 6:23 PMtall-airline-16756
09/08/2025, 6:23 PMtall-airline-16756
09/08/2025, 6:24 PMsendData method.
Here’s how you can do it:
1. First, authenticate with LiveKit using your API key and secret.
2. Then, use the sendData method to specify the room name, the data you want to send, the delivery kind (RELIABLE or LOSSY), and if you want, set a topic or target specific participants.
Here’s a quick example in Node.js:
import { RoomServiceClient } from 'livekit-server-sdk';
const roomService = new RoomServiceClient(
process.env.LIVEKIT_URL,
process.env.LIVEKIT_API_KEY,
process.env.LIVEKIT_API_SECRET
);
await roomService.sendData(
'my-room-name',
new TextEncoder().encode('Hello participants!'),
livekit.DataPacket_Kind.RELIABLE,
{
topic: 'custom_event',
// destinationIdentities: ['user1', 'user2'] // optional: send to specific users
}
);
On the client side, participants will get this data through the dataReceived event in the client SDKs. If you have any questions or want me to walk you through anything else, just let me know—I’m happy to help!
Sources: agent-console/app/api/room/send-data/route.ts | mcp/server.py | src/main/kotlin/io/livekit/server/RoomServiceClient.kt | livekit-api/src/services/room.rs | Webhooks | LiveKit Docsbrash-wire-35118
09/08/2025, 6:25 PMtall-airline-16756
09/08/2025, 6:26 PMfrom livekit.protocol import room as room_proto
from livekit.protocol.models import DataPacket
import json
async def send_data_to_room(room_name: str, message: str):
chat_payload = {
"message": message,
"sender": "System",
"timestamp": int(asyncio.get_event_loop().time() * 1000)
}
data = json.dumps(chat_payload).encode('utf-8')
send_request = room_proto.SendDataRequest(
room=room_name,
data=data,
kind=DataPacket.Kind.RELIABLE,
topic="custom_event"
)
await lkapi.room.send_data(send_request)
Here’s a quick breakdown:
• room_name: This is the name of the room where you want to send your event.
• message: The actual custom event data you want to share.
• kind: Use DataPacket.Kind.RELIABLE if you want to make sure the message gets delivered, or LOSSY if speed is more important.
• topic: This is optional but handy for categorizing your message (like "custom_event").
Just a heads up—make sure you have the right API credentials and permissions to send data to the room. If you have any questions or want me to walk you through it, just let me know. I’m here to help!