Skip to content

Commit ca1d17b

Browse files
committed
Expose reconnect mode
1 parent 23094a5 commit ca1d17b

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

.nanpa/expose-reconnect.kdl

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
patch type="added" "Exposed reconnect mode in RoomDelegate"

Sources/LiveKit/Core/Room+EngineDelegate.swift

+9
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ extension Room {
8686
}
8787
}
8888

89+
// Notify when reconnection mode changes
90+
if state.isReconnectingWithMode != oldState.isReconnectingWithMode,
91+
let mode = state.isReconnectingWithMode
92+
{
93+
delegates.notify(label: { "room.didUpdate reconnectionMode: \(String(describing: state.isReconnectingWithMode)) oldValue: \(String(describing: oldState.isReconnectingWithMode))" }) {
94+
$0.room?(self, didUpdateReconnectMode: mode)
95+
}
96+
}
97+
8998
// Notify change when engine's state mutates
9099
Task.detached { @MainActor in
91100
self.objectWillChange.send()

Sources/LiveKit/Protocols/RoomDelegate.swift

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public protocol RoomDelegate: AnyObject {
3636
// MARK: - Connection Events
3737

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

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

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

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

56+
/// ``Room`` reconnect mode has updated.
57+
@objc optional
58+
func room(_ room: Room, didUpdateReconnectMode reconnectMode: ReconnectMode)
59+
5460
/// Could not connect to the room. Only triggered when the initial connect attempt fails.
5561
@objc optional
5662
func room(_ room: Room, didFailToConnectWithError error: LiveKitError?)

Sources/LiveKit/Types/ConnectionState.swift

+7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ import Foundation
1818

1919
@objc
2020
public enum ReconnectMode: Int, Sendable {
21+
/// Quick reconnection mode attempts to maintain the same session, reusing existing
22+
/// transport connections and published tracks. This is faster but may not succeed
23+
/// in all network conditions.
2124
case quick
25+
26+
/// Full reconnection mode performs a complete new connection to the LiveKit server,
27+
/// closing existing connections and re-publishing all tracks. This is slower but
28+
/// more reliable for recovering from severe connection issues.
2229
case full
2330
}
2431

0 commit comments

Comments
 (0)