Skip to content

Commit ac55b9d

Browse files
authored
feat: create DataPacket dataclass (#126)
1 parent 585a6c1 commit ac55b9d

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

livekit-api/livekit/api/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
# flake8: noqa
1919
# re-export packages from protocol
20-
from livekit.protocol.egress import *
21-
from livekit.protocol.ingress import *
22-
from livekit.protocol.models import *
23-
from livekit.protocol.room import *
24-
from livekit.protocol.webhook import *
20+
from livekit.protocol.egress import * # type: ignore
21+
from livekit.protocol.ingress import * # type: ignore
22+
from livekit.protocol.models import * # type: ignore
23+
from livekit.protocol.room import * # type: ignore
24+
from livekit.protocol.webhook import * # type: ignore
2525

2626
from .twirp_client import TwirpError, TwirpErrorCode
2727
from .livekit_api import LiveKitAPI

livekit-rtc/livekit/rtc/room.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ class RoomOptions:
7676
rtc_config: Optional[RtcConfiguration] = None
7777

7878

79+
@dataclass
80+
class DataPacket:
81+
data: bytes
82+
kind: proto_room.DataPacketKind.ValueType
83+
participant: Optional[
84+
RemoteParticipant
85+
] = None # None when the data has been sent by a server SDK
86+
topic: Optional[str] = None
87+
88+
7989
class ConnectError(Exception):
8090
def __init__(self, message: str):
8191
self.message = message
@@ -372,10 +382,12 @@ def _on_room_event(self, event: proto_room.RoomEvent):
372382
rparticipant = self.participants[event.data_received.participant_sid]
373383
self.emit(
374384
"data_received",
375-
data,
376-
event.data_received.kind,
377-
rparticipant,
378-
event.data_received.topic,
385+
DataPacket(
386+
data=data,
387+
kind=event.data_received.kind,
388+
participant=rparticipant,
389+
topic=event.data_received.topic,
390+
),
379391
)
380392
elif which == "e2ee_state_changed":
381393
sid = event.e2ee_state_changed.participant_sid

0 commit comments

Comments
 (0)