Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rust ffi #217

Merged
merged 24 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async def main():
# participants and tracks that are already available in the room
# participant_connected and track_published events will *not* be emitted for them
for participant in room.participants.items():
for publication in participant.tracks.items():
for publication in participant.track_publications.items():
print("track publication: %s", publication.sid)
```

Expand Down
2 changes: 1 addition & 1 deletion examples/basic_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def on_reconnected() -> None:
)
await room.connect(os.getenv("LIVEKIT_URL"), token)
logging.info("connected to room %s", room.name)
logging.info("participants: %s", room.participants)
logging.info("participants: %s", room.remote_participants)

await asyncio.sleep(2)
await room.local_participant.publish_data("hello world")
Expand Down
71 changes: 71 additions & 0 deletions examples/participant_attributes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import asyncio
import logging
from signal import SIGINT, SIGTERM
import os

from livekit import api, rtc

# ensure LIVEKIT_URL, LIVEKIT_API_KEY, and LIVEKIT_API_SECRET are set


async def main(room: rtc.Room) -> None:
token = (
api.AccessToken()
.with_identity("python-bot")
.with_name("Python Bot")
.with_grants(
api.VideoGrants(
room_join=True,
room="my-room",
can_update_own_metadata=True,
)
)
.to_jwt()
)

@room.on("participant_attributes_changed")
def on_participant_attributes_changed(
changed_attributes: dict[str, str], participant: rtc.Participant
):
logging.info(
"participant attributes changed: %s %s",
participant.attributes,
changed_attributes,
)

await room.connect(os.getenv("LIVEKIT_URL"), token)
logging.info("connected to room %s", room.name)

# Create an attribute
await room.local_participant.set_attributes({"foo": "bar"})
# Delete an attribute
await room.local_participant.set_attributes({"foo": ""})

# Create another attribute
await room.local_participant.set_attributes({"baz": "qux"})

# Update an attribute
await room.local_participant.set_attributes({"baz": "biz"})


if __name__ == "__main__":
logging.basicConfig(
level=logging.INFO,
handlers=[logging.FileHandler("basic_room.log"), logging.StreamHandler()],
)

loop = asyncio.get_event_loop()
room = rtc.Room(loop=loop)

async def cleanup():
await room.disconnect()
loop.stop()

asyncio.ensure_future(main(room))
for signal in [SIGINT, SIGTERM]:
loop.add_signal_handler(signal, lambda: asyncio.ensure_future(cleanup()))

try:
loop.run_forever()
finally:
loop.close()
5 changes: 4 additions & 1 deletion livekit-protocol/generate_proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ protoc \
$API_PROTOCOL/livekit_ingress.proto \
$API_PROTOCOL/livekit_models.proto \
$API_PROTOCOL/livekit_agent.proto \
$API_PROTOCOL/livekit_agent_dispatch.proto \
$API_PROTOCOL/livekit_sip.proto \
$API_PROTOCOL/livekit_analytics.proto

Expand Down Expand Up @@ -58,11 +59,13 @@ mv "$API_OUT_PYTHON/livekit_models_pb2.py" "$API_OUT_PYTHON/models.py"
mv "$API_OUT_PYTHON/livekit_models_pb2.pyi" "$API_OUT_PYTHON/models.pyi"
mv "$API_OUT_PYTHON/livekit_agent_pb2.py" "$API_OUT_PYTHON/agent.py"
mv "$API_OUT_PYTHON/livekit_agent_pb2.pyi" "$API_OUT_PYTHON/agent.pyi"
mv "$API_OUT_PYTHON/livekit_agent_dispatch_pb2.py" "$API_OUT_PYTHON/agent_dispatch.py"
mv "$API_OUT_PYTHON/livekit_agent_dispatch_pb2.pyi" "$API_OUT_PYTHON/agent_dispatch.pyi"
mv "$API_OUT_PYTHON/livekit_analytics_pb2.py" "$API_OUT_PYTHON/analytics.py"
mv "$API_OUT_PYTHON/livekit_analytics_pb2.pyi" "$API_OUT_PYTHON/analytics.pyi"
mv "$API_OUT_PYTHON/livekit_sip_pb2.py" "$API_OUT_PYTHON/sip.py"
mv "$API_OUT_PYTHON/livekit_sip_pb2.pyi" "$API_OUT_PYTHON/sip.pyi"

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
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

perl -i -pe 's|livekit_(\w+)_pb2|${1}|g' "$API_OUT_PYTHON"/*.py "$API_OUT_PYTHON"/*.pyi
80 changes: 41 additions & 39 deletions livekit-protocol/livekit/protocol/agent.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading