Skip to content

Commit

Permalink
facilitate manual call management (daily-demos#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
lazeratops authored Jan 23, 2024
1 parent 3fda9b0 commit b51abd2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
env/
__pycache__/
*~
venv
#*#

# Distribution / packaging
Expand Down
10 changes: 6 additions & 4 deletions src/dailyai/services/daily_transport_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ def __init__(
token: str | None,
bot_name: str,
duration: float = 10,
min_others_count: int = 1,
):
super().__init__()
self.bot_name: str = bot_name
self.room_url: str = room_url
self.token: str | None = token
self.duration: float = duration
self.expiration = time.time() + duration * 60
self.min_others_count = min_others_count

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

self.participant_left = False
self.do_shutdown = False

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

try:
participant_count: int = len(self.client.participants())
self.logger.info(f"{participant_count} participants in room")
while time.time() < self.expiration and not self.participant_left and not self.stop_threads.is_set():
while time.time() < self.expiration and not self.do_shutdown and not self.stop_threads.is_set():
await asyncio.sleep(1)
except Exception as e:
self.logger.error(f"Exception {e}")
Expand Down Expand Up @@ -270,8 +272,8 @@ def on_participant_joined(self, participant):
self.on_first_other_participant_joined()

def on_participant_left(self, participant, reason):
if len(self.client.participants()) < 2:
self.participant_left = True
if len(self.client.participants()) < self.min_others_count + 1:
self.do_shutdown = True
pass

def on_app_message(self, message, sender):
Expand Down

0 comments on commit b51abd2

Please sign in to comment.