Skip to content

Commit

Permalink
VideoView mirrored mode toggle menu
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroshihorie committed Feb 11, 2022
1 parent c727651 commit cc2f0bb
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
5 changes: 5 additions & 0 deletions Shared/Controllers/AppContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ final class AppContext: ObservableObject {
didSet { store.set(.videoViewMode, value: videoViewMode) }
}

@Published var videoViewMirrored: Bool {
didSet { store.set(.videoViewMirrored, value: videoViewMirrored) }
}

@Published var connectionHistory: Set<ConnectionHistory> {
didSet { store.set(.connectionHistory, value: connectionHistory) }
}
Expand All @@ -33,6 +37,7 @@ final class AppContext: ObservableObject {
self.showInformationOverlay = store.get(.showInformationOverlay) ?? false
self.preferMetal = store.get(.preferMetal) ?? true
self.videoViewMode = store.get(.videoViewMode) ?? .fit
self.videoViewMirrored = store.get(.videoViewMirrored) ?? false
self.connectionHistory = store.get(.connectionHistory) ?? []
}
}
43 changes: 27 additions & 16 deletions Shared/ParticipantView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,36 @@ struct ParticipantView: View {
let track = publication.track as? VideoTrack,
appCtx.videoViewVisible {
ZStack(alignment: .topLeading) {
let mirrored = track is LocalVideoTrack ? !appCtx.videoViewMirrored : appCtx.videoViewMirrored
SwiftUIVideoView(track,
mode: videoViewMode,
mirrored: true, dimensions: $dimensions,
mirrored: mirrored,
dimensions: $dimensions,
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) {
if let dimensions = dimensions {
Text("DIM. \(dimensions.width)x\(dimensions.height)")
Text("Metal: \(String(describing: appCtx.preferMetal))")
.foregroundColor(Color.white)
.padding(3)
.background(Color.black)
.cornerRadius(8)
Text("Mirrored: \(String(describing: mirrored))")
.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)

}
Text("Metal: \(String(describing: appCtx.preferMetal))")
.foregroundColor(Color.white)
.padding(3)
.background(Color.green)
.cornerRadius(8)

}
.padding()
}
Expand All @@ -77,13 +84,17 @@ struct ParticipantView: View {
VStack(alignment: .trailing, spacing: 0) {
// Show the sub-video view
if let subVideoTrack = participant.subVideoTrack {
SwiftUIVideoView(subVideoTrack, mode: .fill,
preferMetal: appCtx.preferMetal)
.background(Color.black)
.aspectRatio(contentMode: .fit)
.frame(width: min(geometry.size.width, geometry.size.height) * 0.3)
.cornerRadius(8)
.padding()
let mirrored = subVideoTrack is LocalVideoTrack ? !appCtx.videoViewMirrored : appCtx.videoViewMirrored
SwiftUIVideoView(subVideoTrack,
mode: .fill,
mirrored: mirrored,
preferMetal: appCtx.preferMetal
)
.background(Color.black)
.aspectRatio(contentMode: .fit)
.frame(width: min(geometry.size.width, geometry.size.height) * 0.3)
.cornerRadius(8)
.padding()
}

// Bottom user info bar
Expand Down
10 changes: 8 additions & 2 deletions Shared/RoomView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,14 @@ struct RoomView: View {

Menu {
Toggle("Show info overlay", isOn: $appCtx.showInformationOverlay)
Toggle("Video view visible", isOn: $appCtx.videoViewVisible)
Toggle("Prefer Metal", isOn: $appCtx.preferMetal)

Divider()

Toggle("VideoView visible", isOn: $appCtx.videoViewVisible)
Toggle("VideoView preferMetal", isOn: $appCtx.preferMetal)
Toggle("VideoView mirrored", isOn: $appCtx.videoViewMirrored)

Divider()

Menu {
Button {
Expand Down
1 change: 1 addition & 0 deletions Shared/Support/SecureStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ enum SecureStoreKeys: String {
case showInformationOverlay = "showInformationOverlay"
case preferMetal = "preferMetal"
case videoViewMode = "videoViewMode"
case videoViewMirrored = "videoViewMirrored"

case connectionHistory = "connectionHistory"
}
Expand Down

0 comments on commit cc2f0bb

Please sign in to comment.