Skip to content

Commit

Permalink
Network handling fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aravind-raveendran committed Oct 19, 2023
1 parent 28b7924 commit 2c4bad4
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 5 deletions.
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

0 comments on commit 2c4bad4

Please sign in to comment.