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
22 changes: 13 additions & 9 deletions Sources/LiveViewNative/Coordinators/LiveSessionCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,7 @@ public class LiveSessionCoordinator<R: RootRegistry>: ObservableObject {
}
}

let liveChannel = try await self.liveSocket!.joinLiveviewChannel(
.some([
"_format": .str(string: LiveSessionParameters.platform),
"_interface": .object(object: LiveSessionParameters.platformParams)
]),
nil
)

self.navigationPath.last!.coordinator.join(liveChannel)
try await self.joinLiveViewChannel()

self.state = .connected

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

}
}

func joinLiveViewChannel() async throws {
let liveChannel = try await self.liveSocket!.joinLiveviewChannel(
.some([
"_format": .str(string: LiveSessionParameters.platform),
"_interface": .object(object: LiveSessionParameters.platformParams)
]),
nil
)

self.navigationPath.last?.coordinator.join(liveChannel)
}

private func disconnect(preserveNavigationPath: Bool = false) async {
do {
Expand Down
8 changes: 8 additions & 0 deletions Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ public class LiveViewCoordinator<R: RootRegistry>: ObservableObject {
guard !Task.isCancelled else { return }
do {
switch event.event {
case .phoenix(phoenix: .error):
logger.error("encountered error in reply - channel reconnecting");
if let liveChannel {
let channel = liveChannel.channel()
try await channel.shutdown()
}
try await session.joinLiveViewChannel()
case .user(user: "diff"):
switch event.payload {
case let .jsonPayload(json):
Expand Down Expand Up @@ -342,6 +349,7 @@ public class LiveViewCoordinator<R: RootRegistry>: ObservableObject {
}

func join(_ liveChannel: LiveViewNativeCore.LiveChannel) {

self.liveChannel = liveChannel
let channel = liveChannel.channel()
self.channel = channel
Expand Down
Loading