Skip to content

Commit 821d4bf

Browse files
Update rust ffi (#217)
1 parent 4063504 commit 821d4bf

27 files changed

+1190
-574
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ async def main():
108108
# participants and tracks that are already available in the room
109109
# participant_connected and track_published events will *not* be emitted for them
110110
for participant in room.participants.items():
111-
for publication in participant.tracks.items():
111+
for publication in participant.track_publications.items():
112112
print("track publication: %s", publication.sid)
113113
```
114114

examples/basic_room.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def on_reconnected() -> None:
139139
)
140140
await room.connect(os.getenv("LIVEKIT_URL"), token)
141141
logging.info("connected to room %s", room.name)
142-
logging.info("participants: %s", room.participants)
142+
logging.info("participants: %s", room.remote_participants)
143143

144144
await asyncio.sleep(2)
145145
await room.local_participant.publish_data("hello world")

examples/participant_attributes.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import asyncio
2+
import logging
3+
from signal import SIGINT, SIGTERM
4+
import os
5+
6+
from livekit import api, rtc
7+
8+
# ensure LIVEKIT_URL, LIVEKIT_API_KEY, and LIVEKIT_API_SECRET are set
9+
10+
11+
async def main(room: rtc.Room) -> None:
12+
token = (
13+
api.AccessToken()
14+
.with_identity("python-bot")
15+
.with_name("Python Bot")
16+
.with_grants(
17+
api.VideoGrants(
18+
room_join=True,
19+
room="my-room",
20+
can_update_own_metadata=True,
21+
)
22+
)
23+
.to_jwt()
24+
)
25+
26+
@room.on("participant_attributes_changed")
27+
def on_participant_attributes_changed(
28+
changed_attributes: dict[str, str], participant: rtc.Participant
29+
):
30+
logging.info(
31+
"participant attributes changed: %s %s",
32+
participant.attributes,
33+
changed_attributes,
34+
)
35+
36+
await room.connect(os.getenv("LIVEKIT_URL"), token)
37+
logging.info("connected to room %s", room.name)
38+
39+
# Create an attribute
40+
await room.local_participant.set_attributes({"foo": "bar"})
41+
# Delete an attribute
42+
await room.local_participant.set_attributes({"foo": ""})
43+
44+
# Create another attribute
45+
await room.local_participant.set_attributes({"baz": "qux"})
46+
47+
# Update an attribute
48+
await room.local_participant.set_attributes({"baz": "biz"})
49+
50+
51+
if __name__ == "__main__":
52+
logging.basicConfig(
53+
level=logging.INFO,
54+
handlers=[logging.FileHandler("basic_room.log"), logging.StreamHandler()],
55+
)
56+
57+
loop = asyncio.get_event_loop()
58+
room = rtc.Room(loop=loop)
59+
60+
async def cleanup():
61+
await room.disconnect()
62+
loop.stop()
63+
64+
asyncio.ensure_future(main(room))
65+
for signal in [SIGINT, SIGTERM]:
66+
loop.add_signal_handler(signal, lambda: asyncio.ensure_future(cleanup()))
67+
68+
try:
69+
loop.run_forever()
70+
finally:
71+
loop.close()

livekit-protocol/generate_proto.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ protoc \
3131
$API_PROTOCOL/livekit_ingress.proto \
3232
$API_PROTOCOL/livekit_models.proto \
3333
$API_PROTOCOL/livekit_agent.proto \
34+
$API_PROTOCOL/livekit_agent_dispatch.proto \
3435
$API_PROTOCOL/livekit_sip.proto \
3536
$API_PROTOCOL/livekit_analytics.proto
3637

@@ -58,11 +59,13 @@ mv "$API_OUT_PYTHON/livekit_models_pb2.py" "$API_OUT_PYTHON/models.py"
5859
mv "$API_OUT_PYTHON/livekit_models_pb2.pyi" "$API_OUT_PYTHON/models.pyi"
5960
mv "$API_OUT_PYTHON/livekit_agent_pb2.py" "$API_OUT_PYTHON/agent.py"
6061
mv "$API_OUT_PYTHON/livekit_agent_pb2.pyi" "$API_OUT_PYTHON/agent.pyi"
62+
mv "$API_OUT_PYTHON/livekit_agent_dispatch_pb2.py" "$API_OUT_PYTHON/agent_dispatch.py"
63+
mv "$API_OUT_PYTHON/livekit_agent_dispatch_pb2.pyi" "$API_OUT_PYTHON/agent_dispatch.pyi"
6164
mv "$API_OUT_PYTHON/livekit_analytics_pb2.py" "$API_OUT_PYTHON/analytics.py"
6265
mv "$API_OUT_PYTHON/livekit_analytics_pb2.pyi" "$API_OUT_PYTHON/analytics.pyi"
6366
mv "$API_OUT_PYTHON/livekit_sip_pb2.py" "$API_OUT_PYTHON/sip.py"
6467
mv "$API_OUT_PYTHON/livekit_sip_pb2.pyi" "$API_OUT_PYTHON/sip.pyi"
6568

66-
perl -i -pe 's|^(import (livekit_egress_pb2\|livekit_room_pb2\|livekit_webhook_pb2\|livekit_ingress_pb2\|livekit_models_pb2\|livekit_agent_pb2\|livekit_analytics_pb2\|livekit_sip_pb2))|from . $1|g' "$API_OUT_PYTHON"/*.py "$API_OUT_PYTHON"/*.pyi
69+
perl -i -pe 's|^(import (livekit_egress_pb2\|livekit_room_pb2\|livekit_webhook_pb2\|livekit_ingress_pb2\|livekit_models_pb2\|livekit_agent_pb2\|livekit_agent_dispatch_pb2\|livekit_analytics_pb2\|livekit_sip_pb2))|from . $1|g' "$API_OUT_PYTHON"/*.py "$API_OUT_PYTHON"/*.pyi
6770

6871
perl -i -pe 's|livekit_(\w+)_pb2|${1}|g' "$API_OUT_PYTHON"/*.py "$API_OUT_PYTHON"/*.pyi

livekit-protocol/livekit/protocol/agent.py

Lines changed: 41 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)