Skip to content
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 .changes/reconnect-delegate
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
patch type="added" "Separate delegate methods for reconnect start/completion"
18 changes: 18 additions & 0 deletions Sources/LiveKit/Core/Room+EngineDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ extension Room {
}
}

// Notify when reconnection starts
if oldState.isReconnectingWithMode == nil, state.isReconnectingWithMode != nil {
if let startMode = state.isReconnectingWithMode {
delegates.notify(label: { "room.didStartReconnectWithMode: \(startMode)" }) {
$0.room?(self, didStartReconnectWithMode: startMode)
}
}
}

// Notify when reconnection completes
if oldState.isReconnectingWithMode != nil, state.isReconnectingWithMode == nil {
if let completedMode = oldState.isReconnectingWithMode {
delegates.notify(label: { "room.didCompleteReconnectWithMode: \(completedMode)" }) {
$0.room?(self, didCompleteReconnectWithMode: completedMode)
}
}
}

// Notify when reconnection mode changes
if state.isReconnectingWithMode != oldState.isReconnectingWithMode,
let mode = state.isReconnectingWithMode
Expand Down
16 changes: 14 additions & 2 deletions Sources/LiveKit/Protocols/RoomDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public protocol RoomDelegate: AnyObject, Sendable {
// MARK: - Connection Events

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

Expand All @@ -45,14 +46,25 @@ public protocol RoomDelegate: AnyObject, Sendable {
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.
/// - Note: This method is not called for ``ReconnectMode/quick``, use ``RoomDelegate/room(_:didStartReconnectWithMode:)`` instead.
@objc optional
func roomIsReconnecting(_ room: Room)

/// Successfully re-connected to the room.
/// - Note: This method is not called for ``ReconnectMode/quick``, use ``RoomDelegate/room(_:didCompleteReconnectWithMode:)`` instead.
@objc optional
func roomDidReconnect(_ room: Room)

/// Reconnection started.
/// - Parameter reconnectMode: The mode being used for reconnection
@objc optional
func room(_ room: Room, didStartReconnectWithMode reconnectMode: ReconnectMode)

/// Reconnection completed successfully.
/// - Parameter reconnectMode: The mode that was used for reconnection
@objc optional
func room(_ room: Room, didCompleteReconnectWithMode reconnectMode: ReconnectMode)

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