diff --git a/Sources/DolbyIORTSCore/Model/StreamError.swift b/Sources/DolbyIORTSCore/Model/StreamError.swift index 3d06d95..70ab6ba 100644 --- a/Sources/DolbyIORTSCore/Model/StreamError.swift +++ b/Sources/DolbyIORTSCore/Model/StreamError.swift @@ -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) } diff --git a/Sources/DolbyIORTSCore/Model/StreamState.swift b/Sources/DolbyIORTSCore/Model/StreamState.swift index b8c68c4..9730cab 100644 --- a/Sources/DolbyIORTSCore/Model/StreamState.swift +++ b/Sources/DolbyIORTSCore/Model/StreamState.swift @@ -32,7 +32,7 @@ public enum StreamState: Equatable { numberOfStreamViewers: state.numberOfStreamViewers ) } else { - self = .error(.connectFailed(reason: "")) + self = .stopped } case .stopped: diff --git a/Sources/DolbyIORTSCore/State/StateMachine.swift b/Sources/DolbyIORTSCore/State/StateMachine.swift index b5bd046..d4d2976 100644 --- a/Sources/DolbyIORTSCore/State/StateMachine.swift +++ b/Sources/DolbyIORTSCore/State/StateMachine.swift @@ -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() { diff --git a/Sources/DolbyIORTSUIKit/Private/ViewModels/StreamViewModel.swift b/Sources/DolbyIORTSUIKit/Private/ViewModels/StreamViewModel.swift index edb94a5..2f91e89 100644 --- a/Sources/DolbyIORTSUIKit/Private/ViewModels/StreamViewModel.swift +++ b/Sources/DolbyIORTSUIKit/Private/ViewModels/StreamViewModel.swift @@ -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) diff --git a/Sources/DolbyIORTSUIKit/Private/Views/Error/ErrorViewModel.swift b/Sources/DolbyIORTSUIKit/Private/Views/Error/ErrorViewModel.swift index 0028862..8d9aa4d 100644 --- a/Sources/DolbyIORTSUIKit/Private/Views/Error/ErrorViewModel.swift +++ b/Sources/DolbyIORTSUIKit/Private/Views/Error/ErrorViewModel.swift @@ -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: diff --git a/Sources/DolbyIORTSUIKit/Private/Views/LiveIndicator/LiveIndicatorViewModel.swift b/Sources/DolbyIORTSUIKit/Private/Views/LiveIndicator/LiveIndicatorViewModel.swift index 60fd455..f6ef680 100644 --- a/Sources/DolbyIORTSUIKit/Private/Views/LiveIndicator/LiveIndicatorViewModel.swift +++ b/Sources/DolbyIORTSUIKit/Private/Views/LiveIndicator/LiveIndicatorViewModel.swift @@ -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