eager-window-33590
10/05/2025, 1:04 AMtall-airline-16756
10/05/2025, 1:04 AMtall-airline-16756
10/05/2025, 1:05 AMroom.on(RoomEvent.DataReceived, onData) event handler is perfect for receiving messages sent using send_text in LiveKit.
When data comes in from another participant, the DataReceived event is triggered. Messages sent with send_text are sent as data packets with the MIME type text/plain, and these packets are delivered to everyone in the room who’s listening for the DataReceived event.
If you’d like, I’m here to help with any further clarification or examples you might need!
Sources: test/core/data_stream_test.dart | livekit-rtc/livekit/rtc/room.py | src/room/events.ts | livekit/tests/data_stream_test.rs | livekit-android-test/src/test/java/io/livekit/android/room/RoomDataMockE2ET...eager-window-33590
10/05/2025, 1:26 AMtall-airline-16756
10/05/2025, 1:26 AMpublish_data is used in a LiveKit worker, the client-side event triggered is also DataReceived. This event is emitted on the Room object whenever data is received from another participant or the server.
You can listen for this event just like you would with send_text. For example, in the JavaScript SDK:
room.on('dataReceived', (payload, participant, topic) => {
console.log('Received data:', payload);
// Handle the received data
});
The topic field is really handy for filtering messages, and you can also target specific participants if that fits your needs. Please feel free to reach out if you'd like me to walk you through this further or if you have any other questions—I’m here to help!
Sources: Handling events | LiveKit Docs | src/room/participant/LocalParticipant.ts | Data packets | LiveKit Docseager-window-33590
10/05/2025, 1:28 AMtall-airline-16756
10/05/2025, 1:28 AMRoomEvent.DataReceived might not be triggering in your client code, along with some friendly debugging tips:
1. No Data Being Sent: First, please check if the worker or another participant is actively sending data using publish_data or a similar method.
2. Event Listener Not Subscribed: It’s important to make sure the DataReceived listener is properly attached to the Room object, either before or after connecting.
3. Room State Issues: Confirm that the room is fully connected before expecting data. You can subscribe to RoomEvent.Connected to keep track of the connection state.
4. Data Channel Not Established: Check if the WebRTC data channel has been set up correctly. Look out for any logs indicating the creation of the data channel.
5. Payload Format or Kind Mismatch: Make sure both sender and receiver are using compatible data kinds, like DataPacket_Kind.RELIABLE.
6. E2EE or Encryption Issues: If you’re using end-to-end encryption, please ensure the keys are configured properly. For testing, you might try temporarily disabling E2EE to see if that helps.
For a deeper dive, you can log the connection state, data channel status, and any incoming data packets. I’m here to help if you want to walk through specific debugging steps or need more details—just let me know!
Sources: src/room/Room.ts | Runtime/Scripts/Events.cs | Runtime/Scripts/Room.cs | Connecting to LiveKit | LiveKit Docs | Handling events | LiveKit Docs