Skip to content

Commit 0756a40

Browse files
authored
add optional reason to Room.disconnect() (#584)
1 parent c1e6a58 commit 0756a40

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

livekit-rtc/livekit/rtc/room.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,9 @@ def unregister_text_stream_handler(self, topic: str):
573573
if self._text_stream_handlers.get(topic):
574574
self._text_stream_handlers.pop(topic)
575575

576-
async def disconnect(self) -> None:
576+
async def disconnect(
577+
self, *, reason: DisconnectReason = DisconnectReason.CLIENT_INITIATED
578+
) -> None:
577579
"""Disconnects from the room."""
578580
if not self.isconnected():
579581
return
@@ -583,6 +585,7 @@ async def disconnect(self) -> None:
583585

584586
req = proto_ffi.FfiRequest()
585587
req.disconnect.room_handle = self._ffi_handle.handle # type: ignore
588+
req.disconnect.reason = reason # type: ignore
586589
queue = FfiClient.instance.queue.subscribe()
587590
try:
588591
resp = FfiClient.instance.request(req)
@@ -596,10 +599,10 @@ async def disconnect(self) -> None:
596599
# we should manually flip the state, since the connection could have been torn down before
597600
# the callbacks were processed
598601
if self._connection_state != ConnectionState.CONN_DISCONNECTED:
599-
self.local_participant._info.disconnect_reason = DisconnectReason.CLIENT_INITIATED
602+
self.local_participant._info.disconnect_reason = reason
600603
self._connection_state = ConnectionState.CONN_DISCONNECTED
601604
self.emit("connection_state_changed", self._connection_state)
602-
self.emit("disconnected", DisconnectReason.CLIENT_INITIATED)
605+
self.emit("disconnected", reason)
603606

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

0 commit comments

Comments
 (0)