Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
* main:
  chore: update user agent string with correct library version (#42)
  fix: update no match timeout check from frame count to elapsed time (#41)
  fix: send client close frame (#39)
  fix: data race causing multiple initial events and crash with low net… (#40)
  chore: remove countdown from liveness session check (#36)
  • Loading branch information
phantumcode committed Jul 20, 2023
2 parents 5b47401 + adf29ad commit b05510a
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 238 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ extension LocalizedStringKey {
"amplify_ui_liveness_challenge_recording_indicator_label"
)

/// en = "Hold face position during countdown."
static let challenge_instruction_hold_face_during_countdown = LocalizedStringKey(
"amplify_ui_liveness_challenge_instruction_hold_face_during_countdown"
)

/// en = "Hold face in oval for colored lights."
static let challenge_instruction_hold_face_during_freshness = LocalizedStringKey(
"amplify_ui_liveness_challenge_instruction_hold_face_during_freshness"
Expand Down
2 changes: 1 addition & 1 deletion Sources/FaceLiveness/Utilities/UserAgent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct UserAgentValues {
swiftVersion: Swift().version(),
unameMachine: Device.current.machine.replacingOccurrences(of: ",", with: "_"),
locale: Locale.current.identifier,
lib: "lib/amplify-ui-swift-face-liveness/1.0.1",
lib: "lib/amplify-ui-swift-face-liveness/1.1.0",
additionalMetadata: additionalMetadata
)
}
Expand Down

This file was deleted.

67 changes: 0 additions & 67 deletions Sources/FaceLiveness/Views/Countdown/CountdownView+ViewModel.swift

This file was deleted.

64 changes: 0 additions & 64 deletions Sources/FaceLiveness/Views/Countdown/CountdownView.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,26 @@ struct InstructionContainerView: View {
percentage: 0.2
)
.frame(width: 200, height: 30)
case .pendingFacePreparedConfirmation(let reason):
InstructionView(
text: .init(reason.rawValue),
backgroundColor: .livenessBackground
)
case .completedDisplayingFreshness:
InstructionView(
text: .challenge_verifying,
backgroundColor: .livenessBackground
)
.onAppear {
UIAccessibility.post(
notification: .announcement,
argument: NSLocalizedString(
"amplify_ui_liveness_challenge_verifying",
bundle: .module,
comment: ""
)
)
}
default:
EmptyView()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import SwiftUI
@_spi(PredictionsFaceLiveness) import AWSPredictionsPlugin

fileprivate let initialFaceDistanceThreshold: CGFloat = 0.32
fileprivate let countdownFaceDistanceThreshold: CGFloat = 0.37

extension FaceLivenessDetectionViewModel: FaceDetectionResultHandler {
func process(newResult: FaceDetectionResult) {
Expand All @@ -34,25 +33,20 @@ extension FaceLivenessDetectionViewModel: FaceDetectionResultHandler {
switch livenessState.state {
case .pendingFacePreparedConfirmation:
if face.faceDistance <= initialFaceDistanceThreshold {
DispatchQueue.main.async {
self.livenessState.startCountdown()
self.initializeLivenessStream()
}
DispatchQueue.main.async {
self.livenessState.awaitingRecording()
self.initializeLivenessStream()
}
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
self.livenessState.beginRecording()
}
return
} else {
DispatchQueue.main.async {
self.livenessState.faceNotPrepared(reason: .faceTooClose)
}
return
}
case .countingDown:
if face.faceDistance >= countdownFaceDistanceThreshold {
DispatchQueue.main.async {
self.livenessState.unrecoverableStateEncountered(
.invalidFaceMovementDuringCountdown
)
}
}
case .recording(ovalDisplayed: false):
drawOval(onComplete: {
self.sendInitialFaceDetectedEvent(
Expand Down
34 changes: 6 additions & 28 deletions Sources/FaceLiveness/Views/Liveness/LivenessStateMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ struct LivenessStateMachine {
state = .pendingFacePreparedConfirmation(reason)
}

mutating func openSocket() {
switch state {
case .pendingFacePreparedConfirmation, .countingDown:
state = .socketOpened
default:
break
}
}

mutating func awaitingFaceMatch(with instruction: Instructor.Instruction, nearnessPercentage: Double) {
let reason: FaceNotPreparedReason
let percentage: Double
Expand All @@ -56,16 +47,11 @@ struct LivenessStateMachine {
state = .awaitingFaceInOvalMatch(reason, percentage)
}

mutating func awaitingServerInfoEvent() {
guard case .socketOpened = state else { return }
state = .awaitingServerInfoEvent
}

mutating func receivedServerInfoEvent() throws {
guard case .awaitingServerInfoEvent = state else { return }
state = .serverInfoEventReceived
mutating func awaitingRecording() {
guard case .pendingFacePreparedConfirmation = state else { return }
state = .waitForRecording
}

mutating func unrecoverableStateEncountered(_ error: LivenessError) {
switch state {
case .encounteredUnrecoverableError, .completed:
Expand All @@ -83,11 +69,6 @@ struct LivenessStateMachine {
state = .recording(ovalDisplayed: true)
}

mutating func startCountdown() {
guard case .pendingFacePreparedConfirmation = state else { return }
state = .countingDown
}

mutating func faceMatched() {
state = .faceMatched
}
Expand All @@ -106,7 +87,7 @@ struct LivenessStateMachine {

var shouldDisplayRecordingIcon: Bool {
switch state {
case .initial, .pendingFacePreparedConfirmation, .encounteredUnrecoverableError, .countingDown:
case .initial, .pendingFacePreparedConfirmation, .encounteredUnrecoverableError:
return false
default: return true
}
Expand All @@ -115,10 +96,6 @@ struct LivenessStateMachine {
enum State: Equatable {
case initial
case pendingFacePreparedConfirmation(FaceNotPreparedReason)
case socketOpened
case awaitingServerInfoEvent
case serverInfoEventReceived
case countingDown
case recording(ovalDisplayed: Bool)
case awaitingFaceInOvalMatch(FaceNotPreparedReason, Double)
case faceMatched
Expand All @@ -129,6 +106,7 @@ struct LivenessStateMachine {
case awaitingDisconnectEvent
case disconnectEventReceived
case encounteredUnrecoverableError(LivenessError)
case waitForRecording
}

enum FaceNotPreparedReason: String, Equatable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ struct _FaceLivenessDetectionView<VideoView: View>: View {
)

Spacer()

CountdownInstructionContainerView(
viewModel: viewModel,
onCountdownComplete: {
viewModel.livenessState.beginRecording()
}
)
.padding(.bottom)
}
.padding([.leading, .trailing])
.aspectRatio(3/4, contentMode: .fit)
Expand Down
Loading

0 comments on commit b05510a

Please sign in to comment.