Skip to content

Commit

Permalink
Merge pull request #116 from 100mslive/1.5.0Release
Browse files Browse the repository at this point in the history
1.5.0 Release
  • Loading branch information
gzerad authored Jan 19, 2024
2 parents eadb36f + 9ce923f commit 32a22f6
Show file tree
Hide file tree
Showing 12 changed files with 455 additions and 60 deletions.
120 changes: 70 additions & 50 deletions Example/HMSSDKExample.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions Example/HMSSDKExample/Meeting/BrightnessStripView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// BrightnessStripView.swift
// Procreate
//
// Created by Pawan Dixit on 24/09/2022.
//

import SwiftUI

struct BrightnessStripView: View {

@Binding var controlValue: CGFloat
let width: CGFloat
@Binding var drawRefresh: Bool
let onFinish: ((CGFloat)->Void)?

var body: some View {

let controlColor = Color(UIColor.init(hue: 0.0, saturation: 0.0, brightness: controlValue, alpha: 1.0))

PickerControlView(controlValue: $controlValue, drawRefresh: $drawRefresh, onFinish: onFinish, stripWidth: width, stripColors: extremeEndColors, circleColor: controlColor)
}

private var extremeEndColors: [Color] {
[Color(UIColor.init(hue: 0.0, saturation: 0.0, brightness: 0, alpha: 1.0)),
Color(UIColor.init(hue: 0.0, saturation: 0.0, brightness: 1, alpha: 1.0))]
}
}

struct BrightnessStripView_Previews: PreviewProvider {
static var previews: some View {
BrightnessStripView(controlValue: .constant(1), width: 600, drawRefresh: .constant(true), onFinish: nil)
}
}
125 changes: 125 additions & 0 deletions Example/HMSSDKExample/Meeting/ColorControlsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
//
// ColorControlsView.swift
// HMSSDKExample
//
// Created by Pawan Dixit on 1/9/24.
// Copyright © 2024 100ms. All rights reserved.
//

import SwiftUI
import HMSSDK

