Skip to content

Commit

Permalink
feat: create DataPacket dataclass (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
theomonnom authored Dec 19, 2023
1 parent 585a6c1 commit ac55b9d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
10 changes: 5 additions & 5 deletions livekit-api/livekit/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

# flake8: noqa
# re-export packages from protocol
from livekit.protocol.egress import *
from livekit.protocol.ingress import *
from livekit.protocol.models import *
from livekit.protocol.room import *
from livekit.protocol.webhook import *
from livekit.protocol.egress import * # type: ignore
from livekit.protocol.ingress import * # type: ignore
from livekit.protocol.models import * # type: ignore
from livekit.protocol.room import * # type: ignore
from livekit.protocol.webhook import * # type: ignore

from .twirp_client import TwirpError, TwirpErrorCode
from .livekit_api import LiveKitAPI
Expand Down
20 changes: 16 additions & 4 deletions livekit-rtc/livekit/rtc/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ class RoomOptions:
rtc_config: Optional[RtcConfiguration] = None


@dataclass
class DataPacket:
data: bytes
kind: proto_room.DataPacketKind.ValueType
participant: Optional[
RemoteParticipant
] = None # None when the data has been sent by a server SDK
topic: Optional[str] = None


class ConnectError(Exception):
def __init__(self, message: str):
self.message = message
Expand Down Expand Up @@ -372,10 +382,12 @@ def _on_room_event(self, event: proto_room.RoomEvent):
rparticipant = self.participants[event.data_received.participant_sid]
self.emit(
"data_received",
data,
event.data_received.kind,
rparticipant,
event.data_received.topic,
DataPacket(
data=data,
kind=event.data_received.kind,
participant=rparticipant,
topic=event.data_received.topic,
),
)
elif which == "e2ee_state_changed":
sid = event.e2ee_state_changed.participant_sid
Expand Down

0 comments on commit ac55b9d

Please sign in to comment.