|
| 1 | +// |
| 2 | +// Copyright © 2025 Stream.io Inc. All rights reserved. |
| 3 | +// |
| 4 | + |
| 5 | +import StreamVideo |
| 6 | +import StreamWebRTC |
| 7 | +import SwiftUI |
| 8 | + |
| 9 | +public final class AnyViewFactory: ViewFactory { |
| 10 | + |
| 11 | + private let _makeCallControlsView: (CallViewModel) -> AnyView |
| 12 | + private let _makeOutgoingCallView: (CallViewModel) -> AnyView |
| 13 | + private let _makeJoiningCallView: (CallViewModel) -> AnyView |
| 14 | + private let _makeIncomingCallView: (CallViewModel, IncomingCall) -> AnyView |
| 15 | + private let _makeWaitingLocalUserView: (CallViewModel) -> AnyView |
| 16 | + private let _makeVideoParticipantsView: ( |
| 17 | + CallViewModel, |
| 18 | + CGRect, |
| 19 | + @escaping @MainActor(CallParticipant, Bool) -> Void |
| 20 | + ) -> AnyView |
| 21 | + private let _makeVideoParticipantView: ( |
| 22 | + CallParticipant, |
| 23 | + String, |
| 24 | + CGRect, |
| 25 | + UIView.ContentMode, |
| 26 | + [String: RawJSON], |
| 27 | + Call? |
| 28 | + ) -> AnyView |
| 29 | + private let _makeVideoCallParticipantModifier: ( |
| 30 | + CallParticipant, |
| 31 | + Call?, |
| 32 | + CGRect, |
| 33 | + CGFloat, |
| 34 | + Bool |
| 35 | + ) -> any ViewModifier |
| 36 | + private let _makeCallView: (CallViewModel) -> AnyView |
| 37 | + private let _makeMinimizedCallView: (CallViewModel) -> AnyView |
| 38 | + private let _makeCallTopView: (CallViewModel) -> AnyView |
| 39 | + private let _makeParticipantsListView: (CallViewModel) -> AnyView |
| 40 | + private let _makeScreenSharingView: (CallViewModel, ScreenSharingSession, CGRect) -> AnyView |
| 41 | + private let _makeLobbyView: (CallViewModel, LobbyInfo, Binding<CallSettings>) -> AnyView |
| 42 | + private let _makeReconnectionView: (CallViewModel) -> AnyView |
| 43 | + private let _makeLocalParticipantViewModifier: ( |
| 44 | + CallParticipant, |
| 45 | + Binding<CallSettings>, |
| 46 | + Call? |
| 47 | + ) -> any ViewModifier |
| 48 | + private let _makeUserAvatar: (User, UserAvatarViewOptions) -> AnyView |
| 49 | + |
| 50 | + public init<T: ViewFactory>(_ factory: T) { |
| 51 | + _makeCallControlsView = { AnyView(factory.makeCallControlsView(viewModel: $0)) } |
| 52 | + _makeOutgoingCallView = { AnyView(factory.makeOutgoingCallView(viewModel: $0)) } |
| 53 | + _makeJoiningCallView = { AnyView(factory.makeJoiningCallView(viewModel: $0)) } |
| 54 | + _makeIncomingCallView = { AnyView(factory.makeIncomingCallView(viewModel: $0, callInfo: $1)) } |
| 55 | + _makeWaitingLocalUserView = { AnyView(factory.makeWaitingLocalUserView(viewModel: $0)) } |
| 56 | + _makeVideoParticipantsView = { |
| 57 | + AnyView(factory.makeVideoParticipantsView(viewModel: $0, availableFrame: $1, onChangeTrackVisibility: $2)) |
| 58 | + } |
| 59 | + _makeVideoParticipantView = { |
| 60 | + AnyView( |
| 61 | + factory |
| 62 | + .makeVideoParticipantView( |
| 63 | + participant: $0, |
| 64 | + id: $1, |
| 65 | + availableFrame: $2, |
| 66 | + contentMode: $3, |
| 67 | + customData: $4, |
| 68 | + call: $5 |
| 69 | + ) |
| 70 | + ) |
| 71 | + } |
| 72 | + _makeVideoCallParticipantModifier = { |
| 73 | + factory.makeVideoCallParticipantModifier( |
| 74 | + participant: $0, |
| 75 | + call: $1, |
| 76 | + availableFrame: $2, |
| 77 | + ratio: $3, |
| 78 | + showAllInfo: $4 |
| 79 | + ) |
| 80 | + } |
| 81 | + _makeCallView = { AnyView(factory.makeCallView(viewModel: $0)) } |
| 82 | + _makeMinimizedCallView = { AnyView(factory.makeMinimizedCallView(viewModel: $0)) } |
| 83 | + _makeCallTopView = { AnyView(factory.makeCallTopView(viewModel: $0)) } |
| 84 | + _makeParticipantsListView = { AnyView(factory.makeParticipantsListView(viewModel: $0)) } |
| 85 | + _makeScreenSharingView = { |
| 86 | + AnyView(factory.makeScreenSharingView(viewModel: $0, screensharingSession: $1, availableFrame: $2)) |
| 87 | + } |
| 88 | + _makeLobbyView = { AnyView(factory.makeLobbyView(viewModel: $0, lobbyInfo: $1, callSettings: $2)) } |
| 89 | + _makeReconnectionView = { AnyView(factory.makeReconnectionView(viewModel: $0)) } |
| 90 | + _makeLocalParticipantViewModifier = { |
| 91 | + factory.makeLocalParticipantViewModifier(localParticipant: $0, callSettings: $1, call: $2) |
| 92 | + } |
| 93 | + _makeUserAvatar = { AnyView(factory.makeUserAvatar($0, with: $1)) } |
| 94 | + } |
| 95 | + |
| 96 | + public func makeCallControlsView(viewModel: CallViewModel) -> some View { |
| 97 | + _makeCallControlsView(viewModel) |
| 98 | + } |
| 99 | + |
| 100 | + public func makeOutgoingCallView(viewModel: CallViewModel) -> some View { |
| 101 | + _makeOutgoingCallView(viewModel) |
| 102 | + } |
| 103 | + |
| 104 | + public func makeJoiningCallView(viewModel: CallViewModel) -> some View { |
| 105 | + _makeJoiningCallView(viewModel) |
| 106 | + } |
| 107 | + |
| 108 | + public func makeIncomingCallView(viewModel: CallViewModel, callInfo: IncomingCall) -> some View { |
| 109 | + _makeIncomingCallView(viewModel, callInfo) |
| 110 | + } |
| 111 | + |
| 112 | + public func makeWaitingLocalUserView(viewModel: CallViewModel) -> some View { |
| 113 | + _makeWaitingLocalUserView(viewModel) |
| 114 | + } |
| 115 | + |
| 116 | + public func makeVideoParticipantsView( |
| 117 | + viewModel: CallViewModel, |
| 118 | + availableFrame: CGRect, |
| 119 | + onChangeTrackVisibility: @escaping @MainActor(CallParticipant, Bool) -> Void |
| 120 | + ) -> some View { |
| 121 | + _makeVideoParticipantsView(viewModel, availableFrame, onChangeTrackVisibility) |
| 122 | + } |
| 123 | + |
| 124 | + public func makeVideoParticipantView( |
| 125 | + participant: CallParticipant, |
| 126 | + id: String, |
| 127 | + availableFrame: CGRect, |
| 128 | + contentMode: UIView.ContentMode, |
| 129 | + customData: [String: RawJSON], |
| 130 | + call: Call? |
| 131 | + ) -> some View { |
| 132 | + _makeVideoParticipantView(participant, id, availableFrame, contentMode, customData, call) |
| 133 | + } |
| 134 | + |
| 135 | + public func makeVideoCallParticipantModifier( |
| 136 | + participant: CallParticipant, |
| 137 | + call: Call?, |
| 138 | + availableFrame: CGRect, |
| 139 | + ratio: CGFloat, |
| 140 | + showAllInfo: Bool |
| 141 | + ) -> any ViewModifier { |
| 142 | + _makeVideoCallParticipantModifier(participant, call, availableFrame, ratio, showAllInfo) |
| 143 | + } |
| 144 | + |
| 145 | + public func makeCallView(viewModel: CallViewModel) -> some View { |
| 146 | + _makeCallView(viewModel) |
| 147 | + } |
| 148 | + |
| 149 | + public func makeMinimizedCallView(viewModel: CallViewModel) -> some View { |
| 150 | + _makeMinimizedCallView(viewModel) |
| 151 | + } |
| 152 | + |
| 153 | + public func makeCallTopView(viewModel: CallViewModel) -> some View { |
| 154 | + _makeCallTopView(viewModel) |
| 155 | + } |
| 156 | + |
| 157 | + public func makeParticipantsListView(viewModel: CallViewModel) -> some View { |
| 158 | + _makeParticipantsListView(viewModel) |
| 159 | + } |
| 160 | + |
| 161 | + public func makeScreenSharingView( |
| 162 | + viewModel: CallViewModel, |
| 163 | + screensharingSession: ScreenSharingSession, |
| 164 | + availableFrame: CGRect |
| 165 | + ) -> some View { |
| 166 | + _makeScreenSharingView(viewModel, screensharingSession, availableFrame) |
| 167 | + } |
| 168 | + |
| 169 | + public func makeLobbyView( |
| 170 | + viewModel: CallViewModel, |
| 171 | + lobbyInfo: LobbyInfo, |
| 172 | + callSettings: Binding<CallSettings> |
| 173 | + ) -> some View { |
| 174 | + _makeLobbyView(viewModel, lobbyInfo, callSettings) |
| 175 | + } |
| 176 | + |
| 177 | + public func makeReconnectionView(viewModel: CallViewModel) -> some View { |
| 178 | + _makeReconnectionView(viewModel) |
| 179 | + } |
| 180 | + |
| 181 | + public func makeLocalParticipantViewModifier( |
| 182 | + localParticipant: CallParticipant, |
| 183 | + callSettings: Binding<CallSettings>, |
| 184 | + call: Call? |
| 185 | + ) -> any ViewModifier { |
| 186 | + _makeLocalParticipantViewModifier(localParticipant, callSettings, call) |
| 187 | + } |
| 188 | + |
| 189 | + public func makeUserAvatar( |
| 190 | + _ user: User, |
| 191 | + with options: UserAvatarViewOptions |
| 192 | + ) -> some View { |
| 193 | + _makeUserAvatar(user, options) |
| 194 | + } |
| 195 | +} |
0 commit comments