struct ColorControlsView: View {

let videoFilterPlugin: HMSVideoFilterPlugin

@Environment(\.presentationMode) var presentationMode

@State var drawRefresh = false

var body: some View {
ZStack {
VisualEffectView(effect: UIBlurEffect(style: .systemUltraThinMaterialDark))
.edgesIgnoringSafeArea(.all)
.opacity(0.01)

VStack(alignment: .center) {

Button {
videoFilterPlugin.brightness = HMSVideoFilterPlugin.defaultBrightness
videoFilterPlugin.saturation = HMSVideoFilterPlugin.defaultSaturation
videoFilterPlugin.hue = HMSVideoFilterPlugin.defaultHue
videoFilterPlugin.sharpness = HMSVideoFilterPlugin.defaultSharpness
videoFilterPlugin.redness = HMSVideoFilterPlugin.defaultRedness
videoFilterPlugin.smoothness = HMSVideoFilterPlugin.defaultSmoothness

drawRefresh.toggle()
} label: {
Text("Reset")
}

VStack(spacing: 5) {
HueStripView(controlValue: Binding(get: {
videoFilterPlugin.hue
}, set: {
videoFilterPlugin.hue = $0
}), width: 300, drawRefresh: $drawRefresh, onFinish: {_ in
})
Text("Hue")

}

VStack(spacing: 5) {
SaturationStripView(controlValue: Binding(get: {
videoFilterPlugin.saturation
}, set: {
videoFilterPlugin.saturation = $0
}), width: 300, drawRefresh: $drawRefresh, onFinish: {_ in
})
Text("Saturation")

}

VStack(spacing: 5) {
BrightnessStripView(controlValue: Binding(get: {
videoFilterPlugin.brightness
}, set: {
videoFilterPlugin.brightness = $0
}), width: 300, drawRefresh: $drawRefresh, onFinish: {_ in
})
Text("Brightness")

}

VStack(spacing: 5) {
BrightnessStripView(controlValue: Binding(get: {
videoFilterPlugin.sharpness
}, set: {
videoFilterPlugin.sharpness = $0 * 1
}), width: 300, drawRefresh: $drawRefresh, onFinish: {_ in
})
Text("Sharpness")

}

VStack(spacing: 5) {
BrightnessStripView(controlValue: Binding(get: {
videoFilterPlugin.redness - 1
}, set: {
videoFilterPlugin.redness = 1 + $0
}), width: 300, drawRefresh: $drawRefresh, onFinish: {_ in
})
Text("Redness")

}

VStack(spacing: 5) {
BrightnessStripView(controlValue: Binding(get: {
videoFilterPlugin.smoothness
}, set: {
videoFilterPlugin.smoothness = $0 * 1
}), width: 300, drawRefresh: $drawRefresh, onFinish: {_ in
})
Text("Smoothness")

}

VStack(spacing: 5) {
BrightnessStripView(controlValue: Binding(get: {
videoFilterPlugin.exposure
}, set: {
videoFilterPlugin.exposure = $0
}), width: 300, drawRefresh: $drawRefresh, onFinish: {_ in
})
Text("Exposure")

}
}
.foregroundColor(.white)
.padding()
}
.onTapGesture {
presentationMode.wrappedValue.dismiss()
}
}
}
8 changes: 8 additions & 0 deletions Example/HMSSDKExample/Meeting/HMSSDKInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ final class HMSSDKInteractor: HMSUpdateListener {
private var videoPlugins = [HMSVideoPlugin]()
var virtualBackgroundPlugin: HMSVideoPlugin?
var frameCapturePlugin: HMSFrameCapturePlugin?

var videoFilterPlugin: HMSVideoFilterPlugin?

// MARK: - Setup SDK

Expand Down Expand Up @@ -138,6 +140,12 @@ final class HMSSDKInteractor: HMSUpdateListener {

virtualBackgroundPlugin = HMSVirtualBackgroundPlugin(backgroundImage: UIImage(named: "VB1"))

videoFilterPlugin = HMSVideoFilterPlugin()
videoFilterPlugin?.activate()
if let videoFilterPlugin {
videoPlugins.append(videoFilterPlugin)
}

if UserDefaults.standard.bool(forKey: "virtualBackgroundPluginEnabled") == true {
virtualBackgroundPlugin?.activate()
}
Expand Down
39 changes: 39 additions & 0 deletions Example/HMSSDKExample/Meeting/HueStripView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// HueStripView.swift
// Procreate
//
// Created by Pawan Dixit on 24/09/2022.
//

import SwiftUI

struct HueStripView: View {

@Binding var controlValue: CGFloat
let width: CGFloat
@Binding var drawRefresh: Bool
let onFinish: ((CGFloat)->Void)?

private let gradientColors: [Color] = {
let hueValues = Array(0...359).reversed()
return hueValues.map {
Color(UIColor(hue: CGFloat($0) / 359.0 ,
saturation: 1.0,
brightness: 1.0,
alpha: 1.0))
}
}()

var body: some View {

let controlColor = Color(UIColor.init(hue: 1.0 - controlValue, saturation: 1.0, brightness: 1.0, alpha: 1.0))

PickerControlView(controlValue: $controlValue, drawRefresh: $drawRefresh, onFinish: onFinish, stripWidth: width, stripColors: gradientColors, circleColor: controlColor)
}
}

struct HueStripView_Previews: PreviewProvider {
static var previews: some View {
HueStripView(controlValue: .constant(1), width: 600, drawRefresh: .constant(true), onFinish: nil)
}
}
14 changes: 14 additions & 0 deletions Example/HMSSDKExample/Meeting/MeetingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,20 @@ final class MeetingViewController: UIViewController, UIDocumentPickerDelegate {
])

}

