Skip to content

Commit

Permalink
Merge pull request #209 from dolbyio-samples/bugfix/rts-viewer-stats
Browse files Browse the repository at this point in the history
Bugfix/rts viewer stats
  • Loading branch information
aravind-raveendran authored Aug 20, 2024
2 parents c40d25f + 86d4068 commit e68999e
Show file tree
Hide file tree
Showing 13 changed files with 298 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,10 @@ public actor SubscriptionManager {
public func unSubscribe() async throws {
Self.logger.debug("👨‍🔧 Stop subscription")
await subscriber.enableStats(false)
reset()
try await subscriber.unsubscribe()
try await subscriber.disconnect()
Self.logger.debug("👨‍🔧 Successfully stopped subscription")

reset()
}

private func reset() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,11 @@ private extension StatsInfoViewModel {

static func formatBitRate(bitRate: Double) -> String {
if bitRate < KILOBITS {
"\(bitRate)bps"
"\(bitRate) bps"
} else if bitRate >= KILOBITS && bitRate < MEGABITS {
"\((bitRate / KILOBITS).rounded(toPlaces: 4))Kbps"
"\((bitRate / KILOBITS).rounded(toPlaces: 4)) Kbps"
} else {
"\((bitRate / MEGABITS).rounded(toPlaces: 4))Mbps"
"\((bitRate / MEGABITS).rounded(toPlaces: 4)) Mbps"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class StreamViewModel: ObservableObject {
selectedAudioSource: StreamSource?,
settings: StreamSettings
)
case error(title: String, subtitle: String?)
case error(title: String, subtitle: String?, showLiveIndicator: Bool)
}

let subscriptionManager: SubscriptionManager
Expand Down Expand Up @@ -166,7 +166,7 @@ final class StreamViewModel: ObservableObject {
case .connectionOrder:
sortedSources = sources
case .alphaNumeric:
sortedSources = sources.sorted { $0 < $1 }
sortedSources = sources.sorted { $0.sourceId.description < $1.sourceId.description }
}

let selectedVideoSource: StreamSource
Expand Down Expand Up @@ -288,7 +288,13 @@ private extension StreamViewModel {
await self.updateAudioSourceListing(for: activeSources, currentSettings: settings)
guard let newState = await self.makeState(from: activeSources, settings: settings) else {
Self.logger.debug("🎰 Make state returned without a value")
await self.update(state: .error(title: .offlineErrorTitle, subtitle: .offlineErrorSubtitle))
await self.update(
state: .error(
title: .offlineErrorTitle,
subtitle: .offlineErrorSubtitle,
showLiveIndicator: true
)
)
return
}
await self.update(state: newState)
Expand All @@ -303,14 +309,26 @@ private extension StreamViewModel {
if await !self.isWebsocketConnected {
await self.scheduleReconnection()
}
await self.update(state: .error(title: .noInternetErrorTitle, subtitle: nil))
await self.update(
state: .error(
title: .noInternetErrorTitle,
subtitle: nil,
showLiveIndicator: false
)
)

case let .error(connectionError):
Self.logger.debug("🎰 Connection error - \(connectionError.status), \(connectionError.reason)")
if await !self.isWebsocketConnected {
await self.scheduleReconnection()
}
await self.update(state: .error(title: .offlineErrorTitle, subtitle: .offlineErrorSubtitle))
await self.update(
state: .error(
title: .offlineErrorTitle,
subtitle: .offlineErrorSubtitle,
showLiveIndicator: true
)
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ struct StreamingView: View {
// swiftlint:enable function_body_length

@ViewBuilder
private func errorView(title: String, subtitle: String?) -> some View {
private func errorView(title: String, subtitle: String?, showLiveIndicator: Bool) -> some View {
ErrorView(title: title, subtitle: subtitle)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.overlay(alignment: .topTrailing) {
closeButton
}
.overlay(alignment: .topLeading) {
if shouldShowLiveIndicatorView {
if showLiveIndicator {
liveIndicatorView
}
}
Expand Down Expand Up @@ -249,8 +249,8 @@ struct StreamingView: View {
)
case .loading:
progressView
case let .error(title: title, subtitle: subtitle):
errorView(title: title, subtitle: subtitle)
case let .error(title: title, subtitle: subtitle, showLiveIndicator: showLiveIndicator):
errorView(title: title, subtitle: subtitle, showLiveIndicator: showLiveIndicator)
}
}
.navigationBarTitleDisplayMode(.inline)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/millicast/millicast-sdk-swift-package",
"state" : {
"revision" : "650bda49e494524b53531dedbd29b60a13477418",
"version" : "2.0.0-beta.6"
"revision" : "d20cb45ff24acbc16191d4df6a0e4be9daa26e24",
"version" : "2.0.0-beta.7"
}
}
],
Expand Down
4 changes: 4 additions & 0 deletions rts-viewer-tvos/RTSViewer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
E8752B69298CA513002D5C2B /* StreamDataManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8752B68298CA513002D5C2B /* StreamDataManagerTests.swift */; };
E8752B72298CA78D002D5C2B /* MockDateProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8752B71298CA78D002D5C2B /* MockDateProvider.swift */; };
E8752B74298CB535002D5C2B /* MockStreamDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8752B73298CB535002D5C2B /* MockStreamDataManager.swift */; };
E89D28902C747AFE002254AB /* SerialTasks.swift in Sources */ = {isa = PBXBuildFile; fileRef = E89D288F2C747AFE002254AB /* SerialTasks.swift */; };
E8B48E86297A2957000DC59A /* RecentStreamButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8B48E84297A2957000DC59A /* RecentStreamButton.swift */; };
E8BA8E102991CB0E0043DEE1 /* StreamingViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8BA8E0E2991CB0E0043DEE1 /* StreamingViewModel.swift */; };
E8BA8E192991E8B30043DEE1 /* SimulcastViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8BA8E172991E8B30043DEE1 /* SimulcastViewModel.swift */; };
Expand Down Expand Up @@ -120,6 +121,7 @@
E8752B68298CA513002D5C2B /* StreamDataManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StreamDataManagerTests.swift; sourceTree = "<group>"; };
E8752B71298CA78D002D5C2B /* MockDateProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockDateProvider.swift; sourceTree = "<group>"; };
E8752B73298CB535002D5C2B /* MockStreamDataManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockStreamDataManager.swift; sourceTree = "<group>"; };
E89D288F2C747AFE002254AB /* SerialTasks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SerialTasks.swift; sourceTree = "<group>"; };
E8B48E84297A2957000DC59A /* RecentStreamButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecentStreamButton.swift; sourceTree = "<group>"; };
E8BA8E0E2991CB0E0043DEE1 /* StreamingViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StreamingViewModel.swift; sourceTree = "<group>"; };
E8BA8E172991E8B30043DEE1 /* SimulcastViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimulcastViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -227,6 +229,7 @@
E82FC5042977CF2A0050777F /* Utils */ = {
isa = PBXGroup;
children = (
E89D288F2C747AFE002254AB /* SerialTasks.swift */,
E83CDA4F2A1092A3008690FD /* ImageAsset.swift */,
E8752B50298C7D02002D5C2B /* DateProvider.swift */,
);
Expand Down Expand Up @@ -578,6 +581,7 @@
631DD25826F1E18E0023D24A /* ContentView.swift in Sources */,
E83F0F932C192D4B00F6FA6B /* SettingsViewModel.swift in Sources */,
E83CDA492A10917A008690FD /* BackgroundContainerView.swift in Sources */,
E89D28902C747AFE002254AB /* SerialTasks.swift in Sources */,
6D61AA07299F51AC004CAF9E /* VideoView.swift in Sources */,
E82A0C1E296D0F04007214B8 /* StreamDetailInputView.swift in Sources */,
E8752B4B298C72F7002D5C2B /* CoreDataManager.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/millicast/millicast-sdk-swift-package",
"state" : {
"revision" : "9f95549d5a554a9de5b435149d90f2e0d40724bd",
"version" : "2.0.0-beta.3"
"revision" : "d20cb45ff24acbc16191d4df6a0e4be9daa26e24",
"version" : "2.0.0-beta.7"
}
}
],
Expand Down
2 changes: 2 additions & 0 deletions rts-viewer-tvos/RTSViewer/Resources/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,5 @@
"stream.stats.packets-received.label" = "Packets Received";
"stream.stats.timestamp.label" = "Timestamp (GMT)";
"stream.stats.total-stream-time.label" = "Total Stream Time";
"stream.stats.target-bitrate.label" = "Target Bitrate";
"stream.stats.outgoing-bitrate.label" = "Outgoing Bitrate";
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,26 @@
//

import DolbyIOUIKit
import SwiftUI
import RTSCore
import Foundation
import MillicastSDK
import RTSCore
import SwiftUI

struct StatisticsView: View {
private let viewModel: StatisticsViewModel

init(source: StreamSource, streamStatistics: StreamStatistics) {
viewModel = StatisticsViewModel(source: source, streamStatistics: streamStatistics)
init(
source: StreamSource,
streamStatistics: StreamStatistics,
layers: [MCRTSRemoteTrackLayer],
projectedTimeStamp: Double?
) {
viewModel = StatisticsViewModel(
source: source,
streamStatistics: streamStatistics,
layers: layers,
projectedTimeStamp: projectedTimeStamp
)
}

private let fontAssetTable = FontAsset.avenirNextRegular(size: FontSize.caption2, style: .caption2)
Expand All @@ -31,7 +42,7 @@ struct StatisticsView: View {

HStack {
Text(text: "stream.stats.name.label", fontAsset: fontAssetCaption)
.frame(maxWidth: 350, alignment: .leading)
.frame(maxWidth: 250, alignment: .leading)
Text(text: "stream.stats.value.label", fontAsset: fontAssetCaption)
}
.frame(maxWidth: .infinity, alignment: .leading)
Expand All @@ -43,15 +54,15 @@ struct StatisticsView: View {
HStack {
Text(item.key)
.font(theme[fontAssetTable])
.frame(maxWidth: 350, alignment: .leading)
.frame(maxWidth: 250, alignment: .leading)
Text(item.value)
.font(fontTable)
}
.frame(maxWidth: .infinity, alignment: .leading)
}
}
.frame(maxWidth: 700)
.padding(35)
.frame(maxWidth: 850)
.padding(20)
.background {
Color(uiColor: UIColor.Neutral.neutral800)
.opacity(0.7)
Expand Down
Loading

0 comments on commit e68999e

Please sign in to comment.