acceptable-dream-85180
07/29/2025, 6:54 PMtall-airline-16756
07/29/2025, 6:54 PMtall-airline-16756
07/29/2025, 6:55 PM@room.on("data_received") event handler is used to listen for data messages received from other participants or server SDKs in a LiveKit room.
Here is an example of its usage:
@room.on("data_received")
def on_data_received(data_packet: rtc.DataPacket):
<http://logging.info|logging.info>("received data from %s: %s", data_packet.participant.identity, data_packet.data)
The data_received event handler receives a DataPacket object with the following properties:
• data (bytes): The payload of the data packet
• kind (proto_room.DataPacketKind.ValueType): Type of the data packet (e.g., RELIABLE, LOSSY)
• participant (RemoteParticipant | None): Participant who sent the data. None when sent by a server SDK
• topic (str | None): Topic associated with the data packet
Below is a complete integration example showing how to set up the data_received event handler within a room connection:
import asyncio
import logging
from livekit import rtc
async def main(room: rtc.Room):
@room.on("data_received")
def on_data_received(data: rtc.DataPacket):
<http://logging.info|logging.info>("received data from %s: %s", data.participant.identity, data.data)
# Connect to room and other setup...
await room.connect(url, token) Sources: livekit-rtc/livekit/rtc/room.py