Skip to content

Commit

Permalink
Release 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
laoluani committed Mar 31, 2022
0 parents commit 1153013
Show file tree
Hide file tree
Showing 95 changed files with 11,692 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# OSX
#
.DS_Store

# node.js
#
node_modules/
npm-debug.log
yarn-error.log

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace

# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml

# BUCK
buck-out/
\.buckd/
*.keystore

# VSCode
.vscode/.react
12 changes: 12 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
android/
ios/
example/android/
example/ios/
.prettierrc.js
.vscode/
*-test.js
.eslintrc.js
.watchmanconfig
package.json
*.md
*.config.js
6 changes: 6 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
jsxBracketSameLine: true,
singleQuote: true,
trailingComma: 'none',
semi: false
};
38 changes: 38 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Run iOS",
"request": "launch",
"type": "reactnativedirect",
"cwd": "${workspaceFolder}",
"enableDebug": false,
"platform": "ios"
},
{
"name": "Debug iOS",
"request": "launch",
"type": "reactnativedirect",
"cwd": "${workspaceFolder}",
"platform": "ios"
},
{
"name": "Run Android",
"request": "launch",
"type": "reactnativedirect",
"cwd": "${workspaceFolder}",
"enableDebug": false,
"platform": "android"
},
{
"name": "Debug Android",
"request": "launch",
"type": "reactnativedirect",
"cwd": "${workspaceFolder}",
"platform": "android"
}
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"react-native-tools.projectRoot": "example"
}
328 changes: 328 additions & 0 deletions README.md

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
buildscript {
ext.kotlin_version = "1.5.30"
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 31
buildToolsVersion "31.0.0"

defaultConfig {
minSdkVersion 21
targetSdkVersion 31
versionCode 1
versionName "1.0"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

repositories {
google()
maven { url "https://raw.githubusercontent.com/iProov/android/master/maven/" }
}

dependencies {
implementation 'com.iproov.sdk:iproov:7.3.0'
implementation 'com.facebook.react:react-native:+'
}
6 changes: 6 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!-- AndroidManifest.xml -->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iproov.sdk">

</manifest>
129 changes: 129 additions & 0 deletions android/src/main/java/com/iproov/sdk/IProovReactNativeListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package com.iproov.sdk;

import androidx.annotation.NonNull;

import android.graphics.Bitmap;
import android.util.Base64;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;

import com.iproov.sdk.core.exception.CameraException;
import com.iproov.sdk.core.exception.CameraPermissionException;
import com.iproov.sdk.core.exception.CaptureAlreadyActiveException;
import com.iproov.sdk.core.exception.FaceDetectorException;
import com.iproov.sdk.core.exception.InvalidOptionsException;
import com.iproov.sdk.core.exception.IProovException;
import com.iproov.sdk.core.exception.ListenerNotRegisteredException;
import com.iproov.sdk.core.exception.MultiWindowUnsupportedException;
import com.iproov.sdk.core.exception.NetworkException;
import com.iproov.sdk.core.exception.ServerException;
import com.iproov.sdk.core.exception.UnexpectedErrorException;

import java.io.ByteArrayOutputStream;

public class IProovReactNativeListener implements IProov.Listener {

private final DeviceEventManagerModule.RCTDeviceEventEmitter eventEmitter;

public IProovReactNativeListener(ReactContext reactContext) {
eventEmitter = reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class);
}

@Override
public void onConnecting() {
eventEmitter.emit(IProovReactNativeModule.EVENT_CONNECTING, null);
}

@Override
public void onConnected() {
eventEmitter.emit(IProovReactNativeModule.EVENT_CONNECTED, null);
}

@Override
public void onProcessing(double progress, String message) {
WritableMap params = Arguments.createMap();
params.putDouble("progress", progress);
params.putString("message", message);

eventEmitter.emit(IProovReactNativeModule.EVENT_PROCESSING, params);
}

@Override
public void onSuccess(@NonNull IProov.SuccessResult successResult) {
WritableMap params = Arguments.createMap();
params.putString("token", successResult.token);

if(successResult.frame != null) {
params.putString("frame", base64EncodeBitmap(successResult.frame));
}

eventEmitter.emit(IProovReactNativeModule.EVENT_SUCCESS, params);
IProov.unregisterListener(this);
}

@Override
public void onFailure(@NonNull IProov.FailureResult failureResult) {
WritableMap params = Arguments.createMap();
params.putString("token", failureResult.token);
params.putString("feedback_code", failureResult.feedbackCode);
params.putString("reason", failureResult.reason);
if(failureResult.frame != null) {
params.putString("frame", base64EncodeBitmap(failureResult.frame));
}

eventEmitter.emit(IProovReactNativeModule.EVENT_FAILURE, params);
IProov.unregisterListener(this);
}

@Override
public void onCancelled() {
eventEmitter.emit(IProovReactNativeModule.EVENT_CANCELLED, null);
IProov.unregisterListener(this);
}

@Override
public void onError(@NonNull IProovException e) {
e.printStackTrace();
WritableMap params = Arguments.createMap();
params.putString("error", toErrorString(e));
params.putString("reason", e.getReason());
params.putString("message", e.getLocalizedMessage());

eventEmitter.emit(IProovReactNativeModule.EVENT_ERROR, params);
IProov.unregisterListener(this);
}

private static String toErrorString(IProovException e) {
if(e instanceof CaptureAlreadyActiveException) {
return "capture_already_active_error";
} else if(e instanceof NetworkException) {
return "network_error";
} else if(e instanceof CameraPermissionException) {
return "camera_permission_error";
} else if(e instanceof ServerException) {
return "server_error";
} else if(e instanceof ListenerNotRegisteredException) {
return "listener_not_registered_error";
} else if(e instanceof MultiWindowUnsupportedException) {
return "multi_window_unsupported_error";
} else if(e instanceof CameraException) {
return "camera_error";
} else if(e instanceof FaceDetectorException) {
return "face_detector_error";
} else if (e instanceof InvalidOptionsException) {
return "invalid_options_error";
} else {
return "unexpected_error";
}
}

private static String base64EncodeBitmap(Bitmap bitmap) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
return Base64.encodeToString(byteArray, Base64.NO_WRAP);
}
}
95 changes: 95 additions & 0 deletions android/src/main/java/com/iproov/sdk/IProovReactNativeModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// IProovReactNativeModule.java

