react-native-vision-camera-spoof-detector 1.1.0 → 1.1.8

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.

Potentially problematic release.


This version of react-native-vision-camera-spoof-detector might be problematic. Click here for more details.

Files changed (43) hide show
  1. package/.npmignore +16 -0
  2. package/android/CMakeLists.txt +29 -0
  3. package/android/build.gradle +26 -10
  4. package/android/fix-prefab.gradle +4 -0
  5. package/android/src/main/AndroidManifest.xml +1 -1
  6. package/android/src/main/cpp/CMakeLists.txt +18 -86
  7. package/android/src/main/cpp/FaceAntiSpoofJSI.cpp +80 -6
  8. package/android/src/main/cpp/cpp-adapter.cpp +9 -0
  9. package/android/src/main/java/com/faceantispoof/FaceAntiSpoofModule.kt +55 -103
  10. package/android/src/main/java/com/faceantispoof/FaceAntiSpoofPackage.kt +15 -8
  11. package/android/src/main/java/com/margelo/nitro/camera/spoofdetector/HybridSpoofDetectorFactory.kt +15 -0
  12. package/android/src/main/java/com/margelo/nitro/camera/spoofdetector/HybridSpoofDetectorOutput.kt +107 -0
  13. package/index.js +23 -42
  14. package/nitro.json +20 -0
  15. package/nitrogen/generated/.gitattributes +1 -0
  16. package/nitrogen/generated/android/VisionCameraSpoofDetector+autolinking.cmake +81 -0
  17. package/nitrogen/generated/android/VisionCameraSpoofDetector+autolinking.gradle +27 -0
  18. package/nitrogen/generated/android/VisionCameraSpoofDetectorOnLoad.cpp +58 -0
  19. package/nitrogen/generated/android/VisionCameraSpoofDetectorOnLoad.hpp +34 -0
  20. package/nitrogen/generated/android/c++/JAntiSpoofingResult.hpp +77 -0
  21. package/nitrogen/generated/android/c++/JFunc_void_AntiSpoofingResult.hpp +78 -0
  22. package/nitrogen/generated/android/c++/JFunc_void_std__exception_ptr.hpp +76 -0
  23. package/nitrogen/generated/android/c++/JHybridSpoofDetectorFactorySpec.cpp +75 -0
  24. package/nitrogen/generated/android/c++/JHybridSpoofDetectorFactorySpec.hpp +63 -0
  25. package/nitrogen/generated/android/c++/JSize.hpp +61 -0
  26. package/nitrogen/generated/android/c++/JSpoofDetectorOutputOptions.hpp +91 -0
  27. package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/spoofdetector/AntiSpoofingResult.kt +76 -0
  28. package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/spoofdetector/Func_void_AntiSpoofingResult.kt +78 -0
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/spoofdetector/Func_void_std__exception_ptr.kt +78 -0
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/spoofdetector/HybridSpoofDetectorFactorySpec.kt +57 -0
  31. package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/spoofdetector/Size.kt +56 -0
  32. package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/spoofdetector/SpoofDetectorOutputOptions.kt +65 -0
  33. package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/spoofdetector/VisionCameraSpoofDetectorOnLoad.kt +35 -0
  34. package/nitrogen/generated/shared/c++/AntiSpoofingResult.hpp +103 -0
  35. package/nitrogen/generated/shared/c++/HybridSpoofDetectorFactorySpec.cpp +21 -0
  36. package/nitrogen/generated/shared/c++/HybridSpoofDetectorFactorySpec.hpp +67 -0
  37. package/nitrogen/generated/shared/c++/Size.hpp +87 -0
  38. package/nitrogen/generated/shared/c++/SpoofDetectorOutputOptions.hpp +98 -0
  39. package/package.json +10 -8
  40. package/src/specs/SpoofDetectorFactory.nitro.ts +23 -0
  41. package/android/src/main/assets/spoof_model_scale_2_7.tflite +0 -0
  42. package/android/src/main/assets/spoof_model_scale_4_0.tflite +0 -0
  43. /package/{android/src/main → lib}/assets/FaceAntiSpoofing.tflite +0 -0
