Skip to content

Commit

Permalink
feat: handle metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
theomonnom committed Sep 29, 2023
1 parent a9da597 commit ea6149f
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "client-sdk-rust"]
path = client-sdk-rust
path = rust-sdks
url = https://github.com/livekit/client-sdk-rust
1 change: 0 additions & 1 deletion client-sdk-rust
Submodule client-sdk-rust deleted from b968d3
7 changes: 4 additions & 3 deletions examples/basic_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import livekit

URL = 'ws://localhost:7880'
TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE5MDY2MTMyODgsImlzcyI6IkFQSVRzRWZpZFpqclFvWSIsIm5hbWUiOiJuYXRpdmUiLCJuYmYiOjE2NzI2MTMyODgsInN1YiI6Im5hdGl2ZSIsInZpZGVvIjp7InJvb20iOiJ0ZXN0Iiwicm9vbUFkbWluIjp0cnVlLCJyb29tQ3JlYXRlIjp0cnVlLCJyb29tSm9pbiI6dHJ1ZSwicm9vbUxpc3QiOnRydWV9fQ.uSNIangMRu8jZD5mnRYoCHjcsQWCrJXgHCs0aNIgBFY' # noqa
URL = 'wss://nativesdk.livekit.cloud'
TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MDQ2NzU5OTAsImlzcyI6IkFQSXM4eUdIS0FLZWYyWCIsIm5iZiI6MTY5NTY3NTk5MCwic3ViIjoiY2xpZW50IiwidmlkZW8iOnsiY2FuUHVibGlzaCI6dHJ1ZSwiY2FuUHVibGlzaERhdGEiOnRydWUsImNhblN1YnNjcmliZSI6dHJ1ZSwicm9vbSI6Im9haS1kZWJ1ZyIsInJvb21Kb2luIjp0cnVlfX0.Q7DYepLE1dIkl-ZAYwtFwnBFoInYUX9iuiNRZpiT1tE'


async def main(room: livekit.Room) -> None:
Expand Down Expand Up @@ -118,7 +118,8 @@ def on_reconnected() -> None:
logging.info("participants: %s", room.participants)

await asyncio.sleep(2)
await room.local_participant.publish_data("hello world")
await room.disconnect()
logging.info("disconnected")


if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions examples/e2ee.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

import livekit

URL = 'ws://localhost:7880'
TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE5MDY2MTMyODgsImlzcyI6IkFQSVRzRWZpZFpqclFvWSIsIm5hbWUiOiJuYXRpdmUiLCJuYmYiOjE2NzI2MTMyODgsInN1YiI6Im5hdGl2ZSIsInZpZGVvIjp7InJvb20iOiJ0ZXN0Iiwicm9vbUFkbWluIjp0cnVlLCJyb29tQ3JlYXRlIjp0cnVlLCJyb29tSm9pbiI6dHJ1ZSwicm9vbUxpc3QiOnRydWV9fQ.uSNIangMRu8jZD5mnRYoCHjcsQWCrJXgHCs0aNIgBFY' # noqa
URL = 'wss://nativesdk.livekit.cloud'
TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MDQ2NzU5OTAsImlzcyI6IkFQSXM4eUdIS0FLZWYyWCIsIm5iZiI6MTY5NTY3NTk5MCwic3ViIjoiY2xpZW50IiwidmlkZW8iOnsiY2FuUHVibGlzaCI6dHJ1ZSwiY2FuUHVibGlzaERhdGEiOnRydWUsImNhblN1YnNjcmliZSI6dHJ1ZSwicm9vbSI6Im9haS1kZWJ1ZyIsInJvb21Kb2luIjp0cnVlfX0.Q7DYepLE1dIkl-ZAYwtFwnBFoInYUX9iuiNRZpiT1tE'

# ("livekitrocks") this is our shared key, it must match the one used by your clients
SHARED_KEY = b"livekitrocks"
SHARED_KEY = b"password"


async def draw_cube(source: livekit.VideoSource):
Expand Down
152 changes: 140 additions & 12 deletions examples/publish_wave.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion generate_proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# This script requires protobuf-compiler and https://github.com/nipunn1313/mypy-protobuf

FFI_PROTOCOL=./client-sdk-rust/livekit-ffi/protocol
FFI_PROTOCOL=./rust-sdks/livekit-ffi/protocol
OUT_PYTHON=./livekit/_proto

