How can i gst the current active room metadata ?
# ask-ai
s
How can i gst the current active room metadata ?
t
Thanks for reaching out, Mostafa. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your question about how to get the current active room metadata. Short answer • From a client (browser / mobile): don’t rely on reading
room.metadata
immediately after connect. Listen for the
room_metadata_changed
event and use that value. If
room.metadata
is already set after connect, you can use it; otherwise wait for the event. • From a server: call the RoomService API (e.g.,
getRoom
) to fetch the room object and read its
metadata
for an up-to-date value. How to implement 1) Client-side (recommended event-driven approach) • Subscribe to the event that fires when room metadata changes:
Copy code
room.on("room_metadata_changed", (metadata) => {
  console.log("Room metadata updated:", metadata);
  // handle metadata here
});
• On connect, check
room.metadata
once. If it’s empty or stale, wait for the
room_metadata_changed
event. Example pattern:
Copy code
if (room.metadata) {
  handleMetadata(room.metadata);
} else {
  room.once("room_metadata_changed", (metadata) => handleMetadata(metadata));
}
This avoids races caused by asynchronous propagation of metadata updates. 2) Server-side (direct, synchronous read) • Use the RoomService / server SDK to fetch the room state and read
metadata
. Example (pseudo/Node-style):
Copy code
const room = await roomService.getRoom("room-name");
console.log(room.metadata);
The server call queries the LiveKit server state and returns the current metadata immediately. Why this matters • Metadata updates are asynchronous and may not reach a client instantly after connect, especially across regions. Listening for
room_metadata_changed
ensures you receive the latest value reliably. • The server API provides a direct read if you need synchronous access (for admin dashboards, workflows, etc.). If you want, tell me: • Which SDK you’re using (browser JS, iOS, Android, Python, server JS), and I’ll give a concise code snippet tailored to that environment. • Whether you need handling for initial connect only or continuous updates for the session. Sources: Handling asynchronous metadata updates in LiveKit | LiveKit | server-sdk-js | livekit/livekit_composite | DeepWiki
s
Does the metadate contains the timeout? I want to make sure that configured the timeout correctly
t
Thanks — I’m replying about whether room metadata contains a timeout and how to confirm your timeout is set correctly. Short answer • Room metadata does not include timeout values by default. Timeouts (like user inactivity or room-empty timeouts) are separate configuration settings and aren’t automatically stored in room metadata. • If you want clients or agents to read the timeout from within the room, you must explicitly add the timeout value to the room metadata when creating or updating the room. What you can do now 1. Confirm which timeout you mean: ◦ Agent/user inactivity (e.g.,
user_away_timeout
) ◦ Room empty/idle timeout (e.g.,
empty_timeout
) ◦ Connection or signaling timeouts Tell me which one and I’ll give targeted steps. 1. If you want the timeout visible to clients/agents, add it to room metadata when creating or updating the room. Example pattern (pseudo):
Copy code
// server: include timeout in metadata when creating/updating the room
await roomService.updateRoom({
  name: "room-name",
  metadata: JSON.stringify({ user_away_timeout: 10 }) // seconds
});
Then clients can read it via
room.metadata
or listen for
room_metadata_changed
. 1. To verify the timeout is configured correctly (depending on which timeout): ◦ For agent/user inactivity: check the place it’s set (e.g., AgentSession constructor) and confirm the value (seconds). ◦ For room empty timeout: check the RoomService create/update call that sets
empty_timeout
. ◦ If you added the timeout to metadata: confirm the metadata contains the expected value after creation (or wait for
room_metadata_changed
on clients). If you tell me which timeout you’re verifying and which SDK/environment you’re using (server SDK, browser JS, Agent code, etc.), I’ll provide the exact code snippet and a short checklist to confirm it’s applied correctly. Sources: Handling asynchronous metadata updates in LiveKit | LiveKit | Job lifecycle | LiveKit Documentation | How to detect and handle silence during calls | LiveKit | How to implement call greeting retries in voice agents | LiveKit | server-sdk-ruby | livekit/livekit_composite | DeepWiki