@@ -0,0 +1,65 @@
1
+ ///
2
+ /// SpoofDetectorOutputOptions.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.camera.spoofdetector
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+ import java.util.Objects
13
+
14
+
15
+ /**
16
+ * Represents the JavaScript object/struct "SpoofDetectorOutputOptions".
17
+ */
18
+ @DoNotStrip
19
+ @Keep
20
+ data class SpoofDetectorOutputOptions(
21
+ @DoNotStrip
22
+ @Keep
23
+ val targetResolution: Size?,
24
+ @DoNotStrip
25
+ @Keep
26
+ val onResult: Func_void_AntiSpoofingResult,
27
+ @DoNotStrip
28
+ @Keep
29
+ val onError: Func_void_std__exception_ptr?
30
+ ) {
31
+ /**
32
+ * Create a new instance of SpoofDetectorOutputOptions from Kotlin
33
+ */
34
+ constructor(targetResolution: Size?, onResult: (result: AntiSpoofingResult) -> Unit, onError: ((error: Throwable) -> Unit)?):
35
+ this(targetResolution, Func_void_AntiSpoofingResult_java(onResult), onError?.let { Func_void_std__exception_ptr_java(it) })
36
+
37
+ override fun equals(other: Any?): Boolean {
38
+ if (this === other) return true
39
+ if (other !is SpoofDetectorOutputOptions) return false
40
+ return Objects.deepEquals(this.targetResolution, other.targetResolution)
41
+ && Objects.deepEquals(this.onResult, other.onResult)
42
+ && Objects.deepEquals(this.onError, other.onError)
43
+ }
44
+
45
+ override fun hashCode(): Int {
46
+ return arrayOf<Any?>(
47
+ targetResolution,
48
+ onResult,
49
+ onError
50
+ ).contentDeepHashCode()
51
+ }
52
+
53
+ companion object {
54
+ /**
55
+ * Constructor called from C++
56
+ */
57
+ @DoNotStrip
58
+ @Keep
59
+ @Suppress("unused")
60
+ @JvmStatic
61
+ private fun fromCpp(targetResolution: Size?, onResult: Func_void_AntiSpoofingResult, onError: Func_void_std__exception_ptr?): SpoofDetectorOutputOptions {
62
+ return SpoofDetectorOutputOptions(targetResolution, onResult, onError)
63
+ }
64
+ }
65
+ }
@@ -0,0 +1,35 @@
1
+ ///
2
+ /// VisionCameraSpoofDetectorOnLoad.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.camera.spoofdetector
9
+
10
+ import android.util.Log
11
+
12
+ internal class VisionCameraSpoofDetectorOnLoad {
13
+ companion object {
14
+ private const val TAG = "VisionCameraSpoofDetectorOnLoad"
15
+ private var didLoad = false
16
+ /**
17
+ * Initializes the native part of "VisionCameraSpoofDetector".
18
+ * This method is idempotent and can be called more than once.
19
+ */
20
+ @JvmStatic
21
+ fun initializeNative() {
22
+ if (didLoad) return
23
+ try {
24
+ Log.i(TAG, "Loading VisionCameraSpoofDetector C++ library...")
25
+ System.loadLibrary("VisionCameraSpoofDetector")
26
+ Log.i(TAG, "Successfully loaded VisionCameraSpoofDetector C++ library!")
27
+ didLoad = true
28
+ } catch (e: Error) {
29
+ Log.e(TAG, "Failed to load VisionCameraSpoofDetector C++ library! Is it properly installed and linked? " +
30
+ "Is the name correct? (see `CMakeLists.txt`, at `add_library(...)`)", e)
31
+ throw e
32
+ }
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,103 @@
1
+ ///
2
+ /// AntiSpoofingResult.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
+ #include <NitroModules/PropNameIDCache.hpp>
27
+ #else
28
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
+ #endif
30
+
31
+
32
+
33
+ #include <string>
34
+
35
+ namespace margelo::nitro::camera::spoofdetector {
36
+
37
+ /**
38
+ * A struct which can be represented as a JavaScript object (AntiSpoofingResult).
39
+ */
40
+ struct AntiSpoofingResult final {
41
+ public:
42
+ bool isLive SWIFT_PRIVATE;
43
+ std::string label SWIFT_PRIVATE;
44
+ double neuralNetworkScore SWIFT_PRIVATE;
45
+ double laplacianScore SWIFT_PRIVATE;
46
+ double combinedScore SWIFT_PRIVATE;
47
+ double confidence SWIFT_PRIVATE;
48
+
49
+ public:
50
+ AntiSpoofingResult() = default;
51
+ explicit AntiSpoofingResult(bool isLive, std::string label, double neuralNetworkScore, double laplacianScore, double combinedScore, double confidence): isLive(isLive), label(label), neuralNetworkScore(neuralNetworkScore), laplacianScore(laplacianScore), combinedScore(combinedScore), confidence(confidence) {}
52
+
53
+ public:
54
+ friend bool operator==(const AntiSpoofingResult& lhs, const AntiSpoofingResult& rhs) = default;
55
+ };
56
+
57
+ } // namespace margelo::nitro::camera::spoofdetector
58
+
59
+ namespace margelo::nitro {
60
+
61
+ // C++ AntiSpoofingResult <> JS AntiSpoofingResult (object)
62
+ template <>
63
+ struct JSIConverter<margelo::nitro::camera::spoofdetector::AntiSpoofingResult> final {
64
+ static inline margelo::nitro::camera::spoofdetector::AntiSpoofingResult fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
65
+ jsi::Object obj = arg.asObject(runtime);
66
+ return margelo::nitro::camera::spoofdetector::AntiSpoofingResult(
67
+ JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "isLive"))),
68
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "label"))),
69
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "neuralNetworkScore"))),
70
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "laplacianScore"))),
71
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "combinedScore"))),
72
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "confidence")))
73
+ );
74
+ }
75
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::camera::spoofdetector::AntiSpoofingResult& arg) {
76
+ jsi::Object obj(runtime);
77
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "isLive"), JSIConverter<bool>::toJSI(runtime, arg.isLive));
78
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "label"), JSIConverter<std::string>::toJSI(runtime, arg.label));
79
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "neuralNetworkScore"), JSIConverter<double>::toJSI(runtime, arg.neuralNetworkScore));
80
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "laplacianScore"), JSIConverter<double>::toJSI(runtime, arg.laplacianScore));
81
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "combinedScore"), JSIConverter<double>::toJSI(runtime, arg.combinedScore));
82
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "confidence"), JSIConverter<double>::toJSI(runtime, arg.confidence));
83
+ return obj;
84
+ }
85
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
86
+ if (!value.isObject()) {
87
+ return false;
88
+ }
89
+ jsi::Object obj = value.getObject(runtime);
90
+ if (!nitro::isPlainObject(runtime, obj)) {
91
+ return false;
92
+ }
93
+ if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "isLive")))) return false;
94
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "label")))) return false;
95
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "neuralNetworkScore")))) return false;
96
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "laplacianScore")))) return false;
97
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "combinedScore")))) return false;
98
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "confidence")))) return false;
99
+ return true;
100
+ }
101
+ };
102
+
103
+ } // namespace margelo::nitro
@@ -0,0 +1,21 @@
1
+ ///
2
+ /// HybridSpoofDetectorFactorySpec.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "HybridSpoofDetectorFactorySpec.hpp"
9
+
10
+ namespace margelo::nitro::camera::spoofdetector {
11
+
12
+ void HybridSpoofDetectorFactorySpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridMethod("createSpoofDetectorOutput", &HybridSpoofDetectorFactorySpec::createSpoofDetectorOutput);
18
+ });
19
+ }
20
+
21
+ } // namespace margelo::nitro::camera::spoofdetector
@@ -0,0 +1,67 @@
1
+ ///
2
+ /// HybridSpoofDetectorFactorySpec.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+ // Forward declaration of `HybridCameraOutputSpec` to properly resolve imports.
17
+ namespace margelo::nitro::camera { class HybridCameraOutputSpec; }
18
+ // Forward declaration of `SpoofDetectorOutputOptions` to properly resolve imports.
19
+ namespace margelo::nitro::camera::spoofdetector { struct SpoofDetectorOutputOptions; }
20
+
21
+ #include <memory>
22
+ #include <VisionCamera/HybridCameraOutputSpec.hpp>
23
+ #include "SpoofDetectorOutputOptions.hpp"
24
+
25
+ namespace margelo::nitro::camera::spoofdetector {
26
+
27
+ using namespace margelo::nitro;
28
+
29
+ /**
30
+ * An abstract base class for `SpoofDetectorFactory`
31
+ * Inherit this class to create instances of `HybridSpoofDetectorFactorySpec` in C++.
32
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
33
+ * @example
34
+ * ```cpp
35
+ * class HybridSpoofDetectorFactory: public HybridSpoofDetectorFactorySpec {
36
+ * public:
37
+ * HybridSpoofDetectorFactory(...): HybridObject(TAG) { ... }
38
+ * // ...
39
+ * };
40
+ * ```
41
+ */
42
+ class HybridSpoofDetectorFactorySpec: public virtual HybridObject {
43
+ public:
44
+ // Constructor
45
+ explicit HybridSpoofDetectorFactorySpec(): HybridObject(TAG) { }
46
+
47
+ // Destructor
48
+ ~HybridSpoofDetectorFactorySpec() override = default;
49
+
50
+ public:
51
+ // Properties
52
+
53
+
54
+ public:
55
+ // Methods
56
+ virtual std::shared_ptr<margelo::nitro::camera::HybridCameraOutputSpec> createSpoofDetectorOutput(const SpoofDetectorOutputOptions& options) = 0;
57
+
58
+ protected:
59
+ // Hybrid Setup
60
+ void loadHybridMethods() override;
61
+
62
+ protected:
63
+ // Tag for logging
64
+ static constexpr auto TAG = "SpoofDetectorFactory";
65
+ };
66
+
67
+ } // namespace margelo::nitro::camera::spoofdetector
@@ -0,0 +1,87 @@
1
+ ///
2
+ /// Size.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
+ #include <NitroModules/PropNameIDCache.hpp>
27
+ #else
28
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
+ #endif
30
+
31
+
32
+
33
+
34
+
35
+ namespace margelo::nitro::camera::spoofdetector {
36
+
37
+ /**
38
+ * A struct which can be represented as a JavaScript object (Size).
39
+ */
40
+ struct Size final {
41
+ public:
42
+ double width SWIFT_PRIVATE;
43
+ double height SWIFT_PRIVATE;
44
+
45
+ public:
46
+ Size() = default;
47
+ explicit Size(double width, double height): width(width), height(height) {}
48
+
49
+ public:
50
+ friend bool operator==(const Size& lhs, const Size& rhs) = default;
51
+ };
52
+
53
+ } // namespace margelo::nitro::camera::spoofdetector
54
+
55
+ namespace margelo::nitro {
56
+
57
+ // C++ Size <> JS Size (object)
58
+ template <>
59
+ struct JSIConverter<margelo::nitro::camera::spoofdetector::Size> final {
60
+ static inline margelo::nitro::camera::spoofdetector::Size fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
61
+ jsi::Object obj = arg.asObject(runtime);
62
+ return margelo::nitro::camera::spoofdetector::Size(
63
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "width"))),
64
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height")))
65
+ );
66
+ }
67
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::camera::spoofdetector::Size& arg) {
68
+ jsi::Object obj(runtime);
69
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "width"), JSIConverter<double>::toJSI(runtime, arg.width));
70
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "height"), JSIConverter<double>::toJSI(runtime, arg.height));
71
+ return obj;
72
+ }
73
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
74
+ if (!value.isObject()) {
75
+ return false;
76
+ }
77
+ jsi::Object obj = value.getObject(runtime);
78
+ if (!nitro::isPlainObject(runtime, obj)) {
79
+ return false;
80
+ }
81
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "width")))) return false;
82
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height")))) return false;
83
+ return true;
84
+ }
85
+ };
86
+
87
+ } // namespace margelo::nitro
@@ -0,0 +1,98 @@
1
+ ///
2
+ /// SpoofDetectorOutputOptions.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
+ #include <NitroModules/PropNameIDCache.hpp>
27
+ #else
28
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
+ #endif
30
+
31
+ // Forward declaration of `Size` to properly resolve imports.
32
+ namespace margelo::nitro::camera::spoofdetector { struct Size; }
33
+ // Forward declaration of `AntiSpoofingResult` to properly resolve imports.
34
+ namespace margelo::nitro::camera::spoofdetector { struct AntiSpoofingResult; }
35
+
36
+ #include "Size.hpp"
37
+ #include <optional>
38
+ #include "AntiSpoofingResult.hpp"
39
+ #include <functional>
40
+ #include <exception>
41
+
42
+ namespace margelo::nitro::camera::spoofdetector {
43
+
44
+ /**
45
+ * A struct which can be represented as a JavaScript object (SpoofDetectorOutputOptions).
46
+ */
47
+ struct SpoofDetectorOutputOptions final {
48
+ public:
49
+ std::optional<Size> targetResolution SWIFT_PRIVATE;
50
+ std::function<void(const AntiSpoofingResult& /* result */)> onResult SWIFT_PRIVATE;
51
+ std::optional<std::function<void(const std::exception_ptr& /* error */)>> onError SWIFT_PRIVATE;
52
+
53
+ public:
54
+ SpoofDetectorOutputOptions() = default;
55
+ explicit SpoofDetectorOutputOptions(std::optional<Size> targetResolution, std::function<void(const AntiSpoofingResult& /* result */)> onResult, std::optional<std::function<void(const std::exception_ptr& /* error */)>> onError): targetResolution(targetResolution), onResult(onResult), onError(onError) {}
56
+
57
+ public:
58
+ // SpoofDetectorOutputOptions is not equatable because these properties are not equatable: onResult, onError
59
+ };
60
+
61
+ } // namespace margelo::nitro::camera::spoofdetector
62
+
63
+ namespace margelo::nitro {
64
+
65
+ // C++ SpoofDetectorOutputOptions <> JS SpoofDetectorOutputOptions (object)
66
+ template <>
67
+ struct JSIConverter<margelo::nitro::camera::spoofdetector::SpoofDetectorOutputOptions> final {
68
+ static inline margelo::nitro::camera::spoofdetector::SpoofDetectorOutputOptions fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
69
+ jsi::Object obj = arg.asObject(runtime);
70
+ return margelo::nitro::camera::spoofdetector::SpoofDetectorOutputOptions(
71
+ JSIConverter<std::optional<margelo::nitro::camera::spoofdetector::Size>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "targetResolution"))),
72
+ JSIConverter<std::function<void(const margelo::nitro::camera::spoofdetector::AntiSpoofingResult&)>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onResult"))),
73
+ JSIConverter<std::optional<std::function<void(const std::exception_ptr&)>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onError")))
74
+ );
75
+ }
76
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::camera::spoofdetector::SpoofDetectorOutputOptions& arg) {
77
+ jsi::Object obj(runtime);
78
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "targetResolution"), JSIConverter<std::optional<margelo::nitro::camera::spoofdetector::Size>>::toJSI(runtime, arg.targetResolution));
79
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "onResult"), JSIConverter<std::function<void(const margelo::nitro::camera::spoofdetector::AntiSpoofingResult&)>>::toJSI(runtime, arg.onResult));
80
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "onError"), JSIConverter<std::optional<std::function<void(const std::exception_ptr&)>>>::toJSI(runtime, arg.onError));
81
+ return obj;
82
+ }
83
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
84
+ if (!value.isObject()) {
85
+ return false;
86
+ }
87
+ jsi::Object obj = value.getObject(runtime);
88
+ if (!nitro::isPlainObject(runtime, obj)) {
89
+ return false;
90
+ }
91
+ if (!JSIConverter<std::optional<margelo::nitro::camera::spoofdetector::Size>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "targetResolution")))) return false;
92
+ if (!JSIConverter<std::function<void(const margelo::nitro::camera::spoofdetector::AntiSpoofingResult&)>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onResult")))) return false;
93
+ if (!JSIConverter<std::optional<std::function<void(const std::exception_ptr&)>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onError")))) return false;
94
+ return true;
95
+ }
96
+ };
97
+
98
+ } // namespace margelo::nitro
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-vision-camera-spoof-detector",
3
- "version": "1.1.0",
3
+ "version": "1.1.8",
4
4
  "description": "High-performance face anti-spoofing and liveness detection module for React Native Vision Camera. Uses TensorFlow Lite with GPU acceleration and optimized YUV processing.",
