Skip to content

Expose reconnect mode #642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nanpa/expose-reconnect.kdl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
patch type="added" "Exposed reconnect mode in RoomDelegate"
9 changes: 9 additions & 0 deletions Sources/LiveKit/Core/Room+EngineDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ extension Room {
}
}

// Notify when reconnection mode changes
if state.isReconnectingWithMode != oldState.isReconnectingWithMode,
let mode = state.isReconnectingWithMode
{
delegates.notify(label: { "room.didUpdate reconnectionMode: \(String(describing: state.isReconnectingWithMode)) oldValue: \(String(describing: oldState.isReconnectingWithMode))" }) {
$0.room?(self, didUpdateReconnectMode: mode)
}
}

// Notify change when engine's state mutates
Task.detached { @MainActor in
self.objectWillChange.send()
Expand Down
6 changes: 6 additions & 0 deletions Sources/LiveKit/Protocols/RoomDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public protocol RoomDelegate: AnyObject {
// MARK: - Connection Events

/// ``Room/connectionState`` has updated.
/// - Note: This method is not called for ``ReconnectMode/quick``, use ``RoomDelegate/room(_:didUpdateReconnectMode:)`` instead.
@objc optional
func room(_ room: Room, didUpdateConnectionState connectionState: ConnectionState, from oldConnectionState: ConnectionState)

Expand All @@ -44,13 +45,18 @@ public protocol RoomDelegate: AnyObject {
func roomDidConnect(_ room: Room)

/// Previously connected to room but re-attempting to connect due to network issues.
/// - Note: This method is not called for ``ReconnectMode/quick``, use ``RoomDelegate/room(_:didUpdateReconnectMode:)`` instead.
@objc optional
func roomIsReconnecting(_ room: Room)

/// Successfully re-connected to the room.
@objc optional
func roomDidReconnect(_ room: Room)

/// ``Room`` reconnect mode has updated.
@objc optional
func room(_ room: Room, didUpdateReconnectMode reconnectMode: ReconnectMode)

/// Could not connect to the room. Only triggered when the initial connect attempt fails.
@objc optional
func room(_ room: Room, didFailToConnectWithError error: LiveKitError?)
Expand Down
7 changes: 7 additions & 0 deletions Sources/LiveKit/Types/ConnectionState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ import Foundation

@objc
public enum ReconnectMode: Int, Sendable {
/// Quick reconnection mode attempts to maintain the same session, reusing existing
/// transport connections and published tracks. This is faster but may not succeed
/// in all network conditions.
case quick

/// Full reconnection mode performs a complete new connection to the LiveKit server,
/// closing existing connections and re-publishing all tracks. This is slower but
/// more reliable for recovering from severe connection issues.
case full
}

Expand Down
Loading