can I call `await roomService.deleteRoom(ctx.job.r...
# ask-ai
h
can I call
await roomService.deleteRoom(ctx.job.room?.name);
before the session starts? second question: before the session starts and before ctx.connect is called, can I send message via
ctx.room.localParticipant.publishData()
?
t
Thanks for reaching out, Pavel. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Absolutely, you can go ahead and call
await roomService.deleteRoom(ctx.job.room?.name);
before the session starts. This is a great way to tidy up any rooms that were set up in advance but aren’t needed anymore, even if no one has joined yet. That said, when it comes to sending messages with
ctx.room.localParticipant.publishData()
, you’ll need to wait until after
ctx.connect
has been called. The connection has to be fully established first because the
localParticipant
object and data channel only become ready once
ctx.connect
finishes. Sources: Inside a session | LiveKit Docs | packages/livekit-rtc/src/room.ts | livekit-rtc/livekit/rtc/participant.py | livekit-ffi/src/server/room.rs
h
so when something goes wrong (I mean for example business logic) before
ctx.connect
is called, I need to find another way (other than ctx.room.localParticipant.publishData()) how to let front end know about that and display error message, right?
t
Absolutely, if something goes wrong before
ctx.connect
is called, it’s important to have another way to let the frontend know and show an error message. Here are a couple of friendly approaches you can try: • Client-Side Errors: For things like media device access issues, you can use event listeners such as
RoomEvent.MediaDevicesError
or the
onMediaDeviceFailure
prop in the LiveKit React components. These help you catch and display errors right away, keeping your users informed. • Server-Side Errors: If errors happen in your business logic before
ctx.connect
, wrapping your code in a
try/catch
block and logging the errors on the server is a great start. Then, you can notify the frontend through API callbacks, WebSocket messages, or even some pre-checks in your frontend code to keep everything smooth. If you’d like, I’m here to help with more details or examples on how to set any of these up—just let me know! Sources: src/api/SignalClient.ts | External data and RAG | LiveKit Docs | External data and RAG | LiveKit Docs | complex-agents/nutrition-assistant/nutrition-assistant-frontend/app/page.ts... | components/app.tsx
h
I think I can call some business logic before I ask for a livekit token on frontend, but in that case I need to send a lot of data through metadata in
new RoomAgentDispatch
, for example several larger objects, is there some limit for how much data I can send through metadata?
t
Just to let you know, the metadata size limit for LiveKit rooms and participants is 64 KiB. This applies to the
metadata
field for both rooms and participants, as well as to participant attributes (which includes the combined size of all keys and values). If you find yourself needing to send larger data, a helpful approach would be to store that data externally—like in a database or cloud storage—and then include a reference (such as a URL or ID) in the metadata. This way, everything stays smooth and efficient! Sources: Participant attributes and metadata | LiveKit Docs