How to pass custom data to Livekit room in react n...
# ask-ai
f
How to pass custom data to Livekit room in react native
t
Thanks for reaching out, venu. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you want to pass custom data to a LiveKit room in React Native, here are a couple of friendly ways to do it: • Room Metadata: You can set up some shared, persistent info for the whole room using server-side APIs like
CreateRoom
or
UpdateRoomMetadata
. Everyone who joins the room will be able to access this data. If you want to dive deeper, check out the Room Metadata documentation. • Data Messages: For sending data in real-time, try using data messages with
useDataChannel
from the
@livekit/react-native
SDK. This lets participants chat data back and forth after joining. You can find more info in the Data Messages documentation. Just a heads up: you can’t pass custom data directly as a prop to
LiveKitRoom
in React Native. But don’t worry, these methods will help you get exactly what you need! Sources: Data messages | LiveKit Docs | Room metadata | LiveKit Docs | example/src/RoomPage.tsx | Room metadata | LiveKit Docs
f
I want to pass data inside this - <_LiveKitRoom_ audio={true} video={false} token={details.token} serverUrl={details.url} onConnected={() => {}} > <_LKRoom_ /> </_LiveKitRoom_>
t
Hey there! Just a quick heads-up: the
LiveKitRoom
component in React Native doesn’t let you pass custom data directly as props. But no worries—you can still share your custom data with child components inside
LiveKitRoom
using some common React techniques: • Using External State: You can keep your custom data in the parent component with
useState
and then pass it down to the children inside
LiveKitRoom
. • Using React Context: Another neat way is to create a context that shares your custom data across all components inside
LiveKitRoom
. • Forwarding Data: Or wrap
LiveKitRoom
in a parent component that passes the needed data along to its children. Here’s a quick example to give you an idea:
Copy code
function App() {
  const [customData, setCustomData] = useState({ userName: 'Alice', userId: '123' });

  return (
    <LiveKitRoom serverUrl={url} token={token} connect={true}>
      <MyComponent customData={customData} onDataChange={setCustomData} />
    </LiveKitRoom>
  );
}
If you want, I’m here to help you work through this or anything else you might need! Sources: example/src/RoomPage.tsx | client/components/livekit/room.tsx | Stream music over WebRTC using React and WebAudio | ios/LiveKitReactNativeMeet/AppDelegate.mm
f
lk cloud auth Saved CLI config to /Users/venuchoudhary/.livekit/cli-config.yaml Device: macbookair@venu Requesting verification token... Please confirm access by visiting: https://cloud.livekit.io/cli/confirm-auth?t=5aa77e1c-d294-4b08-ba38-30e6f172918e ┃ Project name already exists, please choose a different name ┃ > Evi user aborted why is this happening I want to deploy an agent to Evi project but I am not able to
t
Hey there! The error message "Project name already exists, please choose a different name" pops up because the LiveKit CLI has found a project name clash in your local configuration. Basically, it means you already have a project with that name saved in your CLI setup. Here’s how you can fix it: 1. First, run
lk project list
to see all the projects you currently have configured. 2. If you spot the project name you want to use, you have two options: ◦ Set that existing project as your default by running
lk project set-default <project_name>
. ◦ Or, simply pick a different name when you go through the
lk cloud auth
process and it asks you for a project name. Feel free to reach out if you want me to walk you through any of these steps or if something’s still unclear! Sources: Deploying to production | LiveKit Docs | README.md
f
when I enter project name it says project already exists choose different nament
t
Hey there! If the CLI asks you to pick a different name because the project already exists, it just means that project is already set up in your local CLI. Here’s what you can do: 1. Run
lk project list
to see all the projects you’ve got configured. 2. If you spot the project you want, set it as the default by running
lk project set-default <project_name>
. 3. If you’re looking to create a new setup for the same project, just enter a unique alias (like
Evi-2
) when it asks you to choose a different name. If you hit any snags or have questions, just give me a shout—I’m here to help!
f
lk agent create Using project [evi] Using agent configuration [livekit.toml] Creating new agent Using secrets file [.env] panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x2 addr=0x8 pc=0x101b2d524] goroutine 1 [running]: main.getClientSettings({0x10336a578, 0x1400035c690}, 0x0) github.com/livekit/livekit-cli/v2/cmd/lk/agent.go:1185 +0x1a4 main.createAgent({0x10336a578, 0x1400035c690}, 0x1041ce520) github.com/livekit/livekit-cli/v2/cmd/lk/agent.go:375 +0x650 github.com/urfave/cli/v3.(*Command).run(0x1041ce520, {0x10336a578, 0x1400035c690}, {0x140005307e0, 0x1, 0x1}) github.com/urfave/cli/v3@v3.3.8/command_run.go:340 +0x1cf0 github.com/urfave/cli/v3.(*Command).run(0x1041ce2a0, {0x10336a578, 0x1400035c570}, {0x1400053ba80, 0x2, 0x2}) github.com/urfave/cli/v3@v3.3.8/command_run.go:278 +0x1758 github.com/urfave/cli/v3.(*Command).run(0x140003f3188, {0x10336a578, 0x14000534120}, {0x1400004e090, 0x3, 0x3}) github.com/urfave/cli/v3@v3.3.8/command_run.go:278 +0x1758 github.com/urfave/cli/v3.(*Command).Run(...) github.com/urfave/cli/v3@v3.3.8/command_run.go:94 main.main() github.com/livekit/livekit-cli/v2/cmd/lk/main.go:90 +0xcdc
t
Hey there! That pesky error "panic: runtime error: invalid memory address or nil pointer dereference" popping up during
lk agent create
usually happens because of one of these reasons: • Existing
livekit.toml
file:
Make sure you’re running the command in a folder that doesn’t already have a
livekit.toml
file. This command is meant for creating new agents, so having an existing config can cause conflicts. • Invalid project URL: Double-check that your LiveKit project URL is correct and properly formatted. If the URL isn’t right, the CLI can trip up when trying to extract the subdomain. • Authentication issues: Take a moment to verify your API key and secret. If these aren’t set up correctly, the CLI can’t get the agent client up and running. • CLI version: Make sure you’re using the latest LiveKit CLI version — updates often fix bugs like this. Here’s what you can try to fix it: 1. Delete any existing
livekit.toml
file in your current directory. 2. Carefully check your project URL, API key, and secret to make sure they’re spot on. 3. Run the command with the
--silent
flag to skip any interactive prompts. 4. Update your LiveKit CLI to the newest version available. If you hit any snags or want a hand, just let me know — I’m here to help! Sources: Agent deployment CLI reference | LiveKit Docs | cmd/lk/sip.go
f
class Evi(Agent): def __init__(self) -> None: super().__init__(instructions=instructions) self.paused: bool = False async def on_enter(self) -> None: if not self.paused: await self.session.generate_reply( instructions="Start the session" ) async def on_exit(self) -> None: return await super().on_exit() Here if I remove the on_enter(), will it still greet the user if the instructions contain that greet the user
t
Just a heads-up: if you remove the
on_enter()
method from your LiveKit agent class, the agent won’t greet the user—even if your instructions say it should. That’s because
on_enter()
is what kicks off those first actions, like saying hello when the agent starts a session. If you want your agent to give a friendly greeting, you’ll need to have
on_enter()
in place and make sure it calls
self.session.generate_reply()
or
self.session.say()
to actually send that greeting out. Feel free to reach out if you want a hand tweaking your setup—I’m here to help! Sources: Pipeline nodes and hooks | LiveKit Docs | pipeline-tts/rime_tts.py | Company directory phone assistant | LiveKit Docs | Workflows | LiveKit Docs
f
but I want the agent to greet according to the instructions
t
Hey there! If you want the agent to greet the user following the instructions, you just need to make sure the greeting gets triggered explicitly. The
on_enter()
method is the perfect spot for this since it runs when the agent becomes active in a session. Here’s a simple way to set up `on_enter()`:
Copy code
async def on_enter(self) -> None:
    await self.session.generate_reply(
        instructions=self.instructions
    )
This way, the agent will generate a reply based on your instructions, including a friendly greeting if you’ve added one. Without using
on_enter()
, the agent won’t automatically say hello, even if the instructions suggest it. If you want me to walk you through this or have any other questions, just let me know—I’m here to help!