Skip to content

Commit e2304e0

Browse files
committed
allow token instead of key/secret
1 parent 1f00c24 commit e2304e0

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

examples/local_audio/full_duplex.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ async def main() -> None:
1818
url = os.getenv("LIVEKIT_URL")
1919
api_key = os.getenv("LIVEKIT_API_KEY")
2020
api_secret = os.getenv("LIVEKIT_API_SECRET")
21-
if not url or not api_key or not api_secret:
22-
raise RuntimeError("LIVEKIT_URL and LIVEKIT_TOKEN must be set in env")
21+
token = os.getenv("LIVEKIT_TOKEN")
22+
# check for either token or api_key and api_secret
23+
if not url or (not token and (not api_key or not api_secret)):
24+
raise RuntimeError("LIVEKIT_TOKEN or LIVEKIT_API_KEY and LIVEKIT_API_SECRET must be set in env")
2325

2426
room = rtc.Room()
2527

@@ -53,18 +55,20 @@ def on_track_unsubscribed(
5355

5456
room.on("track_unsubscribed", on_track_unsubscribed)
5557

56-
token = (
57-
api.AccessToken(api_key, api_secret)
58-
.with_identity("local-audio")
59-
.with_name("Local Audio")
60-
.with_grants(
61-
api.VideoGrants(
62-
room_join=True,
63-
room="local-audio",
58+
# generate token if not provided
59+
if not token:
60+
token = (
61+
api.AccessToken(api_key, api_secret)
62+
.with_identity("local-audio")
63+
.with_name("Local Audio")
64+
.with_grants(
65+
api.VideoGrants(
66+
room_join=True,
67+
room="local-audio",
68+
)
6469
)
70+
.to_jwt()
6571
)
66-
.to_jwt()
67-
)
6872

6973
try:
7074
await room.connect(url, token)

0 commit comments

Comments
 (0)