1- <!-- BEGIN_BANNER_IMAGE-->
2- <picture >
3- <source media =" (prefers-color-scheme: dark) " srcset =" /.github/banner_dark.png " >
4- <source media =" (prefers-color-scheme: light) " srcset =" /.github/banner_light.png " >
5- <img style =" width :100% ;" alt =" The LiveKit icon, the name of the repository and some sample code in the background. " src =" https://raw.githubusercontent.com/livekit/client-sdk-python/main/.github/banner_light.png " >
6- </picture >
1+ <!-- BEGIN_BANNER_IMAGE-->
2+ <picture >
3+ <source media =" (prefers-color-scheme: dark) " srcset =" /.github/banner_dark.png " >
4+ <source media =" (prefers-color-scheme: light) " srcset =" /.github/banner_light.png " >
5+ <img style =" width :100% ;" alt =" The LiveKit icon, the name of the repository and some sample code in the background. " src =" https://raw.githubusercontent.com/livekit/client-sdk-python/main/.github/banner_light.png " >
6+ </picture >
77<!-- END_BANNER_IMAGE-->
88
99[ ![ pypi-v] ( https://img.shields.io/pypi/v/livekit.svg )] ( https://pypi.org/project/livekit/ )
@@ -15,6 +15,7 @@ The Livekit Python Client provides a convenient interface for integrating Liveki
1515Official LiveKit documentation: https://docs.livekit.io/
1616
1717## Installation
18+
1819``` shell
1920$ pip install livekit
2021```
@@ -24,25 +25,34 @@ $ pip install livekit
2425``` python
2526async def main ():
2627 room = livekit.Room()
28+ # By default, autosubscribe is enabled. The participant will be subscribed to
29+ # all published tracks in the room
2730 await room.connect(URL , TOKEN )
2831 logging.info(" connected to room %s " , room.name)
2932
33+ # participants and tracks that are already available in the room
34+ # participant_connected and track_published events will *not* be emitted for them
35+ for participant in room.participants.items():
36+ for publication in participant.tracks.items():
37+ print (" track publication: %s " , publication.sid)
38+
3039 @room.on (" participant_connected" )
3140 def on_participant_connected (participant : livekit.RemoteParticipant):
3241 logging.info(
3342 " participant connected: %s %s " , participant.sid, participant.identity)
3443
3544 video_stream = None
45+
46+ # track_subscribed is emitted whenever the local participant is subscribed to a new track
3647 @room.on (" track_subscribed" )
3748 def on_track_subscribed (track : livekit.Track, publication : livekit.RemoteTrackPublication, participant : livekit.RemoteParticipant):
3849 logging.info(" track subscribed: %s " , publication.sid)
3950 if track.kind == livekit.TrackKind.KIND_VIDEO :
4051 nonlocal video_stream
4152 video_stream = livekit.VideoStream(track)
4253
43- @video_stream.on (" frame_received" )
44- def on_video_frame (frame : livekit.VideoFrame):
45- # received a video frame from the track
54+ async for frame in video_stream:
55+ # received a video frame from the track, process it here
4656 pass
4757
4858 await room.run()
0 commit comments