5
5
  "homepage": "https://github.com/dpraful/react-native-vision-camera-spoof-detector",
6
6
  "repository": {
@@ -28,13 +28,18 @@
28
28
  "types": "index.d.ts",
29
29
  "files": [
30
30
  "android/",
31
+ "lib/",
32
+ "src/",
33
+ "nitrogen/",
34
+ "nitro.json",
31
35
  "ios/",
36
+ ".npmignore",
32
37
  "CHANGELOG.md",
33
- "index.js",
34
38
  "index.d.ts",
35
- "README.md",
39
+ "index.js",
36
40
  "LICENSE",
37
- "react-native-vision-camera-spoof-detector.podspec"
41
+ "react-native-vision-camera-spoof-detector.podspec",
42
+ "README.md"
38
43
  ],
39
44
  "keywords": [
40
45
  "react-native",
@@ -56,8 +61,7 @@
56
61
  "peerDependencies": {
57
62
  "react": ">=16.8.0",
58
63
  "react-native": ">=0.60.0",
59
- "react-native-vision-camera": "^4.6.4 || ^5.0.0",
60
- "react-native-reanimated": "^3.0.0",
64
+ "react-native-vision-camera": "^5.0.0",
61
65
  "react-native-vision-camera-worklets": "^5.0.0",
62
66
  "react-native-worklets": "^0.12.0"
63
67
  },
@@ -69,8 +73,6 @@
69
73
  "devDependencies": {
70
74
  "react": "^18.2.0",
71
75
  "react-native": "^0.72.0",
72
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
73
- "@babel/plugin-proposal-optional-chaining": "^7.21.0",
74
76
  "typescript": "^5.0.0"
75
77
  },
76
78
  "engines": {
@@ -0,0 +1,23 @@
1
+ import type { CameraOutput, Size } from 'react-native-vision-camera'
2
+ import type { HybridObject } from 'react-native-nitro-modules'
3
+
4
+ export interface AntiSpoofingResult {
5
+ isLive: boolean
6
+ label: string
7
+ neuralNetworkScore: number
8
+ laplacianScore: number
9
+ combinedScore: number
10
+ confidence: number
11
+ }
12
+
13
+ export interface SpoofDetectorOutputOptions {
14
+ targetResolution?: Size
15
+ onResult: (result: AntiSpoofingResult) => void
16
+ onError?: (error: Error) => void
17
+ }
18
+
19
+ export interface SpoofDetectorFactory extends HybridObject<{
20
+ android: 'kotlin'
21
+ }> {
22
+ createSpoofDetectorOutput(options: SpoofDetectorOutputOptions): CameraOutput
23
+ }