Skip to content

Commit

Permalink
fix legacy connection delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroshihorie committed Oct 21, 2023
1 parent 0b78389 commit cc56faa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Sources/LiveKit/Core/Room+EngineDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ extension Room: EngineDelegate {
delegateSwift.room(self, didUpdate: state.connectionState, oldValue: oldState.connectionState)
}
}

// Legacy connection delegates
if case .connected = state.connectionState {
let didReconnect = oldState.connectionState == .reconnecting
delegates.notify { $0.room?(self, didConnect: didReconnect) }
} else if case .disconnected(let reason) = state.connectionState {
if case .connecting = oldState.connectionState {
let error = reason?.networkError ?? NetworkError.disconnected(message: "Did fail to connect", rawError: nil)
delegates.notify { $0.room?(self, didFailToConnect: error) }
} else {
delegates.notify { $0.room?(self, didDisconnect: reason?.networkError) }
}
}
}

if state.connectionState.isReconnecting && state.reconnectMode == .full && oldState.reconnectMode != .full {
Expand Down
1 change: 1 addition & 0 deletions Sources/LiveKit/Protocols/RoomDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public protocol RoomDelegateObjC: AnyObject {
func room(_ room: Room, didFailToConnect error: Error)

/// Client disconnected from the room unexpectedly.
/// Using ``room(_:didUpdate:oldValue:)`` is preferred since `.disconnected` state of ``ConnectionState`` provides ``DisconnectReason`` (Swift only).
@objc(room:didDisconnectWithError:) optional
func room(_ room: Room, didDisconnect error: Error?)

Expand Down

0 comments on commit cc56faa

Please sign in to comment.