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 >
7
7
<!-- END_BANNER_IMAGE-->
8
8
9
9
[ ![ 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
15
15
Official LiveKit documentation: https://docs.livekit.io/
16
16
17
17
## Installation
18
+
18
19
``` shell
19
20
$ pip install livekit
20
21
```
@@ -24,25 +25,34 @@ $ pip install livekit
24
25
``` python
25
26
async def main ():
26
27
room = livekit.Room()
28
+ # By default, autosubscribe is enabled. The participant will be subscribed to
29
+ # all published tracks in the room
27
30
await room.connect(URL , TOKEN )
28
31
logging.info(" connected to room %s " , room.name)
29
32
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
+
30
39
@room.on (" participant_connected" )
31
40
def on_participant_connected (participant : livekit.RemoteParticipant):
32
41
logging.info(
33
42
" participant connected: %s %s " , participant.sid, participant.identity)
34
43
35
44
video_stream = None
45
+
46
+ # track_subscribed is emitted whenever the local participant is subscribed to a new track
36
47
@room.on (" track_subscribed" )
37
48
def on_track_subscribed (track : livekit.Track, publication : livekit.RemoteTrackPublication, participant : livekit.RemoteParticipant):
38
49
logging.info(" track subscribed: %s " , publication.sid)
39
50
if track.kind == livekit.TrackKind.KIND_VIDEO :
40
51
nonlocal video_stream
41
52
video_stream = livekit.VideoStream(track)
42
53
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
46
56
pass
47
57
48
58
await room.run()
0 commit comments