Skip to content

Commit 6e8cfc3

Browse files
authored
example and docs tweaks (#432)
1 parent ea42eb8 commit 6e8cfc3

File tree

5 files changed

+34
-18
lines changed

5 files changed

+34
-18
lines changed

examples/data-streams/data_streams.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ async def main(room: rtc.Room):
1313
logging.basicConfig(level=logging.INFO)
1414
logger = logging.getLogger(__name__)
1515

16+
active_tasks = []
17+
1618
async def greetParticipant(identity: str):
1719
text_writer = await room.local_participant.stream_text(
1820
destination_identities=[identity], topic="chat"
@@ -32,8 +34,8 @@ async def on_chat_message_received(reader: rtc.TextStreamReader, participant_ide
3234
logger.info("Received chat message from %s: '%s'", participant_identity, full_text)
3335

3436
async def on_welcome_image_received(reader: rtc.ByteStreamReader, participant_identity: str):
35-
logger.info("Received image from %s: '%s'", participant_identity, reader.info["name"])
36-
with open(reader.info["name"], mode="wb") as f:
37+
logger.info("Received image from %s: '%s'", participant_identity, reader.info.name)
38+
with open(reader.info.name, mode="wb") as f:
3739
async for chunk in reader:
3840
f.write(chunk)
3941

@@ -44,19 +46,19 @@ def on_participant_connected(participant: rtc.RemoteParticipant):
4446
logger.info("participant connected: %s %s", participant.sid, participant.identity)
4547
asyncio.create_task(greetParticipant(participant.identity))
4648

47-
room.set_text_stream_handler(
48-
"chat",
49-
lambda reader, participant_identity: asyncio.create_task(
50-
on_chat_message_received(reader, participant_identity)
51-
),
52-
)
49+
def _handle_chat_stream(reader, participant_identity):
50+
task = asyncio.create_task(on_chat_message_received(reader, participant_identity))
51+
active_tasks.append(task)
52+
task.add_done_callback(lambda _: active_tasks.remove(task))
5353

54-
room.set_byte_stream_handler(
55-
"files",
56-
lambda reader, participant_identity: asyncio.create_task(
57-
on_welcome_image_received(reader, participant_identity)
58-
),
59-
)
54+
room.set_text_stream_handler("chat", _handle_chat_stream)
55+
56+
def _handle_welcome_image_stream(reader, participant_identity):
57+
task = asyncio.create_task(on_welcome_image_received(reader, participant_identity))
58+
active_tasks.append(task)
59+
task.add_done_callback(lambda _: active_tasks.remove(task))
60+
61+
room.set_byte_stream_handler("files", _handle_welcome_image_stream)
6062

6163
# By default, autosubscribe is enabled. The participant will be subscribed to
6264
# all published tracks in the room

livekit-api/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# LiveKit Server APIs
22

33
Access LiveKit server APIs and generate access tokens.
4+
5+
See https://docs.livekit.io/reference/server/server-apis for more information.
6+

livekit-api/livekit/api/room_service.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ async def forward_participant(self, forward: ForwardParticipantRequest) -> None:
215215
SVC,
216216
"ForwardParticipant",
217217
forward,
218-
self._auth_header(VideoGrants(room_admin=True, room=forward.room, destination_room=forward.destination_room)),
218+
self._auth_header(
219+
VideoGrants(
220+
room_admin=True, room=forward.room, destination_room=forward.destination_room
221+
)
222+
),
219223
ForwardParticipantResponse,
220224
)
221225

livekit-rtc/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
# LiveKit Real-time Python SDK
1+
# LiveKit SDK for Python
2+
3+
Python SDK to integrate LiveKit's real-time video, audio, and data capabilities into your Python applications using WebRTC. Designed for use with [LiveKit Agents](https://github.com/livekit/agents) to build powerful voice AI apps.
4+
5+
See https://docs.livekit.io/ for more information.
26

3-
The LiveKit Python SDK provides a convenient interface for integrating LiveKit's real-time video and audio capabilities into your Python applications. With it, developers can easily leverage LiveKit's WebRTC functionalities, allowing them to focus on building their AI models or other application logic without worrying about the complexities of WebRTC.

livekit-rtc/livekit/rtc/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""LiveKit RTC SDK"""
15+
"""LiveKit SDK for Python
16+
`pip install livekit`
17+
18+
See https://docs.livekit.io/home/client/connect/#installing-the-livekit-sdk for more information.
19+
"""
1620

1721
from ._proto import stats_pb2 as stats
1822
from ._proto.e2ee_pb2 import EncryptionState, EncryptionType

0 commit comments

Comments
 (0)