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

Implement VisibilityThresholdModifier #173

Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### 🔄 Changed
- Factory method for creating `LocalParticipantViewModifier`
- `availableSize` has been replaced by `availableFrame` in most Views.

# [0.3.0](https://github.com/GetStream/stream-video-swift/releases/tag/0.3.0)
_August 25, 2023_
Expand Down
4 changes: 2 additions & 2 deletions DemoApp/Sources/Components/DemoAppViewFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ final class DemoAppViewFactory: ViewFactory {
func makeVideoCallParticipantModifier(
participant: CallParticipant,
call: Call?,
availableSize: CGSize,
availableFrame: CGRect,
ratio: CGFloat,
showAllInfo: Bool
) -> some ViewModifier {
DemoVideoCallParticipantModifier(
participant: participant,
call: call,
availableSize: availableSize,
availableFrame: availableFrame,
ratio: ratio,
showAllInfo: showAllInfo
)
Expand Down
18 changes: 9 additions & 9 deletions DemoApp/Sources/Examples/Examples.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,22 @@ struct CustomVideoCallParticipantView: View {

let participant: CallParticipant
var id: String
var availableSize: CGSize
var availableFrame: CGRect
var contentMode: UIView.ContentMode
var edgesIgnoringSafeArea: Edge.Set
var onViewUpdate: (CallParticipant, VideoRenderer) -> Void

public init(
participant: CallParticipant,
id: String? = nil,
availableSize: CGSize,
availableFrame: CGRect,
contentMode: UIView.ContentMode,
edgesIgnoringSafeArea: Edge.Set = .all,
onViewUpdate: @escaping (CallParticipant, VideoRenderer) -> Void
) {
self.participant = participant
self.id = id ?? participant.id
self.availableSize = availableSize
self.availableFrame = availableFrame
self.contentMode = contentMode
self.edgesIgnoringSafeArea = edgesIgnoringSafeArea
self.onViewUpdate = onViewUpdate
Expand All @@ -97,7 +97,7 @@ struct CustomVideoCallParticipantView: View {
public var body: some View {
VideoRendererView(
id: id,
size: availableSize,
size: availableFrame.size,
contentMode: contentMode
) { view in
onViewUpdate(participant, view)
Expand All @@ -113,7 +113,7 @@ struct CustomVideoCallParticipantView: View {
startPoint: .top,
endPoint: .bottom
)
.frame(width: availableSize.width)
.frame(width: availableFrame.width)
.opacity(showVideo ? 0 : 1)

ZStack {
Expand Down Expand Up @@ -142,26 +142,26 @@ struct CustomParticipantModifier: ViewModifier {
var participant: CallParticipant
@Binding var pinnedParticipant: CallParticipant?
var participantCount: Int
var availableSize: CGSize
var availableFrame: CGRect
var ratio: CGFloat

public init(
participant: CallParticipant,
pinnedParticipant: Binding<CallParticipant?>,
participantCount: Int,
availableSize: CGSize,
availableFrame: CGRect,
ratio: CGFloat
) {
self.participant = participant
_pinnedParticipant = pinnedParticipant
self.participantCount = participantCount
self.availableSize = availableSize
self.availableFrame = availableFrame
self.ratio = ratio
}

public func body(content: Content) -> some View {
content
.adjustVideoFrame(to: availableSize.width, ratio: ratio)
.adjustVideoFrame(to: availableFrame.width, ratio: ratio)
.overlay(
ZStack {
VStack {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ struct DemoVideoCallParticipantModifier: ViewModifier {

var participant: CallParticipant
var call: Call?
var availableSize: CGSize
var availableFrame: CGRect
var ratio: CGFloat
var showAllInfo: Bool

init(
participant: CallParticipant,
call: Call?,
availableSize: CGSize,
availableFrame: CGRect,
ratio: CGFloat,
showAllInfo: Bool
) {
self.participant = participant
self.call = call
self.availableSize = availableSize
self.availableFrame = availableFrame
self.ratio = ratio
self.showAllInfo = showAllInfo
}

func body(content: Content) -> some View {
content
.adjustVideoFrame(to: availableSize.width, ratio: ratio)
.adjustVideoFrame(to: availableFrame.size.width, ratio: ratio)
.overlay(
ZStack {
BottomView(content: {
Expand Down Expand Up @@ -83,7 +83,7 @@ struct DemoVideoCallParticipantModifier: ViewModifier {
}
}
)
.modifier(ReactionsViewModifier(participant: participant, availableSize: availableSize))
.modifier(ReactionsViewModifier(participant: participant, availableSize: availableFrame.size))
.onTapGesture(count: 2, perform: {
popoverShown = true
})
Expand Down
8 changes: 5 additions & 3 deletions Sources/StreamVideo/WebRTC/StreamVideoCaptureHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
//

import Foundation
import WebRTC
@preconcurrency import WebRTC

final class StreamVideoCaptureHandler: NSObject, RTCVideoCapturerDelegate {

class StreamVideoCaptureHandler: NSObject, RTCVideoCapturerDelegate {

let source: RTCVideoSource
let filters: [VideoFilter]
let context: CIContext
Expand Down Expand Up @@ -107,3 +107,5 @@ class StreamVideoCaptureHandler: NSObject, RTCVideoCapturerDelegate {
)
}
}

extension StreamVideoCaptureHandler: @unchecked Sendable {}
27 changes: 10 additions & 17 deletions Sources/StreamVideoSwiftUI/CallView/CallView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public struct CallView<Factory: ViewFactory>: View {
viewFactory.makeScreenSharingView(
viewModel: viewModel,
screensharingSession: screenSharingSession,
availableSize: videoFeedProxy.size
availableFrame: videoFeedProxy.frame(in: .global)
)
} else {
participantsView(size: videoFeedProxy.size)
participantsView(bounds: videoFeedProxy.frame(in: .global))
}
}

Expand All @@ -53,7 +53,7 @@ public struct CallView<Factory: ViewFactory>: View {
if (viewModel.call?.state.screenSharingSession == nil || viewModel.call?.state.isCurrentUserScreensharing == true),
viewModel.participantsLayout == .grid, viewModel.participants.count <= 3 {
CornerDragableView(
content: contentDragableView(size: reader.size),
content: contentDragableView(bounds: reader.frame(in: .global)),
proxy: reader
) {
withAnimation {
Expand Down Expand Up @@ -90,7 +90,7 @@ public struct CallView<Factory: ViewFactory>: View {
if viewModel.participantsShown {
viewFactory.makeParticipantsListView(
viewModel: viewModel,
availableSize: reader.size
availableFrame: reader.frame(in: .global)
)
.opacity(viewModel.hideUIElements ? 0 : 1)
.accessibility(identifier: "trailingTopView")
Expand All @@ -108,22 +108,22 @@ public struct CallView<Factory: ViewFactory>: View {
}

@ViewBuilder
private func contentDragableView(size: CGSize) -> some View {
private func contentDragableView(bounds: CGRect) -> some View {
if !viewModel.localVideoPrimary {
localVideoView
.cornerRadius(16)
.padding(.horizontal)
} else {
minimizedView(size: size)
minimizedView(bounds: bounds)
}
}

private func minimizedView(size: CGSize) -> some View {
private func minimizedView(bounds: CGRect) -> some View {
Group {
if !viewModel.participants.isEmpty {
VideoCallParticipantView(
participant: viewModel.participants[0],
availableSize: size,
availableFrame: bounds,
contentMode: .scaleAspectFill,
customData: [:],
call: viewModel.call
Expand Down Expand Up @@ -155,22 +155,15 @@ public struct CallView<Factory: ViewFactory>: View {
}
}

private func participantsView(size: CGSize) -> some View {
private func participantsView(bounds: CGRect) -> some View {
viewFactory.makeVideoParticipantsView(
viewModel: viewModel,
availableSize: size,
onViewRendering: handleViewRendering(_:participant:),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to do this without breaking changes to the public API?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remove this one as it's not being used anywhere. We can definitely go ahead without this change but makes our API confusing as we are asking for something what we won't be using.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other things to keep in mind when looking on the screenshots (as you may missed the note below them):

  • The before screenshot shows lower consumption because the app at that point was unresponsive. Nothing was updating on the screen and that was causing consumption to drop.
  • The after screenshot was captured after 55minutes in a call while the before it was on minute 18.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, you should sell it better then 😄

availableFrame: bounds,
onChangeTrackVisibility: viewModel.changeTrackVisibility(for:isVisible:)
)
}

private var participants: [CallParticipant] {
viewModel.participants
}

private func handleViewRendering(_ view: VideoRenderer, participant: CallParticipant) {
view.handleViewRendering(for: participant) { size, participant in
viewModel.updateTrackSize(size, for: participant)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public struct MinimizedCallView: View {
if !viewModel.participants.isEmpty {
VideoCallParticipantView(
participant: viewModel.participants[0],
availableSize: proxy.size,
availableFrame: proxy.frame(in: .global),
contentMode: .scaleAspectFill,
customData: [:],
call: viewModel.call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public struct CallParticipantsInfoView: View {

@StateObject var viewModel: CallParticipantsInfoViewModel
@ObservedObject var callViewModel: CallViewModel
var availableSize: CGSize
public init(callViewModel: CallViewModel, availableSize: CGSize) {
var availableFrame: CGRect

public init(callViewModel: CallViewModel, availableFrame: CGRect) {
self.callViewModel = callViewModel
self.availableSize = availableSize
self.availableFrame = availableFrame
_viewModel = StateObject(
wrappedValue: CallParticipantsInfoViewModel(
call: callViewModel.call
Expand All @@ -30,7 +30,7 @@ public struct CallParticipantsInfoView: View {
CallParticipantsView(
viewModel: viewModel,
callViewModel: callViewModel,
maxHeight: availableSize.height - padding
maxHeight: availableFrame.size.height - padding
)
.padding()
.padding(.vertical, padding / 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ public struct ParticipantsFullScreenLayout<Factory: ViewFactory>: View {
var viewFactory: Factory
var participant: CallParticipant
var call: Call?
var size: CGSize
var frame: CGRect
var onChangeTrackVisibility: @MainActor(CallParticipant, Bool) -> Void

public init(
viewFactory: Factory,
participant: CallParticipant,
call: Call?,
size: CGSize,
frame: CGRect,
onChangeTrackVisibility: @escaping @MainActor (CallParticipant, Bool) -> Void
) {
self.viewFactory = viewFactory
self.participant = participant
self.call = call
self.size = size
self.frame = frame
self.onChangeTrackVisibility = onChangeTrackVisibility
}

public var body: some View {
viewFactory.makeVideoParticipantView(
participant: participant,
id: participant.id,
availableSize: size,
availableFrame: frame,
contentMode: .scaleAspectFit,
customData: [:],
call: call
Expand All @@ -41,7 +41,7 @@ public struct ParticipantsFullScreenLayout<Factory: ViewFactory>: View {
viewFactory.makeVideoCallParticipantModifier(
participant: participant,
call: call,
availableSize: size,
availableFrame: frame,
ratio: ratio,
showAllInfo: true
)
Expand All @@ -57,7 +57,7 @@ public struct ParticipantsFullScreenLayout<Factory: ViewFactory>: View {
}

private var ratio: CGFloat {
size.width / size.height
frame.size.width / frame.size.height
}
}

Expand Down
Loading
Loading