🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@getyoti/react-face-capture

Package Overview
Dependencies
Maintainers
3
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@getyoti/react-face-capture

Face capture module to collect picture and data for Yoti AI API

1.0.0
npm
Version published
Weekly downloads
891
-40.28%
Maintainers
3
Weekly downloads
 
Created
Source

Yoti Face capture integration

The purpose of this module is to capture a face and return the output image.

Pre-requisite to adopt the dependency

Peer dependencies

The package depends on the following peer dependencies

"react": ">=16.12.0 <18",
"react-dom": ">=16.12.0 <18"

Browser support

BrowserVersions
and_chr98
chrome98,97,96,95
edge98,97
firefox97,96,95,94
ios_saf15.2-15.3,15.0-15.1,14.5-14.8
safari15.2-15.3,15.1,15,14.1

Secondly, the module needs MediaDevices.getUserMedia() to work. When this isn't supported by the browser, the error UNSUPPORTED_BROWSER will be sent.

Note: Non-Safari browsers on iOS are not supported because of an iOS limitation.

Note: Edge is only supported on desktop versions.

Finally, some devices might experience poor performance when attempting to detect a face. This is because the underlying library TensorFlow.js can still be too demanding for older less performant devices.

React face capture module

Install dependency

npm i @getyoti/react-face-capture -S

import js and css

import FaceCapture from "@getyoti/react-face-capture"
import "@getyoti/react-face-capture/index.css"

Copy assets

Assets are not included in the javascript bundle. To have the components to work correctly, you will need to copy library assets from @getyoti/react-face-capture/assets folder into your assets folder.

For instance, in webpack you can use the plugin copy-webpack-plugin in the following way:

new CopyPlugin([
  {
    from: path.resolve(__dirname, './node_modules/@getyoti/react-face-capture/assets'),
    to: path.resolve(__dirname, './assets')
  }
]),

Props

Property nameTypeDefaultMandDescription
captureMethodString manual/autoauto-Capture method to take the photo: by clicking a button or auto-capture.
manualCaptureFallbackBooleantrue-In auto capture method, allow the use of manual capture mode as fallback. This would be triggered only when low performance conditions are detected, usually on very old devices. NOTE: If this option is turned off, some users might not be able to successfully submit an image.
countdownModeString only_desktop/only_mobile/never/alwaysnever-Indicates when the countdown will be used. Note: It's only used if captureMethod is set to manual.
secureBooleanfalse-If true, the face capture module will use the secure mode
onSuccessFunction({ img, secure })-YCallback called once the result (capture) is complete. The field secure is only returned in secure mode (See secure mode section)
onErrorFunction--Callback called when there is an error. See Appendix for the list of error codes we currently support.
onReadyForCaptureFunction--Callback called when the face capture module is ready to take images (Video feed and face scan are ready).
showOverlayBooleantrue-Optional use of the face overlay.
resolutionTypeString hd/full_hdhd-Image resolution constraints passed to getUserMedia.
formatStringjpeg-Image format type.
CustomManualButtonFunctionsimple button-Custom UI of the manual capture button. It uses onClick and disabled as props.
CustomConsentButtonFunctionsimple button-Custom UI of the consent button. It uses onClick and disabled as props.
imageTypeString original/croppedoriginal-imageType select if the image will be the original or it will be cropped in order to improve the timing response when processing the image in the API call.
qualityTypeString high/medium/lowhigh-Sets the image quality of jpeg format images only. High (1) - Medium (0.96) - Low (0.90).
languageLanguage code (*)en-The language code to set the language of the feedback messages.
a11yLiveRegionModeString assertive/politepolite-Determines the politeness setting of the live region used to read out prompts for screen reader users
isConsentRequiredBooleanfalse-Makes sure that the user gives consent to the tool to analyse their face. If it is true, a button will appear on the bottom section of the module, asking the user for their consent, and not analysing the user face until the consent is given. After this, the button disappears.
faceCaptureAssetsRootUrlstringassets/face-capture/-Root url where the face detection assets are located. See copy assets section for assets configuration.

(*) Current languages supported:

  • en: English
  • ar: Arabic
  • cs: Czech
  • da: Danish
  • de: German
  • es: Spanish (Spain)
  • es-419: Spanish (Latin America)
  • et: Estonian
  • fi: Finnish
  • fr: French
  • he: Hebrew
  • hi: Hindi
  • hy: Armenian
  • id: Bahasa
  • it: Italian
  • ja: Japanese
  • ko: Korean
  • lt: Lithuanian
  • lv: Latvian
  • ms: Malay
  • nb: Norwegian
  • nl: Dutch
  • pl: Polish
  • pt: Portuguese
  • ro: Romanian
  • ru: Russian
  • sv: Swedish
  • th: Thai
  • tr: Turkish
  • uk: Ukranian
  • ur: Urdu
  • vi: Vietnamese

