Skip to content

Commit 191140c

Browse files
authored
[Fix]Picture-in-Picture local participant not mirrored (#773)
1 parent 0a0f38f commit 191140c

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

Sources/StreamVideoSwiftUI/Utils/PictureInPicture/PictureInPictureVideoParticipantView.swift

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ struct PictureInPictureVideoParticipantView: View {
2121
var participant: CallParticipant
2222
var track: RTCVideoTrack?
2323

24+
@State private var isUsingFrontCameraForLocalUser: Bool = false
25+
2426
/// Creates a new participant view.
2527
///
2628
/// - Parameters:
@@ -41,11 +43,13 @@ struct PictureInPictureVideoParticipantView: View {
4143
}
4244

4345
var body: some View {
44-
PictureInPictureVideoRendererView(
45-
store: store,
46-
participant: participant,
47-
track: track
48-
)
46+
withCallSettingsObservation {
47+
PictureInPictureVideoRendererView(
48+
store: store,
49+
participant: participant,
50+
track: track
51+
)
52+
}
4953
.opacity(showVideo ? 1 : 0)
5054
.streamAccessibility(value: showVideo ? "1" : "0")
5155
.overlay(overlayView)
@@ -62,4 +66,26 @@ struct PictureInPictureVideoParticipantView: View {
6266
.makeParticipantImageView(participant: participant)
6367
.opacity(showVideo ? 0 : 1)
6468
}
69+
70+
@MainActor
71+
@ViewBuilder
72+
private func withCallSettingsObservation(
73+
@ViewBuilder _ content: () -> some View
74+
) -> some View {
75+
if participant.sessionId == streamVideo.state.activeCall?.state.localParticipant?.sessionId {
76+
Group {
77+
if isUsingFrontCameraForLocalUser {
78+
content()
79+
.rotation3DEffect(.degrees(180), axis: (x: 0, y: 1, z: 0))
80+
} else {
81+
content()
82+
}
83+
}
84+
.onReceive(store.state.call?.state.$callSettings) {
85+
self.isUsingFrontCameraForLocalUser = $0.cameraPosition == .front
86+
}
87+
} else {
88+
content()
89+
}
90+
}
6591
}

0 commit comments

Comments
 (0)