Skip to content

Commit 705a500

Browse files
reconnect on an error in any reply, should push to flash
1 parent dd02963 commit 705a500

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

Sources/LiveViewNative/Coordinators/LiveSessionCoordinator.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,7 @@ public class LiveSessionCoordinator<R: RootRegistry>: ObservableObject {
266266
}
267267
}
268268

269-
let liveChannel = try await self.liveSocket!.joinLiveviewChannel(
270-
.some([
271-
"_format": .str(string: LiveSessionParameters.platform),
272-
"_interface": .object(object: LiveSessionParameters.platformParams)
273-
]),
274-
nil
275-
)
276-
277-
self.navigationPath.last!.coordinator.join(liveChannel)
269+
try await self.joinLiveViewChannel()
278270

279271
self.state = .connected
280272

@@ -328,6 +320,18 @@ public class LiveSessionCoordinator<R: RootRegistry>: ObservableObject {
328320

329321
}
330322
}
323+
324+
func joinLiveViewChannel() async throws {
325+
let liveChannel = try await self.liveSocket!.joinLiveviewChannel(
326+
.some([
327+
"_format": .str(string: LiveSessionParameters.platform),
328+
"_interface": .object(object: LiveSessionParameters.platformParams)
329+
]),
330+
nil
331+
)
332+
333+
self.navigationPath.last?.coordinator.join(liveChannel)
334+
}
331335

332336
private func disconnect(preserveNavigationPath: Bool = false) async {
333337
do {

Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ public class LiveViewCoordinator<R: RootRegistry>: ObservableObject {
270270
guard !Task.isCancelled else { return }
271271
do {
272272
switch event.event {
273+
case .phoenix(phoenix: .error):
274+
logger.error("encountered error in reply - channel reconnecting");
275+
try await session.joinLiveViewChannel()
273276
case .user(user: "diff"):
274277
switch event.payload {
275278
case let .jsonPayload(json):

0 commit comments

Comments
 (0)