Skip to content

Commit b51abd2

Browse files
authored
facilitate manual call management (daily-demos#7)
1 parent 3fda9b0 commit b51abd2

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
env/
33
__pycache__/
44
*~
5+
venv
56
#*#
67

78
# Distribution / packaging

src/dailyai/services/daily_transport_service.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ def __init__(
3030
token: str | None,
3131
bot_name: str,
3232
duration: float = 10,
33+
min_others_count: int = 1,
3334
):
3435
super().__init__()
3536
self.bot_name: str = bot_name
3637
self.room_url: str = room_url
3738
self.token: str | None = token
3839
self.duration: float = duration
3940
self.expiration = time.time() + duration * 60
41+
self.min_others_count = min_others_count
4042

4143
# This queue is used to marshal frames from the async send queue to the thread that emits audio & video.
4244
# We need this to maintain the asynchronous behavior of asyncio queues -- to give async functions
@@ -224,14 +226,14 @@ async def stop_when_done(self):
224226
async def run(self) -> None:
225227
self.configure_daily()
226228

227-
self.participant_left = False
229+
self.do_shutdown = False
228230

229231
async_output_queue_marshal_task = asyncio.create_task(self.marshal_frames())
230232

231233
try:
232234
participant_count: int = len(self.client.participants())
233235
self.logger.info(f"{participant_count} participants in room")
234-
while time.time() < self.expiration and not self.participant_left and not self.stop_threads.is_set():
236+
while time.time() < self.expiration and not self.do_shutdown and not self.stop_threads.is_set():
235237
await asyncio.sleep(1)
236238
except Exception as e:
237239
self.logger.error(f"Exception {e}")
@@ -270,8 +272,8 @@ def on_participant_joined(self, participant):
270272
self.on_first_other_participant_joined()
271273

272274
def on_participant_left(self, participant, reason):
273-
if len(self.client.participants()) < 2:
274-
self.participant_left = True
275+
if len(self.client.participants()) < self.min_others_count + 1:
276+
self.do_shutdown = True
275277
pass
276278

277279
def on_app_message(self, message, sender):

0 commit comments

Comments
 (0)