Skip to content

Commit

Permalink
Update room.py
Browse files Browse the repository at this point in the history
  • Loading branch information
theomonnom committed May 5, 2024
1 parent fcf1c63 commit c736de0
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions livekit-rtc/livekit/rtc/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,32 +218,25 @@ async def connect(
self._task = self._loop.create_task(self._listen_task())

async def disconnect(self) -> None:
if not self.isconnected():
if self._task is not None:
with contextlib.suppress(asyncio.CancelledError):
await self._task

if self._ffi_queue is not None:
FfiClient.instance.queue.unsubscribe(self._ffi_queue)

return

try:
req = proto_ffi.FfiRequest()
req.disconnect.room_handle = self._ffi_handle.handle # type: ignore

queue = FfiClient.instance.queue.subscribe()
try:
resp = FfiClient.instance.request(req)
await queue.wait_for(
lambda e: e.disconnect.async_id == resp.disconnect.async_id
)
finally:
FfiClient.instance.queue.unsubscribe(queue)
if self.isconnected():
req = proto_ffi.FfiRequest()
req.disconnect.room_handle = self._ffi_handle.handle # type: ignore

await self._task
queue = FfiClient.instance.queue.subscribe()
try:
resp = FfiClient.instance.request(req)
await queue.wait_for(
lambda e: e.disconnect.async_id == resp.disconnect.async_id
)
finally:
FfiClient.instance.queue.unsubscribe(queue)

if self._task is not None:
await self._task
finally:
FfiClient.instance.queue.unsubscribe(self._ffi_queue)
if self._ffi_queue is not None:
FfiClient.instance.queue.unsubscribe(self._ffi_queue)

async def _listen_task(self) -> None:
# listen to incoming room events
Expand Down

0 comments on commit c736de0

Please sign in to comment.