@@ -12,6 +12,7 @@ import AVFoundation
12
12
13
13
fileprivate let videoSize : CGSize = . init( width: 480 , height: 640 )
14
14
fileprivate let defaultNoFitTimeoutInterval : TimeInterval = 7
15
+ fileprivate let defaultAttemptCountResetInterval : TimeInterval = 300.0
15
16
16
17
@MainActor
17
18
class FaceLivenessDetectionViewModel : ObservableObject {
@@ -28,6 +29,7 @@ class FaceLivenessDetectionViewModel: ObservableObject {
28
29
let faceDetector : FaceDetector
29
30
let faceInOvalMatching : FaceInOvalMatching
30
31
let challengeID : String = UUID ( ) . uuidString
32
+ let isPreviewScreenEnabled : Bool
31
33
var colorSequences : [ ColorSequence ] = [ ]
32
34
var hasSentFinalVideoEvent = false
33
35
var hasSentFirstVideo = false
@@ -43,6 +45,9 @@ class FaceLivenessDetectionViewModel: ObservableObject {
43
45
var faceMatchedTimestamp : UInt64 ?
44
46
var noFitStartTime : Date ?
45
47
48
+ static var attemptCount : Int = 0
49
+ static var attemptIdTimeStamp : Date = Date ( )
50
+
46
51
var noFitTimeoutInterval : TimeInterval {
47
52
if let sessionTimeoutMilliSec = sessionConfiguration? . ovalMatchChallenge. oval. ovalFitTimeout {
48
53
return TimeInterval ( sessionTimeoutMilliSec/ 1_000 )
@@ -58,7 +63,8 @@ class FaceLivenessDetectionViewModel: ObservableObject {
58
63
videoChunker: VideoChunker ,
59
64
stateMachine: LivenessStateMachine = . init( state: . initial) ,
60
65
closeButtonAction: @escaping ( ) -> Void ,
61
- sessionID: String
66
+ sessionID: String ,
67
+ isPreviewScreenEnabled: Bool
62
68
) {
63
69
self . closeButtonAction = closeButtonAction
64
70
self . videoChunker = videoChunker
@@ -67,6 +73,7 @@ class FaceLivenessDetectionViewModel: ObservableObject {
67
73
self . captureSession = captureSession
68
74
self . faceDetector = faceDetector
69
75
self . faceInOvalMatching = faceInOvalMatching
76
+ self . isPreviewScreenEnabled = isPreviewScreenEnabled
70
77
71
78
self . closeButtonAction = { [ weak self] in
72
79
guard let self else { return }
@@ -186,13 +193,20 @@ class FaceLivenessDetectionViewModel: ObservableObject {
186
193
187
194
func initializeLivenessStream( ) {
188
195
do {
189
- guard let livenessSession = livenessService as? FaceLivenessSession else {
190
- throw FaceLivenessDetectionError . unknown
196
+ if ( abs ( Self . attemptIdTimeStamp. timeIntervalSinceNow) > defaultAttemptCountResetInterval) {
197
+ Self . attemptCount = 1
198
+ } else {
199
+ Self . attemptCount += 1
191
200
}
201
+ Self . attemptIdTimeStamp = Date ( )
192
202
193
- try livenessSession . initializeLivenessStream (
203
+ try livenessService ? . initializeLivenessStream (
194
204
withSessionID: sessionID,
195
- userAgent: UserAgentValues . standard ( ) . userAgentString
205
+ userAgent: UserAgentValues . standard ( ) . userAgentString,
206
+ challenges: FaceLivenessSession . supportedChallenges,
207
+ options: . init(
208
+ attemptCount: Self . attemptCount,
209
+ preCheckViewEnabled: isPreviewScreenEnabled)
196
210
)
197
211
} catch {
198
212
DispatchQueue . main. async {
0 commit comments