From 7f08b04c1eed4fd7fa24702bfd9d2ce32390d884 Mon Sep 17 00:00:00 2001 From: Paul Wells Date: Wed, 20 May 2026 11:42:51 -0700 Subject: [PATCH] Add IsIntentionalDisconnect helper (#4537) Shared helper for callers that need to distinguish intentional/expected participant closures (client leave, admin action, room teardown, migration) from connection failures. Extracted from cloud's IsClosedIntentionally switch so cloud-side code paths can share a single source of truth. --- pkg/rtc/types/interfaces.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/rtc/types/interfaces.go b/pkg/rtc/types/interfaces.go index 4eba9b63a..e77393e80 100644 --- a/pkg/rtc/types/interfaces.go +++ b/pkg/rtc/types/interfaces.go @@ -225,6 +225,23 @@ func (p ParticipantCloseReason) ToDisconnectReason() livekit.DisconnectReason { } } +// IsIntentionalDisconnect reports whether a disconnect reason represents an +// intentional/expected closure (client leaving, admin action, room teardown, +// migration, etc.) as opposed to a connection failure. +func IsIntentionalDisconnect(reason livekit.DisconnectReason) bool { + switch reason { + case livekit.DisconnectReason_CLIENT_INITIATED, + livekit.DisconnectReason_SERVER_SHUTDOWN, + livekit.DisconnectReason_DUPLICATE_IDENTITY, + livekit.DisconnectReason_MIGRATION, + livekit.DisconnectReason_PARTICIPANT_REMOVED, + livekit.DisconnectReason_ROOM_DELETED, + livekit.DisconnectReason_ROOM_CLOSED: + return true + } + return false +} + // --------------------------------------------- type SignallingCloseReason int