veryfi-lens-wasm 3.5.3 → 3.5.4
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/README.md +2 -0
- package/components/cameraPermissionMessage.js +76 -0
- package/core/camera.js +50 -3
- package/core/constants.js +2 -1
- package/core/lifecycle.js +5 -1
- package/core/state.js +4 -0
- package/package.json +1 -1
- package/veryfi-lens.js +2 -0
package/README.md
CHANGED
|
@@ -126,6 +126,7 @@ VeryfiLens.onFailure((error) => { /* error occurred */ });
|
|
|
126
126
|
| `mirrorButton` | `boolean` | `true` | Show mirror/flip video button |
|
|
127
127
|
| `mirrorOnDesktop` | `boolean` | `true` | Auto-mirror video on desktop (front-facing webcam) |
|
|
128
128
|
| `exitButton` | `boolean` | `false` | Show exit/close button |
|
|
129
|
+
| `showCameraPermissionDeniedMessage` | `boolean` | `true` | Show the in-lens message when camera access is denied. Set `false` to render it on your own error screen. A denial always hides every on-camera control and is reported via `onUpdate` as `{ status: "camera_permission_denied", message, error }` (never via `onFailure`) |
|
|
129
130
|
| `onClose` | `function` | — | Callback when lens is closed |
|
|
130
131
|
| `onCloseRedirectUrl` | `string` | — | URL to redirect to on close |
|
|
131
132
|
| `boxColor` | `string` | `"rgba(84, 192, 139, 0.6)"` | Document detection bounding box color |
|
|
@@ -291,6 +292,7 @@ When `multiSubmission` is set or `maxDocuments` is not `1`, `init()` asks the ba
|
|
|
291
292
|
| `lcdModalMessage` | `string` | `"LCD screen detected. Please capture a printed document instead"` |
|
|
292
293
|
| `submitButtonText` | `string` | `"Submit Anyway"` |
|
|
293
294
|
| `retakeButtonText` | `string` | `"Retake a picture"` |
|
|
295
|
+
| `cameraPermissionDeniedMessage` | `string` | `"Camera access was blocked. Please allow camera access in your browser settings and try again."` |
|
|
294
296
|
| `checkEnforcedModalMessage` | `string` | `"Please flip the check and capture the back side"` |
|
|
295
297
|
| `checkOptionalModalMessage` | `string` | `"Do you want to capture the back side of the check?"` |
|
|
296
298
|
| `wrongSideFrontMessage` | `string` | `"This looks like the back of the check..."` |
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { LIQUID_GLASS } from './liquid-glass.js';
|
|
2
|
+
|
|
3
|
+
const STYLE_ID = 'veryfi-camera-permission-message-styles';
|
|
4
|
+
const BODY_CLASS = 'veryfi-camera-permission-denied';
|
|
5
|
+
const PANEL_ID = 'veryfi-camera-permission-message';
|
|
6
|
+
const BLOCKED_CONTROL_IDS = [
|
|
7
|
+
'veryfi-capture-button',
|
|
8
|
+
'veryfi-stitching-button',
|
|
9
|
+
'veryfi-torch-button',
|
|
10
|
+
'veryfi-switch-camera-button',
|
|
11
|
+
'veryfi-mirror-button',
|
|
12
|
+
'veryfi-prescription-overlay-toggle',
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
const ensureStyles = () => {
|
|
16
|
+
if (document.getElementById(STYLE_ID)) return;
|
|
17
|
+
const style = document.createElement('style');
|
|
18
|
+
style.id = STYLE_ID;
|
|
19
|
+
const selector = BLOCKED_CONTROL_IDS.map((id) => `body.${BODY_CLASS} #${id}`).join(',\n');
|
|
20
|
+
style.textContent = `${selector} {\n display: none !important;\n}`;
|
|
21
|
+
document.head.appendChild(style);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const suppressOnCameraControls = () => {
|
|
25
|
+
ensureStyles();
|
|
26
|
+
document.body.classList.add(BODY_CLASS);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const restoreOnCameraControls = () => {
|
|
30
|
+
document.body.classList.remove(BODY_CLASS);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const createCameraPermissionMessage = (container, options = {}) => {
|
|
34
|
+
const panel = document.createElement('div');
|
|
35
|
+
panel.id = PANEL_ID;
|
|
36
|
+
panel.setAttribute('role', 'alert');
|
|
37
|
+
panel.textContent = options.message || '';
|
|
38
|
+
|
|
39
|
+
Object.assign(panel.style, {
|
|
40
|
+
position: 'absolute',
|
|
41
|
+
top: '50%',
|
|
42
|
+
left: '50%',
|
|
43
|
+
transform: 'translate(-50%, -50%)',
|
|
44
|
+
width: '300px',
|
|
45
|
+
maxWidth: 'calc(100vw - 48px)',
|
|
46
|
+
padding: '22px 24px',
|
|
47
|
+
boxSizing: 'border-box',
|
|
48
|
+
backgroundColor: LIQUID_GLASS.panelBackground,
|
|
49
|
+
backdropFilter: LIQUID_GLASS.blur,
|
|
50
|
+
WebkitBackdropFilter: LIQUID_GLASS.blur,
|
|
51
|
+
border: LIQUID_GLASS.border,
|
|
52
|
+
boxShadow: LIQUID_GLASS.panelBoxShadow,
|
|
53
|
+
color: LIQUID_GLASS.panelText,
|
|
54
|
+
borderRadius: '20px',
|
|
55
|
+
fontFamily: "system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif",
|
|
56
|
+
fontSize: '15px',
|
|
57
|
+
lineHeight: '1.45',
|
|
58
|
+
textAlign: 'center',
|
|
59
|
+
whiteSpace: 'pre-line',
|
|
60
|
+
zIndex: '1006',
|
|
61
|
+
pointerEvents: 'auto',
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
container.appendChild(panel);
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
element: panel,
|
|
68
|
+
show: () => { panel.style.display = 'block'; },
|
|
69
|
+
hide: () => { panel.style.display = 'none'; },
|
|
70
|
+
remove: () => {
|
|
71
|
+
if (panel.parentNode) {
|
|
72
|
+
panel.parentNode.removeChild(panel);
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
};
|
package/core/camera.js
CHANGED
|
@@ -1,4 +1,33 @@
|
|
|
1
1
|
import { state, refs, actions } from './state.js';
|
|
2
|
+
import {
|
|
3
|
+
createCameraPermissionMessage,
|
|
4
|
+
suppressOnCameraControls,
|
|
5
|
+
restoreOnCameraControls,
|
|
6
|
+
} from '../components/cameraPermissionMessage.js';
|
|
7
|
+
|
|
8
|
+
// Browsers report a rejected camera prompt (or a blocked site permission) with
|
|
9
|
+
// these DOMException names.
|
|
10
|
+
const PERMISSION_ERROR_NAMES = ['NotAllowedError', 'PermissionDeniedError', 'SecurityError'];
|
|
11
|
+
|
|
12
|
+
const handleCameraPermissionDenied = () => {
|
|
13
|
+
suppressOnCameraControls();
|
|
14
|
+
if (!state.showCameraPermissionDeniedMessage || !state.container) return;
|
|
15
|
+
if (state.cameraPermissionMessage) {
|
|
16
|
+
state.cameraPermissionMessage.show();
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
state.cameraPermissionMessage = createCameraPermissionMessage(state.container, {
|
|
20
|
+
message: state.cameraPermissionDeniedMessage,
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const clearCameraPermissionDenied = () => {
|
|
25
|
+
restoreOnCameraControls();
|
|
26
|
+
if (state.cameraPermissionMessage) {
|
|
27
|
+
state.cameraPermissionMessage.remove();
|
|
28
|
+
state.cameraPermissionMessage = null;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
2
31
|
|
|
3
32
|
export const displayVideo = () => {
|
|
4
33
|
const video = state.videoRef;
|
|
@@ -55,6 +84,10 @@ export const getVideo = async (lensFlavor) => {
|
|
|
55
84
|
const stream = await navigator.mediaDevices.getUserMedia(constraints);
|
|
56
85
|
state.updateHandler?.({ status: 'camera_ready' });
|
|
57
86
|
|
|
87
|
+
// A previously denied prompt can be granted on a later attempt — drop the
|
|
88
|
+
// message so the controls come back.
|
|
89
|
+
clearCameraPermissionDenied();
|
|
90
|
+
|
|
58
91
|
if (!state.videoRef) {
|
|
59
92
|
state.videoRef = document.getElementById("veryfi-video-ref");
|
|
60
93
|
}
|
|
@@ -107,9 +140,23 @@ export const getVideo = async (lensFlavor) => {
|
|
|
107
140
|
refs.wasmWrapper.setDocumentCallback(actions.logDocument);
|
|
108
141
|
}
|
|
109
142
|
} catch (err) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
143
|
+
if (PERMISSION_ERROR_NAMES.includes(err?.name)) {
|
|
144
|
+
// A denied prompt is a user decision, not an SDK failure, so it never goes
|
|
145
|
+
// to failureHandler — partners would render a second, duplicate error
|
|
146
|
+
// dialog on top. `message` carries the configured copy so hosts that turn
|
|
147
|
+
// off the in-lens panel can render it on their own error screen.
|
|
148
|
+
state.updateHandler?.({
|
|
149
|
+
status: 'camera_permission_denied',
|
|
150
|
+
message: state.cameraPermissionDeniedMessage,
|
|
151
|
+
error: err.message,
|
|
152
|
+
});
|
|
153
|
+
console.warn("Camera access denied:", err.message);
|
|
154
|
+
handleCameraPermissionDenied();
|
|
155
|
+
} else {
|
|
156
|
+
state.updateHandler?.({ status: 'camera_failed', error: err.message });
|
|
157
|
+
console.error("Error accessing camera:", err);
|
|
158
|
+
state.failureHandler?.(err);
|
|
159
|
+
}
|
|
113
160
|
}
|
|
114
161
|
};
|
|
115
162
|
|
package/core/constants.js
CHANGED
|
@@ -39,7 +39,7 @@ export const setApiBaseUrl = (base) => {
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
export const DEFAULTS = {
|
|
42
|
-
SDK_VERSION: '3.5.
|
|
42
|
+
SDK_VERSION: '3.5.4',
|
|
43
43
|
BLUR_THRESHOLD: 0.7,
|
|
44
44
|
LCD_THRESHOLD: 0.5,
|
|
45
45
|
BOX_COLOR: 'rgba(84, 192, 139, 0.6)',
|
|
@@ -121,6 +121,7 @@ export const MESSAGES = {
|
|
|
121
121
|
BATCH_FINISH_FAILED: 'Failed to submit the batch. Would you like to try again?',
|
|
122
122
|
BATCH_FINISH_RETRY: 'Retry',
|
|
123
123
|
BATCH_FINISH_CANCEL: 'Close without notifying',
|
|
124
|
+
CAMERA_PERMISSION_DENIED: 'Camera access was blocked. Please allow camera access in your browser settings and try again.',
|
|
124
125
|
AUTH_FAILED: 'Authorization failed, please provide correct client-id or contact customer support at support@veryfi.com',
|
|
125
126
|
AUTH_FAILED_CONTACT: 'Authorization failed, please contact customer support at support@veryfi.com',
|
|
126
127
|
};
|
package/core/lifecycle.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { state, refs, resetState, actions } from './state.js';
|
|
2
|
-
import { getVideo, displayVideo } from './camera.js';
|
|
2
|
+
import { getVideo, displayVideo, clearCameraPermissionDenied } from './camera.js';
|
|
3
3
|
import { initializeWasmWrapper, sendWasm, sendCardWasm, getLongImage, logDocument, stopWasm, resetAutoCaptureCounters, resetFieldDetectorBootstrap } from './wasm-processing.js';
|
|
4
4
|
import { hideVideoOverlay, showVideoOverlay } from './overlay-controls.js';
|
|
5
5
|
import { docReady, handleSubmit, fireResultSetter } from './api.js';
|
|
@@ -285,6 +285,10 @@ export const removeOverlay = () => {
|
|
|
285
285
|
state.reviewGalleryRef = null;
|
|
286
286
|
}
|
|
287
287
|
|
|
288
|
+
// Must run explicitly: clearing the container drops the panel but leaves the
|
|
289
|
+
// body class that suppresses the on-camera controls.
|
|
290
|
+
clearCameraPermissionDenied();
|
|
291
|
+
|
|
288
292
|
cleanupPrescriptionLabelRecording();
|
|
289
293
|
clearTheme();
|
|
290
294
|
|
package/core/state.js
CHANGED
|
@@ -91,6 +91,8 @@ export const state = {
|
|
|
91
91
|
isLcdModal: true,
|
|
92
92
|
container: null,
|
|
93
93
|
exitButton: false,
|
|
94
|
+
showCameraPermissionDeniedMessage: true,
|
|
95
|
+
cameraPermissionDeniedMessage: MESSAGES.CAMERA_PERMISSION_DENIED,
|
|
94
96
|
onCloseRedirectUrl: null,
|
|
95
97
|
onClose: null,
|
|
96
98
|
resultSetter: null,
|
|
@@ -205,6 +207,7 @@ export const state = {
|
|
|
205
207
|
submitButton: null,
|
|
206
208
|
videoOverlay: null,
|
|
207
209
|
captureButton: null,
|
|
210
|
+
cameraPermissionMessage: null,
|
|
208
211
|
exitButtonRef: null,
|
|
209
212
|
longPreview: null,
|
|
210
213
|
cardOverlay: null,
|
|
@@ -370,6 +373,7 @@ export const resetState = () => {
|
|
|
370
373
|
state.isMirrored = false;
|
|
371
374
|
state.cameraFacingMode = 'environment';
|
|
372
375
|
state.captureButton = null;
|
|
376
|
+
state.cameraPermissionMessage = null;
|
|
373
377
|
state.submitButton = null;
|
|
374
378
|
state.exitButtonRef = null;
|
|
375
379
|
state.longPreview = null;
|
package/package.json
CHANGED