how to get the room name on the client side?
# ask-ai
m
how to get the room name on the client side?
t
Thanks for reaching out, Austin. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Great question! You can easily get the room name on the client side by accessing the
name
property of the
Room
object. This works across several LiveKit SDKs, making it pretty straightforward. For instance, if you're working with the JavaScript/TypeScript SDK, you can do it like this:
Copy code
const roomName = room.name;
And if you're using React with
@livekit/components-react
, the
useRoomInfo
hook is super handy:
Copy code
const { name } = useRoomInfo();
If you'd like, I’m here to help with details for a specific SDK or anything else you might need. Just let me know! Sources: livekit-rtc/livekit/rtc/room.py | src/room/Room.ts | packages/react/src/components/RoomName.tsx | lib/src/core/room.dart | Sources/LiveKit/Core/Room.swift
m
the react native sdk
t
To help you retrieve the room name in the React Native SDK, you can easily access the
name
property of the
Room
object that comes from the
LiveKitRoom
component. Here’s a simple way to do it: 1. Make sure your component is nested inside the
LiveKitRoom
component so you can tap into the
Room
context. 2. Use the
useContext(RoomContext)
hook to grab the
Room
instance. 3. Then, just access the
name
property from the
Room
object. Here’s an example to guide you:
Copy code
import { LiveKitRoom, RoomContext } from '@livekit/react-native';
import { useContext } from 'react';

const MyApp = () => {
  return (
    
  );
};

const RoomNameDisplay = () => {
  // Access the Room object from context
  const room = useContext(RoomContext);
  // Access the room name using the name getter
  const roomName = room?.name ?? 'No Room Connected';

  return ;
};
If anything feels unclear or you want to dive deeper, just let me know—I’m here to help! Sources: docs/index.html | src/room/Room.ts | packages/react/src/components/LiveKitRoom.tsx