Skip to content

Commit d00b9a8

Browse files
committed
room close
1 parent d92705f commit d00b9a8

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

livekit/_ffi_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,5 @@ def __init__(self, handle: int):
108108

109109
def __del__(self):
110110
if self.handle != INVALID_HANDLE:
111-
assert (ffi_lib.livekit_ffi_drop_handle(c_size_t(self.handle)))
111+
ffi_lib.livekit_ffi_drop_handle(
112+
c_size_t(self.handle)) # TODO Assert

livekit/room.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,24 @@ def on_connect_callback(cb: proto_room.ConnectCallback):
6464
ffi_client.add_listener('room_event', self._on_room_event)
6565

6666
async def close(self):
67-
self._ffi_handle = None
68-
# TODO(theomonnom): wait for ffi resp
67+
ffi_client = FfiClient()
68+
69+
req = proto_ffi.FfiRequest()
70+
req.disconnect.room_handle.id = self._ffi_handle.handle
71+
72+
resp = ffi_client.request(req)
73+
future = asyncio.Future()
74+
75+
@ffi_client.on('disconnect')
76+
def on_disconnect_callback(cb: proto_room.DisconnectCallback):
77+
if cb.async_id == resp.disconnect.async_id:
78+
future.set_result(cb)
79+
ffi_client.remove_listener(
80+
'disconnect', on_disconnect_callback)
81+
82+
await future
6983
self._close_future.set_result(None)
84+
self._ffi_handle = None
7085

7186
async def run(self):
7287
await self._close_future

0 commit comments

Comments
 (0)