From 4d2e16651594b890c797b2b83f5543a67e54f378 Mon Sep 17 00:00:00 2001 From: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Tue, 22 Feb 2022 14:33:12 +0700 Subject: [PATCH] Squashed commit of the following: commit 25a82f42a780b7cf87d54cb5bed7972269fdbd1d Author: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Tue Feb 22 14:32:25 2022 +0700 use 0.9.8 commit 361a1d9bd721ac691c3673e3dcb591107b36ff38 Author: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Tue Feb 22 02:10:55 2022 +0700 Update RoomView.swift commit c91859318f6d623aa07d590ec911735650063103 Author: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Mon Feb 21 19:40:51 2022 +0700 Update Package.resolved commit c8a56d5808c0ff98eb62a1617e0f1b57d613404d Author: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Mon Feb 21 19:18:32 2022 +0700 adjustments commit d11eae4d8b9da19728b6c291b27cdab008354e1b Author: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Sat Feb 19 00:43:43 2022 +0700 center align commit 4f1f56589fd5f2ae260a6cfb5b999970f2db0be2 Author: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Fri Feb 18 15:30:10 2022 +0700 show video stats --- .../xcshareddata/swiftpm/Package.resolved | 4 +- LiveKitExample.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/swiftpm/Package.resolved | 8 +-- .../xcschemes/LiveKitExample (macOS).xcscheme | 1 - Shared/Controllers/RoomContext.swift | 8 ++- Shared/ExampleObservableRoom.swift | 11 +++- Shared/ParticipantView.swift | 65 ++++++++++++++----- Shared/RoomView.swift | 15 +++-- 8 files changed, 81 insertions(+), 33 deletions(-) diff --git a/LiveKitExample-dev.xcworkspace/xcshareddata/swiftpm/Package.resolved b/LiveKitExample-dev.xcworkspace/xcshareddata/swiftpm/Package.resolved index b714a17..1d75654 100644 --- a/LiveKitExample-dev.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/LiveKitExample-dev.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -33,8 +33,8 @@ "repositoryURL": "https://github.com/webrtc-sdk/Specs.git", "state": { "branch": null, - "revision": "f83999edabf06600cf4ff8ccd5647c333ba27e98", - "version": "93.4577.2" + "revision": "063f852f5e6150c9006ba884c2664ed1c868ddb1", + "version": "97.4692.2" } }, { diff --git a/LiveKitExample.xcodeproj/project.pbxproj b/LiveKitExample.xcodeproj/project.pbxproj index 2cc6adb..15334ad 100644 --- a/LiveKitExample.xcodeproj/project.pbxproj +++ b/LiveKitExample.xcodeproj/project.pbxproj @@ -792,7 +792,7 @@ repositoryURL = "https://github.com/livekit/client-sdk-swift"; requirement = { kind = exactVersion; - version = 0.9.7; + version = 0.9.8; }; }; 68816CBF27B4D6BC00E24622 /* XCRemoteSwiftPackageReference "KeychainAccess" */ = { diff --git a/LiveKitExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/LiveKitExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 3759d41..1085135 100644 --- a/LiveKitExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/LiveKitExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -6,8 +6,8 @@ "repositoryURL": "https://github.com/livekit/client-sdk-swift", "state": { "branch": null, - "revision": "3bb9469ddc88f7355ff4a56b04a8a7bb27f81140", - "version": "0.9.7" + "revision": "600994caf57ebe0052e339462a3c0786bdf3f981", + "version": "0.9.8" } }, { @@ -42,8 +42,8 @@ "repositoryURL": "https://github.com/webrtc-sdk/Specs.git", "state": { "branch": null, - "revision": "f83999edabf06600cf4ff8ccd5647c333ba27e98", - "version": "93.4577.2" + "revision": "063f852f5e6150c9006ba884c2664ed1c868ddb1", + "version": "97.4692.2" } }, { diff --git a/LiveKitExample.xcodeproj/xcshareddata/xcschemes/LiveKitExample (macOS).xcscheme b/LiveKitExample.xcodeproj/xcshareddata/xcschemes/LiveKitExample (macOS).xcscheme index 8bbdd9b..7a14266 100644 --- a/LiveKitExample.xcodeproj/xcshareddata/xcschemes/LiveKitExample (macOS).xcscheme +++ b/LiveKitExample.xcodeproj/xcshareddata/xcschemes/LiveKitExample (macOS).xcscheme @@ -34,7 +34,6 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - enableAddressSanitizer = "YES" enableASanStackUseAfterReturn = "YES" launchStyle = "0" useCustomWorkingDirectory = "NO" diff --git a/Shared/Controllers/RoomContext.swift b/Shared/Controllers/RoomContext.swift index ad7e9f0..0d824a0 100644 --- a/Shared/Controllers/RoomContext.swift +++ b/Shared/Controllers/RoomContext.swift @@ -97,7 +97,13 @@ final class RoomContext: ObservableObject { extension RoomContext: RoomDelegate { - func room(_ room: Room, didUpdate connectionState: ConnectionState) { + func room(_ room: Room, didUpdate connectionState: ConnectionState, oldValue: ConnectionState) { + + guard !connectionState.isEqual(to: oldValue, includingAssociatedValues: false) else { + print("Skipping same conectionState") + return + } + print("Did update connectionState \(connectionState) \(room.connectionState)") if let error = connectionState.disconnectedWithError { diff --git a/Shared/ExampleObservableRoom.swift b/Shared/ExampleObservableRoom.swift index 088e511..2d357f1 100644 --- a/Shared/ExampleObservableRoom.swift +++ b/Shared/ExampleObservableRoom.swift @@ -151,8 +151,15 @@ class ExampleObservableRoom: ObservableRoom { // MARK: - RoomDelegate - override func room(_ room: Room, didUpdate connectionState: ConnectionState) { - super.room(room, didUpdate: connectionState) + override func room(_ room: Room, didUpdate connectionState: ConnectionState, oldValue: ConnectionState) { + + super.room(room, didUpdate: connectionState, oldValue: oldValue) + + guard !connectionState.isEqual(to: oldValue, includingAssociatedValues: false) else { + print("Skipping same conectionState") + return + } + if case .disconnected = connectionState { DispatchQueue.main.async { // Reset state diff --git a/Shared/ParticipantView.swift b/Shared/ParticipantView.swift index 8d931e9..005c2ff 100644 --- a/Shared/ParticipantView.swift +++ b/Shared/ParticipantView.swift @@ -11,6 +11,7 @@ struct ParticipantView: View { var onTap: ((_ participant: ObservableParticipant) -> Void)? @State private var dimensions: Dimensions? + @State private var trackStats: TrackStats? func bgView(systemSymbol: SFSymbol, geometry: GeometryProxy) -> some View { Image(systemSymbol: systemSymbol) @@ -43,31 +44,61 @@ struct ParticipantView: View { mode: videoViewMode, mirrored: appCtx.videoViewMirrored ? !shouldMirror : shouldMirror, dimensions: $dimensions, + trackStats: $trackStats, preferMetal: appCtx.preferMetal) .background(Color.black) // .scaleEffect(CGSize(width: -1.0, height: 1.0))// flip local view horizontally // Show the actual video dimensions (if enabled) if appCtx.showInformationOverlay { - VStack(alignment: .leading) { - Text("Metal: \(String(describing: appCtx.preferMetal))") - .foregroundColor(Color.white) - .padding(3) - .background(Color.black) - .cornerRadius(8) - Text("Mirrored: \(String(describing: shouldMirror))") - .foregroundColor(Color.white) - .padding(3) - .background(Color.black) - .cornerRadius(8) - if let dimensions = dimensions { - Text("\(dimensions.width)x\(dimensions.height)") - .foregroundColor(Color.white) - .padding(3) - .background(Color.lkBlue) - .cornerRadius(8) + HStack(alignment: .top, spacing: 5) { + VStack(alignment: .leading, spacing: 5) { + Text("View") + .fontWeight(.bold) + Text("metal: \(String(describing: appCtx.preferMetal))") + Text("mirror: \(String(describing: shouldMirror))") } + .font(.system(size: 10)) + .foregroundColor(Color.white) + .padding(5) + .background(Color.black.opacity(0.5)) + .cornerRadius(8) + + VStack(alignment: .leading, spacing: 5) { + Text("Video") + .fontWeight(.bold) + + HStack(alignment: .top, spacing: 3) { + if let dimensions = dimensions { + Text("\(dimensions.width)x\(dimensions.height)") + } + if let codecName = trackStats?.codecName { + HStack(spacing: 3) { + Text(codecName) + .fontWeight(.bold) + } + } + } + + if let trackStats = trackStats, trackStats.bpsSent != 0 { + HStack(spacing: 3) { + Image(systemSymbol: .arrowUpCircle) + Text(trackStats.formattedBpsSent()) + } + } + if let trackStats = trackStats, trackStats.bpsReceived != 0 { + HStack(spacing: 3) { + Image(systemSymbol: .arrowDownCircle) + Text(trackStats.formattedBpsReceived()) + } + } + } + .font(.system(size: 10)) + .foregroundColor(Color.white) + .padding(5) + .background(Color.black.opacity(0.5)) + .cornerRadius(8) } .padding() } diff --git a/Shared/RoomView.swift b/Shared/RoomView.swift index ad50a89..020ecd0 100644 --- a/Shared/RoomView.swift +++ b/Shared/RoomView.swift @@ -222,6 +222,7 @@ struct RoomView: View { .toolbar { ToolbarItemGroup(placement: toolbarPlacement) { + #if os(macOS) if let name = room.room.name { Text(name) .fontWeight(.bold) @@ -230,6 +231,7 @@ struct RoomView: View { if let identity = room.room.localParticipant?.identity { Text(identity) } + #endif #if os(macOS) // Pin on top @@ -412,12 +414,12 @@ struct RoomView: View { struct ParticipantLayout: View { let views: [AnyView] - let spacing: CGFloat? + let spacing: CGFloat init( _ data: Data, id: KeyPath = \.self, - spacing: CGFloat? = nil, + spacing: CGFloat, @ViewBuilder content: @escaping (Data.Element) -> Content) { self.spacing = spacing self.views = data.map { AnyView(content($0[keyPath: id])) } @@ -430,7 +432,7 @@ struct ParticipantLayout: View { return (x: c[0], y: c[1]) } - func grid(axis: Axis) -> some View { + func grid(axis: Axis, geometry: GeometryProxy) -> some View { ScrollView([ axis == .vertical ? .vertical : .horizontal ]) { HorVGrid(axis: axis, columns: [GridItem(.flexible())], spacing: spacing) { ForEach(0..: View { .aspectRatio(1, contentMode: .fill) } } + .padding(axis == .horizontal ? [.leading, .trailing] : [.top, .bottom], + max(0, ((axis == .horizontal ? geometry.size.width : geometry.size.height) + - ((axis == .horizontal ? geometry.size.height : geometry.size.width) * CGFloat(views.count)) - (spacing * CGFloat(views.count - 1))) / 2)) } } @@ -446,9 +451,9 @@ struct ParticipantLayout: View { if views.isEmpty { EmptyView() } else if geometry.size.width <= 300 { - grid(axis: .vertical) + grid(axis: .vertical, geometry: geometry) } else if geometry.size.height <= 300 { - grid(axis: .horizontal) + grid(axis: .horizontal, geometry: geometry) } else { let verticalWhenTall: Axis = geometry.isTall ? .vertical : .horizontal