Skip to content

Commit 2fad7c6

Browse files
committed
Merge remote-tracking branch 'origin/main' into typester/audio-filter-plugin
2 parents 781c8e0 + fe1d072 commit 2fad7c6

37 files changed

+1433
-365
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
**/*.dll filter=lfs diff=lfs merge=lfs -text
22
**/*.so filter=lfs diff=lfs merge=lfs -text
33
**/*.dylib filter=lfs diff=lfs merge=lfs -text
4+
**/*.jpg filter=lfs diff=lfs merge=lfs -text
45
livekit-protocol/livekit/protocol/** linguist-generated=true
56
livekit-rtc/livekit/rtc/_proto/** linguist-generated=true

.github/banner_dark.png

-72.6 KB
Loading

.github/banner_light.png

-13.2 KB
Loading

.github/workflows/check-types.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
run: python -m pip install --upgrade mypy
3030

3131
- name: Install packages
32-
run: python -m pip install pytest ./livekit-api ./livekit-protocol ./livekit-rtc
32+
run: python -m pip install pytest ./livekit-api ./livekit-protocol ./livekit-rtc pydantic
3333

3434
- name: Check Types
3535
run: python -m mypy --install-type --non-interactive -p 'livekit-protocol' -p 'livekit-api' -p 'livekit-rtc'

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ jobs:
2323
- name: Run tests
2424
run: |
2525
python3 ./livekit-rtc/rust-sdks/download_ffi.py --output livekit-rtc/livekit/rtc/resources
26-
pip3 install pytest ./livekit-protocol ./livekit-api ./livekit-rtc
26+
pip3 install pytest ./livekit-protocol ./livekit-api ./livekit-rtc pydantic
2727
pytest . --ignore=livekit-rtc/rust-sdks

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
# 📹🎙️🐍 Python SDK for LiveKit
1414

1515
<!--BEGIN_DESCRIPTION-->
16-
1716
Use this SDK to add realtime video, audio and data features to your Python app. By connecting to <a href="https://livekit.io/">LiveKit</a> Cloud or a self-hosted server, you can quickly build applications such as multi-modal AI, live streaming, or video calls with just a few lines of code.
18-
1917
<!--END_DESCRIPTION-->
2018

2119
This repo contains two packages
@@ -210,14 +208,13 @@ You may throw errors of the type `RpcError` with a string `message` in an RPC me
210208
Please join us on [Slack](https://livekit.io/join-slack) to get help from our devs / community members. We welcome your contributions(PRs) and details can be discussed there.
211209

212210
<!--BEGIN_REPO_NAV-->
213-
214211
<br/><table>
215-
216212
<thead><tr><th colspan="2">LiveKit Ecosystem</th></tr></thead>
217213
<tbody>
218-
<tr><td>Realtime SDKs</td><td><a href="https://github.com/livekit/components-js">React Components</a> · <a href="https://github.com/livekit/client-sdk-js">Browser</a> · <a href="https://github.com/livekit/components-swift">Swift Components</a> · <a href="https://github.com/livekit/client-sdk-swift">iOS/macOS/visionOS</a> · <a href="https://github.com/livekit/client-sdk-android">Android</a> · <a href="https://github.com/livekit/client-sdk-flutter">Flutter</a> · <a href="https://github.com/livekit/client-sdk-react-native">React Native</a> · <a href="https://github.com/livekit/rust-sdks">Rust</a> · <a href="https://github.com/livekit/node-sdks">Node.js</a> · <b>Python</b> · <a href="https://github.com/livekit/client-sdk-unity-web">Unity (web)</a> · <a href="https://github.com/livekit/client-sdk-unity">Unity (beta)</a></td></tr><tr></tr>
219-
<tr><td>Server APIs</td><td><a href="https://github.com/livekit/node-sdks">Node.js</a> · <a href="https://github.com/livekit/server-sdk-go">Golang</a> · <a href="https://github.com/livekit/server-sdk-ruby">Ruby</a> · <a href="https://github.com/livekit/server-sdk-kotlin">Java/Kotlin</a> · <b>Python</b> · <a href="https://github.com/livekit/rust-sdks">Rust</a> · <a href="https://github.com/agence104/livekit-server-sdk-php">PHP (community)</a></td></tr><tr></tr>
220-
<tr><td>Agents Frameworks</td><td><a href="https://github.com/livekit/agents">Python</a> · <a href="https://github.com/livekit/agent-playground">Playground</a></td></tr><tr></tr>
214+
<tr><td>LiveKit SDKs</td><td><a href="https://github.com/livekit/client-sdk-js">Browser</a> · <a href="https://github.com/livekit/client-sdk-swift">iOS/macOS/visionOS</a> · <a href="https://github.com/livekit/client-sdk-android">Android</a> · <a href="https://github.com/livekit/client-sdk-flutter">Flutter</a> · <a href="https://github.com/livekit/client-sdk-react-native">React Native</a> · <a href="https://github.com/livekit/rust-sdks">Rust</a> · <a href="https://github.com/livekit/node-sdks">Node.js</a> · <b>Python</b> · <a href="https://github.com/livekit/client-sdk-unity">Unity</a> · <a href="https://github.com/livekit/client-sdk-unity-web">Unity (WebGL)</a></td></tr><tr></tr>
215+
<tr><td>Server APIs</td><td><a href="https://github.com/livekit/node-sdks">Node.js</a> · <a href="https://github.com/livekit/server-sdk-go">Golang</a> · <a href="https://github.com/livekit/server-sdk-ruby">Ruby</a> · <a href="https://github.com/livekit/server-sdk-kotlin">Java/Kotlin</a> · <b>Python</b> · <a href="https://github.com/livekit/rust-sdks">Rust</a> · <a href="https://github.com/agence104/livekit-server-sdk-php">PHP (community)</a> · <a href="https://github.com/pabloFuente/livekit-server-sdk-dotnet">.NET (community)</a></td></tr><tr></tr>
216+
<tr><td>UI Components</td><td><a href="https://github.com/livekit/components-js">React</a> · <a href="https://github.com/livekit/components-android">Android Compose</a> · <a href="https://github.com/livekit/components-swift">SwiftUI</a></td></tr><tr></tr>
217+
<tr><td>Agents Frameworks</td><td><a href="https://github.com/livekit/agents">Python</a> · <a href="https://github.com/livekit/agents-js">Node.js</a> · <a href="https://github.com/livekit/agent-playground">Playground</a></td></tr><tr></tr>
221218
<tr><td>Services</td><td><a href="https://github.com/livekit/livekit">LiveKit server</a> · <a href="https://github.com/livekit/egress">Egress</a> · <a href="https://github.com/livekit/ingress">Ingress</a> · <a href="https://github.com/livekit/sip">SIP</a></td></tr><tr></tr>
222219
<tr><td>Resources</td><td><a href="https://docs.livekit.io">Docs</a> · <a href="https://github.com/livekit-examples">Example apps</a> · <a href="https://livekit.io/cloud">Cloud</a> · <a href="https://docs.livekit.io/home/self-hosting/deployment">Self-hosting</a> · <a href="https://github.com/livekit/livekit-cli">CLI</a></td></tr>
223220
</tbody>
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import os
2+
import logging
3+
import asyncio
4+
from signal import SIGINT, SIGTERM
5+
from livekit import rtc
6+
7+
# Set the following environment variables with your own values
8+
TOKEN = os.environ.get("LIVEKIT_TOKEN")
9+
URL = os.environ.get("LIVEKIT_URL")
10+
11+
12+
async def main(room: rtc.Room):
13+
logging.basicConfig(level=logging.INFO)
14+
logger = logging.getLogger(__name__)
15+
16+
async def greetParticipant(identity: str):
17+
text_writer = await room.local_participant.stream_text(
18+
destination_identities=[identity], topic="chat"
19+
)
20+
for char in "Hi! Just a friendly message":
21+
await text_writer.write(char)
22+
await text_writer.aclose()
23+
24+
await room.local_participant.send_file(
25+
"./green_tree_python.jpg",
26+
destination_identities=[identity],
27+
topic="files",
28+
)
29+
30+
async def on_chat_message_received(
31+
reader: rtc.TextStreamReader, participant_identity: str
32+
):
33+
full_text = await reader.read_all()
34+
logger.info(
35+
"Received chat message from %s: '%s'", participant_identity, full_text
36+
)
37+
38+
async def on_welcome_image_received(
39+
reader: rtc.ByteStreamReader, participant_identity: str
40+
):
41+
logger.info(
42+
"Received image from %s: '%s'", participant_identity, reader.info["name"]
43+
)
44+
with open(reader.info["name"], mode="wb") as f:
45+
async for chunk in reader:
46+
f.write(chunk)
47+
48+
f.close()
49+
50+
@room.on("participant_connected")
51+
def on_participant_connected(participant: rtc.RemoteParticipant):
52+
logger.info(
53+
"participant connected: %s %s", participant.sid, participant.identity
54+
)
55+
asyncio.create_task(greetParticipant(participant.identity))
56+
57+
room.set_text_stream_handler(
58+
"chat",
59+
lambda reader, participant_identity: asyncio.create_task(
60+
on_chat_message_received(reader, participant_identity)
61+
),
62+
)
63+
64+
room.set_byte_stream_handler(
65+
"files",
66+
lambda reader, participant_identity: asyncio.create_task(
67+
on_welcome_image_received(reader, participant_identity)
68+
),
69+
)
70+
71+
# By default, autosubscribe is enabled. The participant will be subscribed to
72+
# all published tracks in the room
73+
await room.connect(URL, TOKEN)
74+
logger.info("connected to room %s", room.name)
75+
76+
for identity, participant in room.remote_participants.items():
77+
logger.info("Sending a welcome message to %s", identity)
78+
await greetParticipant(participant.identity)
79+
80+
81+
if __name__ == "__main__":
82+
logging.basicConfig(
83+
level=logging.INFO,
84+
handlers=[
85+
logging.FileHandler("data_stream_example.log"),
86+
logging.StreamHandler(),
87+
],
88+
)
89+
90+
loop = asyncio.get_event_loop()
91+
room = rtc.Room(loop=loop)
92+
93+
async def cleanup():
94+
await room.disconnect()
95+
loop.stop()
96+
97+
asyncio.ensure_future(main(room))
98+
for signal in [SIGINT, SIGTERM]:
99+
loop.add_signal_handler(signal, lambda: asyncio.ensure_future(cleanup()))
100+
101+
try:
102+
loop.run_forever()
103+
finally:
104+
loop.close()
Lines changed: 3 additions & 0 deletions
Loading

examples/publish_hue.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,28 @@ async def main(room: rtc.Room):
5252

5353
asyncio.ensure_future(draw_color_cycle(source))
5454

55+
# uncomment the below to test Track Subscription Permissions
56+
# https://docs.livekit.io/home/client/tracks/publish/#subscription-permissions
57+
# await asyncio.sleep(10)
58+
59+
# logging.info(
60+
# "setting track subscription permissions to False, no one can subscribe to the track"
61+
# )
62+
# room.local_participant.set_track_subscription_permissions(allow_all_participants=False)
63+
64+
# await asyncio.sleep(10)
65+
66+
# logging.info("allowing user to subscribe to the track")
67+
# room.local_participant.set_track_subscription_permissions(
68+
# allow_all_participants=False,
69+
# participant_permissions=[
70+
# rtc.ParticipantTrackPermission(
71+
# participant_identity="allowed-user-identity",
72+
# allow_all=True,
73+
# )
74+
# ],
75+
# )
76+
5577

5678
async def draw_color_cycle(source: rtc.VideoSource):
5779
argb_frame = bytearray(WIDTH * HEIGHT * 4)

livekit-api/livekit/api/room_service.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import aiohttp
2+
from uuid import uuid4
23
from livekit.protocol.room import (
34
CreateRoomRequest,
45
ListRoomsRequest,
@@ -288,6 +289,8 @@ async def send_data(self, send: SendDataRequest) -> SendDataResponse:
288289
Returns:
289290
SendDataResponse: Empty response object
290291
"""
292+
293+
send.nonce = uuid4().bytes
291294
return await self._client.request(
292295
SVC,
293296
"SendData",

0 commit comments

Comments
 (0)