@@ -16,44 +16,67 @@ Official LiveKit documentation: https://docs.livekit.io/
16
16
17
17
## Installation
18
18
19
+ RTC Client:
19
20
``` shell
20
21
$ pip install livekit
21
22
```
22
23
24
+ API / Server SDK:
25
+ ``` shell
26
+ $ pip install livekit-api
27
+ ```
28
+
23
29
## Connecting to a room
24
30
25
31
``` python
26
- async def main ():
27
- room = livekit.Room()
32
+ from livekit import rtc
28
33
29
- # participants and tracks that are already available in the room
30
- # participant_connected and track_published events will *not* be emitted for them
31
- for participant in room.participants.items():
32
- for publication in participant.tracks.items():
33
- print (" track publication: %s " , publication.sid)
34
+ async def main ():
35
+ room = rtc.Room()
34
36
35
37
@room.on (" participant_connected" )
36
- def on_participant_connected (participant : livekit .RemoteParticipant):
38
+ def on_participant_connected (participant : rtc .RemoteParticipant):
37
39
logging.info(
38
40
" participant connected: %s %s " , participant.sid, participant.identity)
39
41
40
- async def receive_frames (stream : livekit .VideoStream):
42
+ async def receive_frames (stream : rtc .VideoStream):
41
43
async for frame in video_stream:
42
44
# received a video frame from the track, process it here
43
45
pass
44
46
45
47
# track_subscribed is emitted whenever the local participant is subscribed to a new track
46
48
@room.on (" track_subscribed" )
47
- def on_track_subscribed (track : livekit .Track, publication : livekit .RemoteTrackPublication, participant : livekit .RemoteParticipant):
49
+ def on_track_subscribed (track : rtc .Track, publication : rtc .RemoteTrackPublication, participant : rtc .RemoteParticipant):
48
50
logging.info(" track subscribed: %s " , publication.sid)
49
- if track.kind == livekit .TrackKind.KIND_VIDEO :
50
- video_stream = livekit .VideoStream(track)
51
+ if track.kind == rtc .TrackKind.KIND_VIDEO :
52
+ video_stream = rtc .VideoStream(track)
51
53
asyncio.ensure_future(receive_frames(video_stream))
52
54
53
55
# By default, autosubscribe is enabled. The participant will be subscribed to
54
56
# all published tracks in the room
55
57
await room.connect(URL , TOKEN )
56
58
logging.info(" connected to room %s " , room.name)
59
+
60
+ # participants and tracks that are already available in the room
61
+ # participant_connected and track_published events will *not* be emitted for them
62
+ for participant in room.participants.items():
63
+ for publication in participant.tracks.items():
64
+ print (" track publication: %s " , publication.sid)
65
+ ```
66
+
67
+ ## Create a new access token
68
+
69
+ ``` python
70
+ from livekit import api
71
+
72
+ token = api.AccessToken(" API_KEY" , " SECRET_KEY" )
73
+ token = AccessToken()
74
+ jwt = (
75
+ token.with_identity(" user1" )
76
+ .with_name(" user1" )
77
+ .with_grants(VideoGrants(room_join = True , room = " room1" ))
78
+ .to_jwt()
79
+ )
57
80
```
58
81
59
82
## Examples
0 commit comments