can i map room_id to room_name or room_name to roo...
# ask-ai
c
can i map room_id to room_name or room_name to room_id?
t
Thanks for reaching out, Subham. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Absolutely, room_id (SID) and room_name can definitely be mapped to each other in LiveKit. Both are part of the
Room
object and you can easily access them through server-side APIs or client SDKs. Here’s a simple way to map between them: • You can use the ListRooms API, which gives you a list of rooms including both
sid
(room_id) and
name
(room_name). • From the client SDKs, once you’re connected to a room, you can access
room.name
and
room.sid
(or their equivalents) at the same time. Just a quick heads-up: if you reuse the same
room_name
shortly after deleting a room, the same
room_id
might be reused as well. To keep things unique and avoid any confusion, it’s a good idea to use unique names when creating new rooms. Sources: Sources/LiveKit/Core/Room.swift | lib/livekit/proto/livekit_models_pb.rb | livekit/livekit_room.pb.go | src/room/Room.ts | livekit-rtc/livekit/rtc/_proto/room_pb2.py
Absolutely, you can map room_id (also known as sid) to room_name or the other way around in LiveKit. Both of these are part of the
Room
object and you can easily access them through the server-side APIs or client SDKs. Here’s how you can create this mapping: • Use the ListRooms API, which provides a list of rooms including both
sid
and
name
fields. • In the client SDKs, you can access the
Room
object directly, where both
room.name
and
room.sid
are available for your use. Just a quick heads-up: if you reuse the same
room_name
shortly after deleting a room, the same
room_id
might be reused. To keep things smooth and avoid any conflicts, it’s best to ensure the
room_name
is unique when creating new rooms.
c
give me an implemenation for the same using python sdk?
t
I'd love to share a helpful example with you! Here's how you can use the LiveKit Python SDK to map room_id (SID) to room_name:
Copy code
from livekit import api
import asyncio

async def map_room_id_to_name():
    # Initialize the LiveKit API client
    lkapi = api.LiveKitAPI()
    
    # List all active rooms
    rooms_response = await lkapi.room.list_rooms(api.ListRoomsRequest())
    
    # Create a mapping from room SID to room name
    room_mapping = {room.sid: room.name for room in rooms_response.rooms}
    
    print("Room ID (SID) to Room Name Mapping:", room_mapping)
    
    await lkapi.aclose()
    return room_mapping

# Run the async function
if __name__ == "__main__":
    asyncio.run(map_room_id_to_name())
Output Example:
Copy code
{
  "RM_abc123": "my-room",
  "RM_xyz789": "another-room"
}
This snippet uses the
list_rooms
method from the
RoomService
API to fetch all active rooms and neatly map each
sid
to its
name
. If you have any questions or want to explore this further, just let me know—I'm here to help! Sources: examples/api.py