<@U06LSEPH77D> help me understand this so i have ...
# ask-ai
r
@alert-easter-19258 help me understand this so i have a Redis queue worker that runs in a different server, in that worker i need to send back the result of a function back to the livekit room event handlers # Example worker code
Copy code
lkapi = api.LiveKitAPI()
data_payload = {
                "type": "perception_result",
                "analysis": analysis.model_dump(),
            }
json_data = json.dumps(data_payload).encode("utf-8")
await lkapi.room.send_data(
                    send=api.SendDataRequest(
                        room=task_context.room_name,
                        data=json_data,
                        kind="LOSSY",
                    )
                )
Then in the livekit room, i have it this way
Copy code
ctx.room.on("data_received", on_data_received) # i logged the result of the callback
but funny thing is, i dont see the log in the livekit room with payload, but i see the log from other services eg. tavus, what could be the problem? ive ensured that im sending it to the right room
t
Thanks for reaching out, Navicstein. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Let's work together to figure out why your Redis queue worker's data isn't showing up in the LiveKit room logs. Here are a few friendly steps to guide you: • First, double-check that the
send_data
method is correctly targeting the right room name and using the right delivery mode, like "LOSSY". • Make sure the
on_data_received
event handler is properly set up in the room and is actively listening for any incoming data. • Take a moment to verify that the data payload is formatted and encoded correctly before it’s sent to the room. • Also, confirm that both the Redis worker and the LiveKit room are connected and running smoothly when you’re sending the data. • It might help to test the
send_data
functionality using the LiveKit CLI. This can help us see if the issue is with the worker or the room setup. If you try these steps and things still aren't working, please don’t hesitate to share more details like the room name, worker logs, or any error messages you’re seeing. I’m here to help you through this! Sources: internal/bus/bus_redis.go | agent-console/app/api/room/send-data/route.ts | cmd/lk/room.go | Agent Testing & CI/CD | livekit/livekit_composite | DeepWiki | livekit-ffi/src/server/room.rs
r
ok so funny enough im seeing the logs in the frontend client, something like this - which means the queue is sending the right data
Copy code
room event dataReceived 
{
    "room": "oculsus_5580f7",
    "roomID": "RM_SGgXtPiDhCYN",
    "participant": "user-oculus",
    "pID": "PA_WLqYbkmRfrg7",
    "event": "dataReceived",
    "args": [
        "lk-chat-topic"
    ]
}
but here's confusing me, i can see other services "data_received" room callbacks in the server logs but not the one from the queue ive even i changed the kind to
RELIABLE
and changed the destination entities
Copy code
await lkapi.room.send_data(
    send=api.SendDataRequest(
    room=task_context.room_name,
    data=json.dumps(analysis_dict).encode("utf-8"),
    kind="RELIABLE", 
    destination_identities=[task_context.agent_identity, task_context.user_identity],
    )
)
t
Thanks for reaching out! The
data_received
event is something that happens on the client side when a participant gets a data packet through the LiveKit SDKs. It’s not automatically logged by the LiveKit server, which is why you might notice it on the frontend but not see it in the server logs. To help you check the data flow on the server side, here are a few friendly tips: • You can turn on
debug
logging in the LiveKit server settings to get a closer look at how messages are routed internally. • Keep an eye on Redis channels directly to make sure data packets are being sent and routed as expected. • Try logging the payload structure in your Redis worker to confirm everything looks right. If you’d like, I’m here to help you step-by-step with enabling debug logs or checking the Redis message flow. Just let me know! Sources: livekit-rtc/livekit/rtc/room.py | config-sample.yaml | Data packets | LiveKit docs | agent-console/lib/event-definitions.tsx | lib/src/events.dart
r
show me an example of how to use the
lkapi.room.send_data
and also the callback
t
Here’s a friendly example to help you use
lkapi.room.send_data
for sending data to a LiveKit room and managing the
data_received
callback: Sending Data
Copy code
await lkapi.room.send_data(
    send=api.SendDataRequest(
        room="room_name",
        data=json.dumps({"key": "value"}).encode("utf-8"),
        kind="RELIABLE",  # or "LOSSY"
        destination_identities=["participant1", "participant2"]  # Optional
    )
)
This will send a JSON payload to the room you specify. You have the option to pick
RELIABLE
for guaranteed delivery, or
LOSSY
if you prefer faster transmission without a delivery guarantee. Handling the Callback On the client side, you can easily listen for the
data_received
event like this:
Copy code
@room.on("data_received")
def on_data_received(data):
    print(f"Received data: {data}")
This way, you’ll see the received data logged whenever a packet arrives in the room. If you have any questions or would like me to walk you through more examples, just let me know—I’m here to help! Sources: Data packets | LiveKit docs | src/test/kotlin/io/livekit/server/RoomServiceClientTest.kt | cmd/lk/room.go | callback_test.go