@smileid/usesmileid_vision_face 12.2.0 → 12.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -1
- package/ios/UseSmileIDVisionFaceModule/ResizingFrameStorage.swift +4 -2
- package/ios/UseSmileIDVisionFaceModule/UseSmileIDVisionFaceKameraAnalysisTick.swift +5 -38
- package/ios/UseSmileIDVisionFaceModule/UseSmileIDVisionFaceModule.swift +17 -8
- package/ios/UseSmileIDVisionFaceModule/UseSmileIDVisionFaceSessionHolder.swift +23 -2
- package/package.json +6 -6
- package/plugin/build/index.js +1 -1
- package/ios/UseSmileIDVisionFaceModule/UseSmileIDAnalyzerExecutor.swift +0 -119
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
Full release notes: [Smile ID docs](https://docs.usesmileid.com/developer-resources/sdks/mobile/release-notes/react-native-expo).
|
|
2
2
|
|
|
3
|
+
## 12.3.0
|
|
4
|
+
|
|
5
|
+
See the repository CHANGELOG for the 12.3.0 release notes.
|
|
6
|
+
|
|
7
|
+
|
|
3
8
|
## 12.2.0
|
|
4
9
|
|
|
5
10
|
See the repository CHANGELOG for the 12.2.0 release notes.
|
|
6
11
|
|
|
7
|
-
|
|
8
12
|
## 12.1.1
|
|
9
13
|
|
|
10
14
|
See the repository CHANGELOG for the 12.1.1 release notes.
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// MIRRORED FILE — duplicated in both RN Expo iOS vision modules
|
|
2
|
-
// (usesmileid_vision_face / usesmileid_vision_document)
|
|
3
|
-
// targets can't share sources
|
|
2
|
+
// (usesmileid_vision_face / usesmileid_vision_document). The per-module pod
|
|
3
|
+
// targets can't share sources, and the bridge pod that both depend on doesn't
|
|
4
|
+
// link the native UseSmileIDBridge package this conforms to. Apply any edit to
|
|
5
|
+
// BOTH copies in the same commit.
|
|
4
6
|
|
|
5
7
|
import Foundation
|
|
6
8
|
import UIKit
|
|
@@ -1,49 +1,16 @@
|
|
|
1
|
-
import CoreMedia
|
|
2
1
|
import Kamera
|
|
3
|
-
import CoreImage
|
|
4
2
|
import UIKit
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
private extension CGImagePropertyOrientation {
|
|
8
|
-
/// Kamera rotation + mirror metadata → the preview's selfie-mirrored view. The mirror
|
|
9
|
-
/// applies after the rotation, so the quarter-turn cases swap (`.right` ↔ `.leftMirrored`).
|
|
10
|
-
init(rotationDegrees: Int, isMirrored: Bool) {
|
|
11
|
-
let normalised = ((rotationDegrees % 360) + 360) % 360
|
|
12
|
-
switch (normalised, isMirrored) {
|
|
13
|
-
case (90, false): self = .right
|
|
14
|
-
case (90, true): self = .leftMirrored
|
|
15
|
-
case (180, false): self = .down
|
|
16
|
-
case (180, true): self = .downMirrored
|
|
17
|
-
case (270, false): self = .left
|
|
18
|
-
case (270, true): self = .rightMirrored
|
|
19
|
-
case (_, true): self = .upMirrored
|
|
20
|
-
default: self = .up
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
4
|
/// Scans the latest `KameraFrameHub` frame; no pending frame returns the `no_frame` wire error.
|
|
26
5
|
enum UseSmileIDVisionFaceKameraTick {
|
|
27
|
-
/// Reused across ticks — per-tick creation recompiles the GPU pipeline.
|
|
28
|
-
private static let ciContext = CIContext(options: [.useSoftwareRenderer: false])
|
|
29
|
-
|
|
30
6
|
static func analyze(arguments: [String: Any?]?) -> Any {
|
|
31
7
|
guard let frame = KameraFrameHub.take() else {
|
|
32
8
|
return ["error": "no_frame"]
|
|
33
9
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
let orientedImage = CIImage(cvPixelBuffer: concrete.pixelBuffer)
|
|
40
|
-
.oriented(CGImagePropertyOrientation(
|
|
41
|
-
rotationDegrees: frame.rotationDegrees,
|
|
42
|
-
isMirrored: frame.isMirrored
|
|
43
|
-
))
|
|
44
|
-
let cgImage = ciContext.createCGImage(orientedImage, from: orientedImage.extent)
|
|
45
|
-
frame.close()
|
|
46
|
-
guard let cgImage else {
|
|
10
|
+
// The session reads the live frame's readings as the scan runs; closing it afterwards releases
|
|
11
|
+
// it to the pipeline for the next one.
|
|
12
|
+
defer { frame.close() }
|
|
13
|
+
guard frame is CVPixelBufferKameraFrame else {
|
|
47
14
|
return ["error": "frame_conversion_failed"]
|
|
48
15
|
}
|
|
49
16
|
|
|
@@ -51,7 +18,7 @@ enum UseSmileIDVisionFaceKameraTick {
|
|
|
51
18
|
let rotation = (arguments?["rotation"] as? NSNumber)?.intValue ?? 0
|
|
52
19
|
|
|
53
20
|
guard let result = UseSmileIDVisionFaceSessionHolder.shared.scanAndDrain(
|
|
54
|
-
|
|
21
|
+
frame: frame,
|
|
55
22
|
rotation: rotation
|
|
56
23
|
) else {
|
|
57
24
|
return ["error": "session_not_configured"]
|
|
@@ -129,12 +129,11 @@ private extension Dictionary where Key == String, Value == Any? {
|
|
|
129
129
|
func toFaceScanConfig() -> FaceScanConfig {
|
|
130
130
|
let base = FaceDetectorMode.from(token: self["faceDetectorMode"] as? String).config
|
|
131
131
|
return FaceScanConfig(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
stayInFoundDuration: (self["stayInFoundDuration"] as? NSNumber)?.intValue ?? 3_000,
|
|
132
|
+
numSamples: (self["numSamples"] as? NSNumber)?.intValue ?? ThresholdConfig.FaceCapture.numSamples,
|
|
133
|
+
sampleInterval: (self["sampleInterval"] as? NSNumber)?.intValue
|
|
134
|
+
?? ThresholdConfig.FaceCapture.sampleIntervalMs,
|
|
135
|
+
stayInFoundDuration: (self["stayInFoundDuration"] as? NSNumber)?.intValue
|
|
136
|
+
?? ThresholdConfig.FaceCapture.defaultStayInFoundDuration,
|
|
138
137
|
faceDetectorConfig: FaceDetectorConfig(
|
|
139
138
|
minFillThreshold: (self["minFillThreshold"] as? NSNumber)?.floatValue ?? base.minFillThreshold,
|
|
140
139
|
maxFillThreshold: (self["maxFillThreshold"] as? NSNumber)?.floatValue ?? base.maxFillThreshold,
|
|
@@ -262,12 +261,22 @@ extension UseSmileIDBridge.UseSmileIDScanState {
|
|
|
262
261
|
if let captureProgress {
|
|
263
262
|
map["captureProgress"] = Double(captureProgress)
|
|
264
263
|
}
|
|
265
|
-
// Latched pose-match flag for the ESS head turn —
|
|
266
|
-
//
|
|
264
|
+
// Latched pose-match flag for the ESS head turn — keeps the direction arrow
|
|
265
|
+
// green through a hold at the threshold. Emit only while matched (omit ⇒ false on the JS side),
|
|
267
266
|
// matching the optional-field omission convention above.
|
|
268
267
|
if poseMatched {
|
|
269
268
|
map["poseMatched"] = true
|
|
270
269
|
}
|
|
270
|
+
switch captureStep {
|
|
271
|
+
case .holdStill: map["captureStep"] = "holdStill"
|
|
272
|
+
case .smile: map["captureStep"] = "smile"
|
|
273
|
+
// None yet, and a step a newer bridge adds crosses as none.
|
|
274
|
+
case nil: break
|
|
275
|
+
@unknown default: break
|
|
276
|
+
}
|
|
277
|
+
if let turnProgress {
|
|
278
|
+
map["turnProgress"] = Double(turnProgress)
|
|
279
|
+
}
|
|
271
280
|
return map
|
|
272
281
|
}
|
|
273
282
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Foundation
|
|
2
|
+
import Kamera
|
|
2
3
|
import UIKit
|
|
3
4
|
import UseSmileIDBridge
|
|
4
5
|
import UseSmileIDVisionFace
|
|
@@ -66,7 +67,11 @@ final class UseSmileIDVisionFaceSessionHolder {
|
|
|
66
67
|
|
|
67
68
|
/// Run `session.scan` + `drainCaptureReadyEvents` as one atomic unit, blocking the
|
|
68
69
|
/// caller. Returns `nil` when no session is configured; never throws.
|
|
69
|
-
|
|
70
|
+
///
|
|
71
|
+
/// The session analyses the kamera `frame`'s pixel buffer as the native capture screens do, with
|
|
72
|
+
/// the readings kamera took on it (device motion, tracked face, live-frame quality), and draws an
|
|
73
|
+
/// image only for a frame a capture keeps. The caller keeps `frame` open until this returns.
|
|
74
|
+
func scanAndDrain(frame: any KameraFrame, rotation: Int) -> [String: Any]? {
|
|
70
75
|
var result: [String: Any]?
|
|
71
76
|
operationQueue.sync {
|
|
72
77
|
guard let currentSession = session else {
|
|
@@ -74,8 +79,14 @@ final class UseSmileIDVisionFaceSessionHolder {
|
|
|
74
79
|
}
|
|
75
80
|
let resultBox = ScanResultBox()
|
|
76
81
|
let semaphore = DispatchSemaphore(value: 0)
|
|
82
|
+
let frameBox = KameraFrameBox(frame)
|
|
77
83
|
Task.detached(priority: .userInitiated) {
|
|
78
|
-
let scanResult = await currentSession.scan(
|
|
84
|
+
guard let scanResult = await currentSession.scan(kameraFrame: frameBox.frame, rotation: rotation) else {
|
|
85
|
+
// A frame with no pixel buffer; the tick only hands over pixel-buffer frames.
|
|
86
|
+
resultBox.value = ["error": "frame_conversion_failed"]
|
|
87
|
+
semaphore.signal()
|
|
88
|
+
return
|
|
89
|
+
}
|
|
79
90
|
let nativeOutput = scanResult.output as? UseSmileIDBridge.FaceDetectorOutput
|
|
80
91
|
let state = scanResult.state
|
|
81
92
|
let events = currentSession.drainCaptureReadyEvents()
|
|
@@ -93,6 +104,16 @@ final class UseSmileIDVisionFaceSessionHolder {
|
|
|
93
104
|
}
|
|
94
105
|
}
|
|
95
106
|
|
|
107
|
+
/// Carries the kamera frame into the scan Task. Kamera frames guard their planes with their own
|
|
108
|
+
/// lock, and the caller blocks on the Task while it reads the frame.
|
|
109
|
+
private final class KameraFrameBox: @unchecked Sendable {
|
|
110
|
+
let frame: any KameraFrame
|
|
111
|
+
|
|
112
|
+
init(_ frame: any KameraFrame) {
|
|
113
|
+
self.frame = frame
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
96
117
|
/// Shuttles a scan result from the cooperative-pool Task to the semaphore-blocked caller.
|
|
97
118
|
private final class ScanResultBox: @unchecked Sendable {
|
|
98
119
|
var value: [String: Any] = [:]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smileid/usesmileid_vision_face",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.3.0",
|
|
4
4
|
"description": "Apple Vision face detection implementation for the UseSmileID React Native (Expo) SDK.",
|
|
5
5
|
"homepage": "https://usesmileid.com",
|
|
6
6
|
"repository": {
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"CHANGELOG.md"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@smileid/usesmileid_bridge": "12.
|
|
50
|
-
"@smileid/usesmileid_platform_interface": "12.
|
|
49
|
+
"@smileid/usesmileid_bridge": "12.3.0",
|
|
50
|
+
"@smileid/usesmileid_platform_interface": "12.3.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"expo": ">=56.0.0",
|
|
@@ -55,9 +55,9 @@
|
|
|
55
55
|
"react-native": ">=0.83.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@types/node": "^26.6.
|
|
59
|
-
"expo": "~57.0.
|
|
60
|
-
"expo-modules-core": "^57.0.
|
|
58
|
+
"@types/node": "^26.6.4",
|
|
59
|
+
"expo": "~57.0.26",
|
|
60
|
+
"expo-modules-core": "^57.0.21",
|
|
61
61
|
"react-native": "^0.86.3",
|
|
62
62
|
"typescript": "^6.0.3",
|
|
63
63
|
"xcode": "^3.0.1"
|
package/plugin/build/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?(function(i,r,t,e){e===void 0&&(e=t);var o=Object.getOwnPropertyDescriptor(r,t);(!o||("get"in o?!r.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(i,e,o)}):(function(i,r,t,e){e===void 0&&(e=t),i[e]=r[t]})),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?(function(i,r){Object.defineProperty(i,"default",{enumerable:!0,value:r})}):function(i,r){i.default=r}),__importStar=this&&this.__importStar||(function(){var i=function(r){return i=Object.getOwnPropertyNames||function(t){var e=[];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[e.length]=o);return e},i(r)};return function(r){if(r&&r.__esModule)return r;var t={};if(r!=null)for(var e=i(r),o=0;o<e.length;o++)e[o]!=="default"&&__createBinding(t,r,e[o]);return __setModuleDefault(t,r),t}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.SPM_PRODUCTS=void 0;const config_plugins_1=require("expo/config-plugins"),fs=__importStar(require("fs")),path=__importStar(require("path")),deployment_target_1=require("./lib/deployment_target"),podfile_1=require("./lib/podfile"),signature_dedup_1=require("./lib/signature_dedup"),spm_1=require("./lib/spm"),IOS_DEPLOYMENT_TARGET="16.4",SMILE_ID_PACKAGE={url:"https://github.com/smileidentity/ios-spm",requirement:{kind:"exactVersion",version:"12.
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?(function(i,r,t,e){e===void 0&&(e=t);var o=Object.getOwnPropertyDescriptor(r,t);(!o||("get"in o?!r.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(i,e,o)}):(function(i,r,t,e){e===void 0&&(e=t),i[e]=r[t]})),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?(function(i,r){Object.defineProperty(i,"default",{enumerable:!0,value:r})}):function(i,r){i.default=r}),__importStar=this&&this.__importStar||(function(){var i=function(r){return i=Object.getOwnPropertyNames||function(t){var e=[];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[e.length]=o);return e},i(r)};return function(r){if(r&&r.__esModule)return r;var t={};if(r!=null)for(var e=i(r),o=0;o<e.length;o++)e[o]!=="default"&&__createBinding(t,r,e[o]);return __setModuleDefault(t,r),t}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.SPM_PRODUCTS=void 0;const config_plugins_1=require("expo/config-plugins"),fs=__importStar(require("fs")),path=__importStar(require("path")),deployment_target_1=require("./lib/deployment_target"),podfile_1=require("./lib/podfile"),signature_dedup_1=require("./lib/signature_dedup"),spm_1=require("./lib/spm"),IOS_DEPLOYMENT_TARGET="16.4",SMILE_ID_PACKAGE={url:"https://github.com/smileidentity/ios-spm",requirement:{kind:"exactVersion",version:"12.3.0"}},POD_TARGET="UseSmileIDVisionFaceExpo";exports.SPM_PRODUCTS=["UseSmileIDVisionFace"];const PODFILE_MARKER="usesmileid_vision_face",BRIDGE_POD_TARGET="UseSmileIDBridgeExpo",BRIDGE_SPM_PRODUCTS=["UseSmileIDBridge"],BRIDGE_PODFILE_MARKER="usesmileid_bridge",withVisionFaceSpm=(i,r)=>(i=(0,deployment_target_1.withIosDeploymentTargetFloor)(i,IOS_DEPLOYMENT_TARGET),i=(0,config_plugins_1.withXcodeProject)(i,t=>{const e=t.modRequest.projectName;if(!e)throw new Error("[usesmileid_vision_face] Unable to resolve host app native target name from Expo config.");return(0,spm_1.linkSpmPackage)(t.modResults,SMILE_ID_PACKAGE,{targetName:e,products:[...exports.SPM_PRODUCTS]}),r?.iosSignatureAggregation==="disabled"?(0,signature_dedup_1.disableSignatureAggregation)(t.modResults,e):(0,signature_dedup_1.ensureSignatureDedupPhase)(t.modResults,e),t}),i=(0,config_plugins_1.withDangerousMod)(i,["ios",t=>{const e=path.join(t.modRequest.platformProjectRoot,"Podfile"),o=fs.readFileSync(e,"utf-8");let n=(0,podfile_1.injectPodfileSpmBlock)(o,{marker:PODFILE_MARKER,package:SMILE_ID_PACKAGE,podTarget:POD_TARGET,products:[...exports.SPM_PRODUCTS]});return n=(0,podfile_1.injectPodfileSpmBlock)(n,{marker:BRIDGE_PODFILE_MARKER,package:SMILE_ID_PACKAGE,podTarget:BRIDGE_POD_TARGET,products:[...BRIDGE_SPM_PRODUCTS],required:!0}),n=(0,podfile_1.injectPodfileKameraLinkBlock)(n),n=(0,podfile_1.injectPodfileSignatureDedupBlock)(n),n!==o&&fs.writeFileSync(e,n),t}]),i);exports.default=withVisionFaceSpm;
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
// MIRRORED FILE — this file is duplicated byte-identical across the two
|
|
2
|
-
// RN Expo iOS bridge modules. Canonical location:
|
|
3
|
-
// usesmileid_vision_face/ios/UseSmileIDVisionFaceModule/
|
|
4
|
-
// UseSmileIDAnalyzerExecutor.swift
|
|
5
|
-
// Mirror location:
|
|
6
|
-
// usesmileid_vision_document/ios/UseSmileIDVisionDocumentModule/
|
|
7
|
-
// UseSmileIDAnalyzerExecutor.swift
|
|
8
|
-
//
|
|
9
|
-
// Each RN module is its own CocoaPods bridge target with its own
|
|
10
|
-
// `source_files` glob; source cannot be shared across them without
|
|
11
|
-
// inventing a new pod. The helper is duplicated verbatim into both
|
|
12
|
-
// vision modules. Any edit here MUST be copied to the other location in
|
|
13
|
-
// the same commit.
|
|
14
|
-
//
|
|
15
|
-
// Purpose: collapse the analyze / flush plumbing of the two RN Expo
|
|
16
|
-
// vision modules into a single generic executor whose Task closures
|
|
17
|
-
// capture only @Sendable values (closures + locals) — no module-class
|
|
18
|
-
// state, no implicit `self`. This forces both modules to share one set
|
|
19
|
-
// of Sendable correctness properties by construction: if one compiles
|
|
20
|
-
// cleanly under strict concurrency, the other must too.
|
|
21
|
-
//
|
|
22
|
-
// RN-specific differences from the Flutter twin:
|
|
23
|
-
// • RN modules receive pre-decoded JPEG/PNG bytes (`UIImage(data:)`),
|
|
24
|
-
// so the executor accepts `UIImage` directly rather than Pigeon's
|
|
25
|
-
// `YuvImage` and an associated decoder. JPEG decoding happens in
|
|
26
|
-
// the per-module wrapper before the executor is invoked.
|
|
27
|
-
// • The completion signature is `(Result<PigeonResult, Error>) -> Void`
|
|
28
|
-
// identical to Flutter — the per-module wrapper translates that
|
|
29
|
-
// into Expo's `Promise.resolve`/`reject`. Keeping the executor's
|
|
30
|
-
// public surface a `Result` consumer means both bridges share the
|
|
31
|
-
// same Task discipline.
|
|
32
|
-
|
|
33
|
-
import ExpoModulesCore
|
|
34
|
-
import UIKit
|
|
35
|
-
import UseSmileIDBridge
|
|
36
|
-
|
|
37
|
-
/// Bridges an Expo Modules @escaping completion handler into Swift 6
|
|
38
|
-
/// Task captures. Expo's `Promise` is itself reference-typed but not
|
|
39
|
-
/// `Sendable`; the executor never captures a `Promise` — it captures a
|
|
40
|
-
/// `Result` consumer closure that the per-module wrapper translates
|
|
41
|
-
/// into `resolve`/`reject`. This box mirrors the Flutter PigeonCompletion
|
|
42
|
-
/// pattern.
|
|
43
|
-
final class ExecutorCompletion<T>: @unchecked Sendable {
|
|
44
|
-
let call: (T) -> Void
|
|
45
|
-
init(_ fn: @escaping (T) -> Void) { self.call = fn }
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/// Generic helper that owns the analyze / flush bridging between the
|
|
49
|
-
/// RN Expo Module's completion-based API and the native session's async
|
|
50
|
-
/// API.
|
|
51
|
-
///
|
|
52
|
-
/// The class itself is `@unchecked Sendable` because it stores only
|
|
53
|
-
/// `@Sendable` closures (which are themselves Sendable). The downstream
|
|
54
|
-
/// `Task.detached` bodies capture those closures — never an instance of a
|
|
55
|
-
/// concrete module class — so the compiler can prove the Task body is
|
|
56
|
-
/// Sendable-by-construction.
|
|
57
|
-
///
|
|
58
|
-
/// `NativeOutput` is the concrete native analyzer output type (e.g.
|
|
59
|
-
/// `FaceDetectorOutput`, `DocumentDetectorOutput`); `Wire` is the
|
|
60
|
-
/// JS-side wire dictionary the module returns to JS (typed as
|
|
61
|
-
/// `[String: Any?]` after Expo bridge marshalling).
|
|
62
|
-
final class UseSmileIDAnalyzerExecutor<NativeOutput: AnalyzerOutput, Wire>: @unchecked Sendable {
|
|
63
|
-
|
|
64
|
-
private let scan: @Sendable (UIImage, Int) async -> (NativeOutput?, UseSmileIDScanState)
|
|
65
|
-
private let drainEvents: @Sendable () -> [UseSmileIDBridge.CaptureReadyEvent]
|
|
66
|
-
private let flushFn: @Sendable () async throws -> Void
|
|
67
|
-
private let buildResult: @Sendable (NativeOutput?, UseSmileIDScanState, [UseSmileIDBridge.CaptureReadyEvent]) -> Wire
|
|
68
|
-
|
|
69
|
-
init(
|
|
70
|
-
scan: @escaping @Sendable (UIImage, Int) async -> (NativeOutput?, UseSmileIDScanState),
|
|
71
|
-
drainEvents: @escaping @Sendable () -> [UseSmileIDBridge.CaptureReadyEvent],
|
|
72
|
-
flush: @escaping @Sendable () async throws -> Void,
|
|
73
|
-
buildResult: @escaping @Sendable (NativeOutput?, UseSmileIDScanState, [UseSmileIDBridge.CaptureReadyEvent]) -> Wire
|
|
74
|
-
) {
|
|
75
|
-
self.scan = scan
|
|
76
|
-
self.drainEvents = drainEvents
|
|
77
|
-
self.flushFn = flush
|
|
78
|
-
self.buildResult = buildResult
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/// Hands the already-decoded `UIImage` to the captured `scan` closure
|
|
82
|
-
/// on a detached task. The Task's capture list explicitly lists every
|
|
83
|
-
/// value it consumes so the compiler can verify the closure is
|
|
84
|
-
/// Sendable without falling back on implicit `self` capture.
|
|
85
|
-
///
|
|
86
|
-
/// The `completion` consumer is a `Result<Wire, Error>` — the
|
|
87
|
-
/// per-module wrapper translates that into `Promise.resolve` /
|
|
88
|
-
/// `Promise.reject`.
|
|
89
|
-
func analyze(
|
|
90
|
-
image: UIImage,
|
|
91
|
-
rotation: Int,
|
|
92
|
-
completion: @escaping (Result<Wire, Error>) -> Void
|
|
93
|
-
) {
|
|
94
|
-
let scan = self.scan
|
|
95
|
-
let drainEvents = self.drainEvents
|
|
96
|
-
let buildResult = self.buildResult
|
|
97
|
-
let completionBox = ExecutorCompletion(completion)
|
|
98
|
-
Task.detached(priority: .userInitiated) {
|
|
99
|
-
let (output, state) = await scan(image, rotation)
|
|
100
|
-
let events = drainEvents()
|
|
101
|
-
completionBox.call(.success(buildResult(output, state, events)))
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/// Awaits the captured `flushFn` on a detached task. Mirrors `analyze`'s
|
|
106
|
-
/// capture discipline — no `self`, no class state.
|
|
107
|
-
func flush(completion: @escaping (Result<Void, Error>) -> Void) {
|
|
108
|
-
let flushFn = self.flushFn
|
|
109
|
-
let completionBox = ExecutorCompletion(completion)
|
|
110
|
-
Task.detached(priority: .userInitiated) {
|
|
111
|
-
do {
|
|
112
|
-
try await flushFn()
|
|
113
|
-
completionBox.call(.success(()))
|
|
114
|
-
} catch {
|
|
115
|
-
completionBox.call(.failure(error))
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|