Language fallback

Mechanisnm used for the prop language to avoid issues when the value passed is wrong. Example: first try exact match (es-es or es-ES, ignore case):

  • If no match, try the mainstream (es), by removing the region part (-es).
  • If no mainstream, try any other available es-[region] sibling (example: es-419).
  • If no regional sibling, use the default language: en.

Supported error codes

Error codeDescription
NO_CAMERANo camera detected on the user’s device
GENERIC_CAMERA_ERROROther camera error. The reasons can be various, and inconsistent across browsers. The complete error is logged in the user’s browser console.
UNSUPPORTED_BROWSERThe user’s browser is not supported, because the API needed for camera interaction is missing. Note: Older Non-Safari browsers on iOS also fall into this category.
NO_CAMERA_PERMISSIONThe user rejected the camera permission
OVERCONSTRAINEDThe camera constraints are not compatible with any camera device. Note: One recovery option is to lower the widthMinConstraint value.
FACE_DETECTION_INIT_ERRORThe face detection has failed to initialise. This usually means that the required model assets are missing from the host application.
INTERNAL_ERRORInternal error. This can be due to a programming error, or the user using an old unsupported browser.
CAPTURE_LOAD_ERRORThe secure module could not be loaded. This usually means your token is not updated, or there is an error on the module provider.

The error codes can be imported as follow:

import { ERROR_CODE } from '@getyoti/react-face-capture';

Secure mode

The secure mode allows Yoti back-end service verifying the image captured on the client-side browser with the FCM hasn't been modified in any form. Note the Secure mode of Yoti FCM will request Yoti back-end in order to download the encrypted capture package that takes the photos and create the secure result request. The secure result information will be returned in onSuccess callback:

{
  "img": "<base64_img>",
  "secure": {
    "version": "<fcm_version>",
    "token": "<session_token>",
    "signature": "<result_signature>"
  }
}

The flow for the secure mode is the following:

  • Request for a session -> (GET) https://api.yoti.com/ai/sm/v1/secure-fcm/<version>/token
  • Request for the encrypted javascript module -> (GET) https://api.yoti.com/ai/sm/v1/secure-fcm/<version>/module?s=<token>

Where <version> is the current version of the FCM (It is embedded in the module) and the <token> is the session token the first request returns.

Diagram

Possible issues

The secure mode requests Yoti back-end in order to download the encrypted module on demand so the front-end must be able to handle that requests. Keep in mind if your front-end uses any mechanism to prevent data injection attacks or cross-site scripting like SCP you will need to allow the FCM requests.

Example

import FaceCapture from '@getyoti/react-face-capture';
import '@getyoti/react-face-capture/index.css';

export function App() {
  const onSuccess = ({ image }) => console.log('Length = ', image.length);
  const onError = (error) => console.log('Error =', error);

  return <FaceCapture onSuccess={onSuccess} onError={onError} />;
}

Face capture module vanilla

If you do not have a react tech stack, you can use the face capture vanilla version. When you install the library on your machine, It's located inside the folder vanilla.

Add the package in your codebase and serve the static assets:

1. serve package static assets


/@getyoti/react-face-capture/vanilla/assets/face-capture/
/@getyoti/react-face-capture/vanilla/index.css
/@getyoti/react-face-capture/vanilla/index.js

2. Add Face capture script and style

Inside the page you want to have face capture, add Face capture scripts and style like in the example below. faceCaptureAssetsRootUrl is property you can use to instruct the library where neural net files are served otherwise we look the files relative to the page location assets/face-capture/.

3. Render face capture

Our scripts will give you access to Yoti.FaceCaptureModule.render you can pass 2 parameters, first parameters are the props and are the same used in react integration and second parameter you need a html DOM reference so we know where we can render the UI.

In order to unmount the component, it is highly recommended to call the Yoti.FaceCaptureModule.unmount function instead of destroying the HTML element, as this could lead to some issues or misbehavior.

index.html

<link href="/@getyoti/react-face-capture/vanilla/index.css" />
<script src="/@getyoti/react-face-capture/vanilla/index.js" />
<script>
  const props = {
    faceCaptureAssetsRootUrl: '/@getyoti/react-face-capture/vanilla/assets/';
  };

  const fcm = Yoti.FaceCaptureModule.render(props, document.getElementById('face-capture-module-root'));

  function reload() {
        fcm.reload()
  }

  function unmount() {
        fcm.unmount()
  }
</script>

<div id="face-capture-module-root"></div>

CHANGELOG

CHANGELOG file.

FAQs

Package last updated on 22 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts