File tree Expand file tree Collapse file tree 3 files changed +28
-1
lines changed
Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 66//
77
88import SwiftUI
9+ import LiveViewNativeCore
910
1011/// An object that configures the behavior of a ``LiveSessionCoordinator``.
1112public struct LiveSessionConfiguration {
@@ -99,3 +100,26 @@ public struct LiveSessionConfiguration {
99100 public static let never : Self = . init( )
100101 }
101102}
103+
104+
105+ public final class ReconnectStrategyAdapter : SocketReconnectStrategy {
106+
107+ private let behavior : LiveSessionConfiguration . ReconnectBehavior
108+
109+ public init ( _ behavior: LiveSessionConfiguration . ReconnectBehavior ) {
110+ self . behavior = behavior
111+ }
112+
113+ public func sleepDuration( _ attempt: UInt64 ) -> TimeInterval {
114+
115+ guard let delay = behavior. delay else {
116+ return TimeInterval . greatestFiniteMagnitude
117+ }
118+
119+ let safeAttempt = min ( Int ( attempt) , Int . max)
120+ return delay ( safeAttempt)
121+ }
122+
123+
124+ }
125+
Original file line number Diff line number Diff line change @@ -216,6 +216,8 @@ public class LiveSessionCoordinator<R: RootRegistry>: ObservableObject {
216216 try await socket. shutdown ( )
217217 }
218218
219+ let adapter = ReconnectStrategyAdapter ( self . configuration. reconnectBehavior)
220+
219221 self . liveSocket = try await LiveSocket (
220222 originalURL. absoluteString,
221223 LiveSessionParameters . platform,
@@ -225,6 +227,7 @@ public class LiveSessionCoordinator<R: RootRegistry>: ObservableObject {
225227 method: httpMethod. flatMap ( Method . init ( _: ) ) ,
226228 timeoutMs: 10_000
227229 )
230+ adapter,
228231 )
229232
230233 // save cookies to storage
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ public struct LiveErrorView<Fallback: View>: View {
2929 case let . ConnectionError( trace) = error
3030 {
3131 SwiftUI . VStack {
32- WebErrorView ( html: trace)
32+ WebErrorView ( html: trace. errorText )
3333 #if os(watchOS) || os(tvOS)
3434 SwiftUI . Button {
3535 Task {
You can’t perform that action at this time.
0 commit comments