Skip to content

Commit 7de2d93

Browse files
committed
add optional reason to Room.disconnect()
1 parent 03691b3 commit 7de2d93

File tree

6 files changed

+281
-253
lines changed

6 files changed

+281
-253
lines changed

livekit-rtc/livekit/rtc/_proto/participant_pb2.py

Lines changed: 16 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

livekit-rtc/livekit/rtc/_proto/participant_pb2.pyi

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

livekit-rtc/livekit/rtc/_proto/room_pb2.py

Lines changed: 251 additions & 241 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

livekit-rtc/livekit/rtc/_proto/room_pb2.pyi

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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)