protoc \
Expand Down
32 changes: 29 additions & 3 deletions livekit/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,43 @@ async def publish_data(self,
req.publish_data.destination_sids.extend(sids)

try:
queue = self._room_queue.subscribe()
queue = ffi_client.queue.subscribe()
resp = ffi_client.request(req)
cb = await queue.wait_for(lambda e: e.publish_data.async_id ==
resp.publish_data.async_id)
queue.task_done()
finally:
self._room_queue.unsubscribe(queue)
ffi_client.queue.unsubscribe(queue)

if cb.publish_data.error:
raise PublishDataError(cb.publish_data.error)

async def update_metadata(self, metadata: str) -> None:
req = proto_ffi.FfiRequest()
req.update_local_metadata.local_participant_handle = self._ffi_handle.handle
req.update_local_metadata.metadata = metadata

try:
queue = ffi_client.queue.subscribe()
resp = ffi_client.request(req)
cb = await queue.wait_for(lambda e: e.update_local_metadata.async_id ==
resp.update_local_metadata.async_id)
finally:
ffi_client.queue.unsubscribe(queue)

async def update_name(self, name: str) -> None:
req = proto_ffi.FfiRequest()
req.update_local_name.local_participant_handle = self._ffi_handle.handle
req.update_local_name.name = name

try:
queue = ffi_client.queue.subscribe()
resp = ffi_client.request(req)
cb = await queue.wait_for(lambda e: e.update_local_name.async_id ==
resp.update_local_name.async_id)
finally:
ffi_client.queue.unsubscribe(queue)


async def publish_track(self, track: Track, options: TrackPublishOptions) \
-> TrackPublication:
if not isinstance(track, LocalAudioTrack) \
Expand Down
27 changes: 22 additions & 5 deletions livekit/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@

@dataclass
class RtcConfiguration:
ice_transport_type: proto_room.IceTransportType = \
ice_transport_type: proto_room.IceTransportType.ValueType = \
proto_room.IceTransportType.TRANSPORT_ALL
continual_gathering_policy: proto_room.ContinualGatheringPolicy = \
continual_gathering_policy: proto_room.ContinualGatheringPolicy.ValueType = \
proto_room.ContinualGatheringPolicy.GATHER_CONTINUALLY
ice_servers: list[proto_room.IceServer] = field(default_factory=list)

Expand Down Expand Up @@ -274,12 +274,29 @@ def _on_room_event(self, event: proto_room.RoomEvent):
speakers.append(self._retrieve_participant(sid))

self.emit('active_speakers_changed', speakers)
elif which == 'room_metadata_changed':
old_metadata = self.metadata
self._info.metadata = event.room_metadata_changed.metadata
self.emit('room_metadata_changed', old_metadata, self.metadata)
elif which == 'participant_metadata_changed':
sid = event.participant_metadata_changed.participant_sid
participant = self._retrieve_participant(sid)
old_metadata = participant.metadata
participant._info.metadata = event.participant_metadata_changed.metadata
self.emit('participant_metadata_changed',
participant, old_metadata, participant.metadata)
elif which == 'participant_name_changed':
sid = event.participant_name_changed.participant_sid
participant = self._retrieve_participant(sid)
old_name = participant.name
participant._info.name = event.participant_name_changed.name
self.emit('participant_name_changed',
participant, old_name, participant.name)
elif which == 'connection_quality_changed':
sid = event.connection_quality_changed.participant_sid
p = self._retrieve_participant(sid)

participant = self._retrieve_participant(sid)
self.emit('connection_quality_changed',
p, event.connection_quality_changed.quality)
participant, event.connection_quality_changed.quality)
elif which == 'data_received':
rparticipant = self.participants[event.data_received.participant_sid]
owned_buffer_info = event.data_received.data
Expand Down
1 change: 1 addition & 0 deletions rust-sdks
Submodule rust-sdks added at d7ec6f
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BuildPyCommand(setuptools.command.build_py.build_py):

def run(self):

download_script = here / 'client-sdk-rust' / 'download_ffi.py'
download_script = here / 'rust-sdks' / 'download_ffi.py'
cmd = ['python3', download_script.absolute(), '--output',
'livekit/resources']

Expand Down

0 comments on commit ea6149f

Please sign in to comment.