How to set room attributes from auth server API?
# ask-ai
a
How to set room attributes from auth server API?
t
Thanks for reaching out, Gamal. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to help you with setting room attributes from the auth server API! You can use the room metadata field, which lets you store structured data (like JSON) as a string. Here are two friendly ways to do this: • During Room Creation: You can use the
CreateRoom
API and simply include the
metadata
field. Here's a quick example:
Copy code
// Node.js Example
await roomService.createRoom({
  name: 'my-room',
  metadata: JSON.stringify({ theme: "dark", accessLevel: "premium" })
});
• After Room Creation: If you want to update the metadata later, you can use the
UpdateRoomMetadata
API to change it dynamically. For instance:
Copy code
// Node.js Example
await roomService.updateRoomMetadata('my-room', JSON.stringify({ theme: "light", accessLevel: "basic" }));
Just a quick note: room metadata has a limit of 64 KiB and is shared with participants through the
RoomMetadataChanged
event. If you'd like, I’m here to provide more details or examples—just let me know! Sources: Core Platform Architecture & Authentication | livekit/livekit_composite | D... | Room metadata | LiveKit Docs | packages/livekit-server-sdk/src/RoomServiceClient.ts | livekit-api/livekit/api/room_service.py
a
How to create room with attributes using API connection-details?
t
Creating a room with specific attributes using your API connection details is quite straightforward with the
CreateRoom
API. Let me walk you through an example using the Node.js SDK:
Copy code
`import { RoomServiceClient } from 'livekit-server-sdk';

const client = new RoomServiceClient('', 'API_KEY', 'API_SECRET');

await client.createRoom({
  name: 'my-room',
  emptyTimeout: 300,               // Keep room open for 5 minutes before first participant
  departureTimeout: 300,           // Keep room open for 5 minutes after last participant leaves
  maxParticipants: 50,             // Limit participants to 50
  metadata: JSON.stringify({       // Store attributes as JSON in metadata
    category: "meeting",
    department: "engineering",
    priority: "high"
  })
});`


Just a quick note: room metadata is stored as a single string, so using JSON is a great way to keep your structured data organized. And if you ever need to update this information, you can easily do so with the `UpdateRoomMetadata` API.


If you’d like, I’m here to help with more examples or guide you through using a different SDK. Just let me know!
Sources: livekit-api/livekit/api/room_service.py | README.md | Rooms, participants, and tracks | LiveKit Docs | packages/livekit-server-sdk/src/AccessToken.ts | examples/api/src/main.rs