-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into selfie-instruction-screen
- Loading branch information
Showing
9 changed files
with
999 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
404 changes: 404 additions & 0 deletions
404
packages/components/document-capture/document-instructions/src/DocumentInstruction.js
Large diffs are not rendered by default.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
...ages/components/document-capture/document-instructions/src/DocumentInstruction.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import "./index"; | ||
|
||
const meta = { | ||
component: "document-instruction", | ||
}; | ||
|
||
export default meta; | ||
|
||
export const DocumentInstruction = { | ||
render: () => ` | ||
<document-instruction | ||
show-navigation | ||
document-capture-modes="camera,upload" | ||
> | ||
</document-instruction> | ||
`, | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/components/document-capture/document-instructions/src/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { | ||
DocumentInstruction | ||
} from './DocumentInstruction'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* The type of image submitted in the job request | ||
* @readonly | ||
* @enum {number} | ||
*/ | ||
export const IMAGE_TYPE = { | ||
/** SELFIE_IMAGE_FILE Selfie image in .png or .jpg file format */ | ||
SELFIE_IMAGE_FILE: 0, | ||
/** ID_CARD_IMAGE_FILE ID card image in .png or .jpg file format */ | ||
ID_CARD_IMAGE_FILE: 1, | ||
/** SELFIE_IMAGE_BASE64 Base64 encoded selfie image (.png or .jpg) */ | ||
SELFIE_IMAGE_BASE64: 2, | ||
/** ID_CARD_IMAGE_BASE64 Base64 encoded ID card image (.png or .jpg) */ | ||
ID_CARD_IMAGE_BASE64: 3, | ||
/** LIVENESS_IMAGE_FILE Liveness image in .png or .jpg file format */ | ||
LIVENESS_IMAGE_FILE: 4, | ||
/** ID_CARD_BACK_IMAGE_FILE Back of ID card image in .png or .jpg file format */ | ||
ID_CARD_BACK_IMAGE_FILE: 5, | ||
/** LIVENESS_IMAGE_BASE64 Base64 encoded liveness image (.jpg or .png) */ | ||
LIVENESS_IMAGE_BASE64: 6, | ||
/** ID_CARD_BACK_IMAGE_BASE64 Base64 encoded back of ID card image (.jpg or .png) */ | ||
ID_CARD_BACK_IMAGE_BASE64: 7, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
class SmartFileUpload { | ||
static memoryLimit = 10240000; | ||
|
||
static supportedTypes = ['image/jpeg', 'image/png']; | ||
|
||
static getHumanSize(numberOfBytes) { | ||
// Approximate to the closest prefixed unit | ||
const units = [ | ||
'B', | ||
'kB', | ||
'MB', | ||
'GB', | ||
'TB', | ||
'PB', | ||
'EB', | ||
'ZB', | ||
'YB', | ||
]; | ||
const exponent = Math.min( | ||
Math.floor(Math.log(numberOfBytes) / Math.log(1024)), | ||
units.length - 1, | ||
); | ||
const approx = numberOfBytes / 1024 ** exponent; | ||
const output = exponent === 0 | ||
? `${numberOfBytes} bytes` | ||
: `${approx.toFixed(0)} ${units[exponent]}`; | ||
|
||
return output; | ||
} | ||
|
||
static getData(file) { | ||
return new Promise((resolve, reject) => { | ||
const reader = new FileReader(); | ||
|
||
reader.onload = (e) => { | ||
resolve(e.target.result); | ||
}; | ||
reader.onerror = () => { | ||
reject(new Error('An error occurred reading the file. Please check the file, and try again')); | ||
}; | ||
reader.readAsDataURL(file); | ||
}); | ||
} | ||
|
||
static async retrieve(files) { | ||
if (files.length > 1) { | ||
throw new Error('Only one file upload is permitted at a time'); | ||
} | ||
|
||
const file = files[0]; | ||
|
||
if (!SmartFileUpload.supportedTypes.includes(file.type)) { | ||
throw new Error('Unsupported file format. Please ensure that you are providing a JPG or PNG image'); | ||
} | ||
|
||
if (file.size > SmartFileUpload.memoryLimit) { | ||
throw new Error(`${file.name} is too large. Please ensure that the file is less than ${SmartFileUpload.getHumanSize(SmartFileUpload.memoryLimit)}.`); | ||
} | ||
|
||
const imageAsDataUrl = await SmartFileUpload.getData(file); | ||
|
||
return imageAsDataUrl; | ||
} | ||
} | ||
|
||
export default SmartFileUpload; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
class SmartCamera { | ||
static stream = null; | ||
|
||
static async getMedia(constraints) { | ||
try { | ||
SmartCamera.stream = await navigator.mediaDevices.getUserMedia({ | ||
...constraints, | ||
video: { | ||
...constraints.video, | ||
// NOTE: Special case for multi-camera Samsung devices (learnt from Acuant) | ||
// "We found out that some triple camera Samsung devices (S10, S20, Note 20, etc) capture images blurry at edges. | ||
// Zooming to 2X, matching the telephoto lens, doesn't solve it completely but mitigates it." | ||
zoom: SmartCamera.isSamsungMultiCameraDevice() ? 2.0 : 1.0, | ||
} | ||
}); | ||
return SmartCamera.stream; | ||
} catch (error) { | ||
throw error; | ||
} | ||
} | ||
|
||
static stopMedia() { | ||
if (SmartCamera.stream) { | ||
SmartCamera.stream.getTracks().forEach(track => track.stop()); | ||
SmartCamera.stream = null; | ||
} | ||
} | ||
|
||
static isSamsungMultiCameraDevice() { | ||
const matchedModelNumber = navigator.userAgent.match(/SM-[N|G]\d{3}/); | ||
if (!matchedModelNumber) { | ||
return false; | ||
} | ||
|
||
const modelNumber = parseInt(matchedModelNumber[0].match(/\d{3}/)[0], 10); | ||
const smallerModelNumber = 970; // S10e | ||
return !isNaN(modelNumber) && modelNumber >= smallerModelNumber; | ||
} | ||
|
||
static handleCameraError(e) { | ||
switch (e.name) { | ||
case 'NotAllowedError': | ||
case 'SecurityError': | ||
return ` | ||
Looks like camera access was not granted, or was blocked by a browser | ||
level setting / extension. Please follow the prompt from the URL bar, | ||
or extensions, and enable access. | ||
You may need to refresh to start all over again | ||
`; | ||
case 'AbortError': | ||
return ` | ||
Oops! Something happened, and we lost access to your stream. | ||
Please refresh to start all over again | ||
`; | ||
case 'NotReadableError': | ||
return ` | ||
There seems to be a problem with your device's camera, or its connection. | ||
Please check this, and when resolved, try again. Or try another device. | ||
`; | ||
case 'NotFoundError': | ||
return ` | ||
We are unable to find a video stream. | ||
You may need to refresh to start all over again | ||
`; | ||
case 'TypeError': | ||
return ` | ||
This site is insecure, and as such cannot have access to your camera. | ||
Try to navigate to a secure version of this page, or contact the owner. | ||
`; | ||
default: | ||
return e.message; | ||
} | ||
} | ||
} | ||
|
||
export { SmartCamera }; |
Oops, something went wrong.