File tree Expand file tree Collapse file tree 2 files changed +36
-8
lines changed Expand file tree Collapse file tree 2 files changed +36
-8
lines changed Original file line number Diff line number Diff line change 3
3
import logging
4
4
from dotenv import load_dotenv , find_dotenv
5
5
6
- from livekit import rtc
6
+ from livekit import api , rtc
7
7
8
8
9
9
async def main () -> None :
@@ -13,8 +13,9 @@ async def main() -> None:
13
13
load_dotenv (find_dotenv ())
14
14
15
15
url = os .getenv ("LIVEKIT_URL" )
16
- token = os .getenv ("LIVEKIT_TOKEN" )
17
- if not url or not token :
16
+ api_key = os .getenv ("LIVEKIT_API_KEY" )
17
+ api_secret = os .getenv ("LIVEKIT_API_SECRET" )
18
+ if not url or not api_key or not api_secret :
18
19
raise RuntimeError ("LIVEKIT_URL and LIVEKIT_TOKEN must be set in env" )
19
20
20
21
room = rtc .Room ()
@@ -99,6 +100,19 @@ def on_participant_disconnected(participant: rtc.RemoteParticipant):
99
100
logging .info ("participant disconnected: %s" , participant .identity )
100
101
101
102
room .on ("participant_disconnected" , on_participant_disconnected )
103
+
104
+ token = (
105
+ api .AccessToken (api_key , api_secret )
106
+ .with_identity ("local-audio" )
107
+ .with_name ("Local Audio" )
108
+ .with_grants (
109
+ api .VideoGrants (
110
+ room_join = True ,
111
+ room = "local-audio" ,
112
+ )
113
+ )
114
+ .to_jwt ()
115
+ )
102
116
103
117
try :
104
118
await room .connect (url , token )
Original file line number Diff line number Diff line change 3
3
import logging
4
4
from dotenv import load_dotenv , find_dotenv
5
5
6
- from livekit import rtc
6
+ from livekit import api , rtc
7
7
8
8
9
9
async def main () -> None :
@@ -13,16 +13,30 @@ async def main() -> None:
13
13
load_dotenv (find_dotenv ())
14
14
15
15
url = os .getenv ("LIVEKIT_URL" )
16
- token = os .getenv ("LIVEKIT_TOKEN" )
17
- if not url or not token :
18
- raise RuntimeError ("LIVEKIT_URL and LIVEKIT_TOKEN must be set in env" )
16
+ api_key = os .getenv ("LIVEKIT_API_KEY" )
17
+ api_secret = os .getenv ("LIVEKIT_API_SECRET" )
18
+ if not url or not api_key or not api_secret :
19
+ raise RuntimeError ("LIVEKIT_URL and LIVEKIT_API_KEY and LIVEKIT_API_SECRET must be set in env" )
19
20
20
21
room = rtc .Room ()
21
22
22
23
# Create media devices helper and open default microphone with AEC enabled
23
24
devices = rtc .MediaDevices ()
24
25
mic = devices .open_input (enable_aec = True )
25
-
26
+
27
+ token = (
28
+ api .AccessToken (api_key , api_secret )
29
+ .with_identity ("local-audio" )
30
+ .with_name ("Local Audio" )
31
+ .with_grants (
32
+ api .VideoGrants (
33
+ room_join = True ,
34
+ room = "local-audio" ,
35
+ )
36
+ )
37
+ .to_jwt ()
38
+ )
39
+
26
40
try :
27
41
await room .connect (url , token )
28
42
logging .info ("connected to room %s" , room .name )
You can’t perform that action at this time.
0 commit comments