package com.iproov.sdk;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

import com.iproov.sdk.bridge.OptionsBridge;
import com.iproov.sdk.core.exception.IProovException;
import com.iproov.sdk.core.exception.InvalidOptionsException;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;


public class IProovReactNativeModule extends ReactContextBaseJavaModule {

private final ReactApplicationContext reactContext;
private IProovReactNativeListener listener;

public static final String EVENT_CONNECTING = "iproov_connecting";
public static final String EVENT_CONNECTED = "iproov_connected";
public static final String EVENT_PROCESSING = "iproov_processing";
public static final String EVENT_SUCCESS = "iproov_success";
public static final String EVENT_FAILURE = "iproov_failure";
public static final String EVENT_CANCELLED = "iproov_cancelled";
public static final String EVENT_ERROR = "iproov_error";


public IProovReactNativeModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
}

@Override
public Map<String, Object> getConstants() {
final Map<String, Object> constants = new HashMap<>();
constants.put("EVENT_CONNECTING", EVENT_CONNECTING);
constants.put("EVENT_CONNECTED", EVENT_CONNECTED);
constants.put("EVENT_PROCESSING", EVENT_PROCESSING);
constants.put("EVENT_SUCCESS", EVENT_SUCCESS);
constants.put("EVENT_FAILURE", EVENT_FAILURE);
constants.put("EVENT_CANCELLED", EVENT_CANCELLED);
constants.put("EVENT_ERROR", EVENT_ERROR);
return constants;
}

@Override
public String getName() {
return "IProovReactNative";
}

@ReactMethod
public void launch(String baseUrl, String token, String optionsString) {
listener = new IProovReactNativeListener(reactContext);
IProov.registerListener(listener);

IProov.Options options;

try {
options = OptionsBridge.fromJson(reactContext, new JSONObject(optionsString));
} catch (IProovException e) {
e.printStackTrace();
listener.onError(e);
return;
} catch (JSONException e) {
e.printStackTrace();
listener.onError(new InvalidOptionsException(reactContext, e.getLocalizedMessage()));
return;
}

try {
IProov.launch(reactContext, baseUrl, token, options);
} catch (IProovException e) {
e.printStackTrace();
listener.onError(e);
}
}

// Required for RN 0.65+, otherwise you get a warning
// More info here: https://github.com/facebook/react-native/commit/114be1d2170bae2d29da749c07b45acf931e51e2
@ReactMethod
public void addListener(String eventName) {
// Do nothing
}

@ReactMethod
public void removeListeners(Integer count) {
// Do nothing
}
}
Loading

0 comments on commit 1153013

Please sign in to comment.