Skip to content

Commit 89fb1ba

Browse files
committed
update example
1 parent 30ee183 commit 89fb1ba

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

examples/local_audio/full_duplex.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
from dotenv import load_dotenv, find_dotenv
55

6-
from livekit import rtc
6+
from livekit import api, rtc
77

88

99
async def main() -> None:
@@ -13,8 +13,9 @@ async def main() -> None:
1313
load_dotenv(find_dotenv())
1414

1515
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:
1819
raise RuntimeError("LIVEKIT_URL and LIVEKIT_TOKEN must be set in env")
1920

2021
room = rtc.Room()
@@ -99,6 +100,19 @@ def on_participant_disconnected(participant: rtc.RemoteParticipant):
99100
logging.info("participant disconnected: %s", participant.identity)
100101

101102
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+
)
102116

103117
try:
104118
await room.connect(url, token)

examples/local_audio/publish_mic.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
from dotenv import load_dotenv, find_dotenv
55

6-
from livekit import rtc
6+
from livekit import api, rtc
77

88

99
async def main() -> None:
@@ -13,16 +13,30 @@ async def main() -> None:
1313
load_dotenv(find_dotenv())
1414

1515
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")
1920

2021
room = rtc.Room()
2122

2223
# Create media devices helper and open default microphone with AEC enabled
2324
devices = rtc.MediaDevices()
2425
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+
2640
try:
2741
await room.connect(url, token)
2842
logging.info("connected to room %s", room.name)

0 commit comments

Comments
 (0)