busy-breakfast-32623
08/10/2025, 7:14 PMtall-airline-16756
08/10/2025, 7:14 PMtall-airline-16756
08/10/2025, 7:14 PMlist_rooms
method from the RoomService client. It’ll give you a list of all the rooms currently active in your project.
Here’s a simple example in Python using the LiveKit SDK:
from livekit import api
from livekit.protocol.room import ListRoomsRequest
async def list_active_rooms():
lkapi = api.LiveKitAPI()
request = ListRoomsRequest(names=[])
rooms_response = await lkapi.room.list_rooms(request)
room_names = [room.name for room in rooms_response.rooms]
return room_names
# Example usage:
# rooms = await list_active_rooms()
# print(rooms)
This little snippet sets up the RoomService client, calls list_rooms
, and pulls out the names of all the active rooms for you. And if there aren’t any active rooms right now, you’ll just get back an empty list—nice and simple!
Sources: livekit/livekit_egress.pb.go | examples/api.py | packages/livekit-server-sdk/src/RoomServiceClient.tsbusy-breakfast-32623
08/10/2025, 7:16 PMtall-airline-16756
08/10/2025, 7:17 PMregisterTextStreamHandler
method to listen to the lk.chat
topic and grab messages as they come in. For example:
// Listen to chat messages and store them
room.registerTextStreamHandler('lk.chat', async (reader, participantInfo) => {
const { id, timestamp } = <http://reader.info|reader.info>;
for await (const chunk of reader) {
const message = {
id,
timestamp,
roomName: room.name,
sender: participantInfo?.identity,
content: chunk,
};
// Store the message in your database
await storeMessageInDatabase(message);
}
});
1. Store Messages: Save those captured messages in a database you like—Redis, PostgreSQL, MongoDB, whatever fits your setup—with details like message ID, timestamp, room name, sender, and content.
2. Retrieve Messages: Set up an API endpoint to pull messages from your database, filtering by room name or whatever criteria you need. Here’s an example:
// Example API route to fetch chat history
export async function GET(request: Request) {
const { roomName } = await request.json();
try {
const messages = await fetchMessagesFromDatabase(roomName);
return NextResponse.json(messages);
} catch (error) {
return NextResponse.json(
{ error: 'Failed to fetch messages' },
{ status: 500 }
);
}
}
With this setup, you’ll have a handy record of all chat messages across your LiveKit rooms. If you want to chat more about this or need a hand, just let me know—I’m here to help!
Sources: Sending text | LiveKit Docs | examples/demo/demo.ts | client/app/actions.ts | complex-agents/role-playing/role_playing_frontend/hooks/useChatAndTranscrip...