if let videoFilterPlugin = interactor.videoFilterPlugin {
actions.append(contentsOf: [UIAction(title: "Color Controls",
image: UIImage(systemName: "rainbow")) { [weak self] _ in

let controller = UIHostingController(rootView: ColorControlsView(videoFilterPlugin: videoFilterPlugin))
controller.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
controller.modalTransitionStyle = .crossDissolve
controller.view.backgroundColor = .clear
self?.present(controller, animated: true, completion: nil)

self?.updateSettingsButton()
}])
}

return actions
}
Expand Down
121 changes: 121 additions & 0 deletions Example/HMSSDKExample/Meeting/PickerControlView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
//
// ColorPickerView.swift
// Procreate
//
// Created by Pawan Dixit on 23/09/2022.
//

import SwiftUI

struct PickerControlView: View {

let precisionFactor = 50.0

// Params
@Binding var controlValue: CGFloat
@Binding var drawRefresh: Bool
let onFinish: ((CGFloat)->Void)?

let stripWidth: CGFloat
let stripColors: [Color]
let circleColor: Color

// Gesture
@State private var isDragging: Bool = false
@State private var dragControlLocation: CGFloat = .zero
@State private var dragOffset: CGSize = .zero

// Gesture effects
private var circleWidth: CGFloat {
isDragging ? 35 : 15
}

// Normalize gesture between 0 and stripWidth
private func normalizedGestureLocation() -> CGFloat {
var gestureLocation = dragControlLocation + dragOffset.width

// Normalize with respect to strip width
gestureLocation = max(0, gestureLocation)
gestureLocation = min(gestureLocation, stripWidth)

return gestureLocation
}

// Current control value based on current translation within the view
private var currentControlValue: CGFloat {
self.normalizedGestureLocation() / stripWidth
}

@State var lastTranslation = CGSize.zero

var body: some View {

let dragGesture = DragGesture()
.onChanged({ (value) in

let translation = CGSize(width: value.translation.width - lastTranslation.width, height: value.translation.height - lastTranslation.height)

lastTranslation = value.translation

// Use drag in y axis as precision factor for x axis movement
let yDrag = max(1, abs(value.translation.height)/precisionFactor)
dragOffset = CGSize(width: translation.width/yDrag, height: value.translation.height)

controlValue = currentControlValue

self.dragControlLocation += self.dragOffset.width
self.dragControlLocation = max(0, self.dragControlLocation)
self.dragControlLocation = min(self.dragControlLocation, stripWidth)

self.dragOffset = .zero

withAnimation {
self.isDragging = true
}
})
.onEnded({ (value) in

lastTranslation = .zero

onFinish?(self.controlValue)

withAnimation {

self.isDragging = false
}
})

ZStack(alignment: .leading) {
LinearGradient(gradient: Gradient(colors: stripColors),
startPoint: .leading,
endPoint: .trailing)
.frame(width: stripWidth, height: 4)
.cornerRadius(5)
.shadow(radius: 8)

Circle()
.foregroundColor(self.circleColor)
.frame(width: self.circleWidth, height: self.circleWidth, alignment: .center)
.shadow(radius: 5)
.offset(x: self.normalizedGestureLocation() - self.circleWidth / 2, y: 0.0)


}
.frame(width: stripWidth, height: 50)
.padding(.horizontal)
.contentShape(Rectangle())
.gesture(dragGesture)
.onAppear() {
dragControlLocation = controlValue * stripWidth
}
.onChange(of: drawRefresh) { newValue in
dragControlLocation = controlValue * stripWidth
}
}
}

struct PickerControlView_Previews: PreviewProvider {
static var previews: some View {
PickerControlView(controlValue: .constant(0.5), drawRefresh: .constant(false), onFinish: nil, stripWidth: 600, stripColors: [.white, .red], circleColor: .red)
}
}
Loading

0 comments on commit 32a22f6

Please sign in to comment.