Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions livekit-agents/livekit/agents/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ async def wait_for_participant(
participant that joins the room will be returned.
If the participant has already joined, the function will return immediately.
"""

# handle connection automatically, otherwise wait_for_participant will raise an error
if not self._room.isconnected():
await self.connect()

return await wait_for_participant(self._room, identity=identity, kind=kind)

async def connect(
Expand Down
9 changes: 5 additions & 4 deletions livekit-agents/livekit/agents/utils/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def kind_match(p: rtc.RemoteParticipant) -> bool:

return p.kind == kind

def _on_participant_connected(p: rtc.RemoteParticipant) -> None:
def _on_participant_active(p: rtc.RemoteParticipant) -> None:
if (identity is None or p.identity == identity) and kind_match(p):
if not fut.done():
fut.set_result(p)
Expand All @@ -101,18 +101,19 @@ def _on_connection_state_changed(state: int) -> None:
if state == rtc.ConnectionState.CONN_DISCONNECTED and not fut.done():
fut.set_exception(RuntimeError("room disconnected while waiting for participant"))

room.on("participant_connected", _on_participant_connected)
room.on("participant_active", _on_participant_active)
Comment thread
davidzhao marked this conversation as resolved.
room.on("connection_state_changed", _on_connection_state_changed)

try:
for p in room.remote_participants.values():
_on_participant_connected(p)
if p.state == rtc.ParticipantState.PARTICIPANT_STATE_ACTIVE:
_on_participant_active(p)
if fut.done():
break

return await fut
finally:
room.off("participant_connected", _on_participant_connected)
room.off("participant_active", _on_participant_active)
room.off("connection_state_changed", _on_connection_state_changed)


Expand Down
2 changes: 1 addition & 1 deletion livekit-agents/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies = [
"typer>=0.15.1",
"click~=8.1",
"certifi>=2025.6.15",
"livekit==1.1.3",
"livekit==1.1.5",
"livekit-api>=1.0.7,<2",
"livekit-protocol>=1.1.3,<2",
"livekit-blingfire~=1.1,<2",
Expand Down
Loading
Loading