Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network handling fixes #43

Merged
merged 1 commit into from
Oct 20, 2023
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
2 changes: 1 addition & 1 deletion Sources/DolbyIORTSCore/Model/StreamError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import Foundation

public enum StreamError: Error, Equatable {
case subscribeFailed(reason: String)
case connectFailed(reason: String)
case connectFailed(reason: String, status: Int32)
case signalingError(reason: String)
}
2 changes: 1 addition & 1 deletion Sources/DolbyIORTSCore/Model/StreamState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public enum StreamState: Equatable {
numberOfStreamViewers: state.numberOfStreamViewers
)
} else {
self = .error(.connectFailed(reason: ""))
self = .stopped
}

case .stopped:
Expand Down
2 changes: 1 addition & 1 deletion Sources/DolbyIORTSCore/State/StateMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ final class StateMachine {
}

func onConnectionError(_ status: Int32, withReason reason: String) {
currentState = .error(.init(error: .connectFailed(reason: reason)))
currentState = .error(.init(error: .connectFailed(reason: reason, status: status)))
}

func onDisconnected() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,10 @@ final class StreamViewModel: ObservableObject {
self.internalState = .loading
case let .error(streamError):
self.internalState = .error(ErrorViewModel(error: streamError))
case .stopped, .disconnected:
case .stopped:
self.internalState = .error(.streamOffline)
case .disconnected:
self.internalState = .error(.noInternet)
}
}
.store(in: &self.subscriptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ final class ErrorViewModel {
switch error {
case let streamError as StreamError:
switch streamError {
case .connectFailed(reason: _, status: 0):
// Status code `0` represents a `no network` error code
return (.noInternetErrorTitle, nil)
case .connectFailed:
return (.offlineErrorTitle, .offlineErrorSubtitle)
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class LiveIndicatorViewModel: ObservableObject {
}

private func setupStateObservers() {
Task { [weak self] in
Task { @StreamOrchestrator [weak self] in
guard let self = self else { return }

await self.streamOrchestrator.statePublisher
Expand Down