biometry-react-components 1.0.0 → 1.1.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # biometry-react-components
2
2
 
3
- React UI components for capturing high-quality biometric data (face, documents) to facilitate integration with Biometry services.
3
+ React UI component library with tools to work with camera and microphone for easier integration of Biometry services. This library could be used in combination with [Biometry SDK](https://www.npmjs.com/package/biometry-sdk)
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,11 +8,24 @@ React UI components for capturing high-quality biometric data (face, documents)
8
8
  npm install biometry-react-components
9
9
  ```
10
10
 
11
+ ### Peer Dependencies
12
+
13
+ This library requires React 16.8.0 or higher (supports React Hooks):
14
+
15
+ ```json
16
+ {
17
+ "peerDependencies": {
18
+ "react": ">=16.8.0",
19
+ "react-dom": ">=16.8.0"
20
+ }
21
+ }
22
+ ```
23
+
11
24
  ## Components
12
25
 
13
26
  ### DocScan
14
27
 
15
- Captures document images with a rectangular guidance overlay.
28
+ Captures ID documents, driver license and etc. Suitable component for Biometry's [DocAuth](https://developer.biometrysolutions.com/api/doc-auth/).
16
29
 
17
30
  ```tsx
18
31
  import { DocScan } from 'biometry-react-components';
@@ -20,6 +33,9 @@ import { DocScan } from 'biometry-react-components';
20
33
  function DocumentCapture() {
21
34
  const handleCapture = (file: File) => {
22
35
  console.log('Captured document:', file);
36
+ // Send file to your endpoint that will process DocAuth (we recommend this way, because you will not expose the API key on client side)
37
+ // or
38
+ // const response = await sdk.checkDocAuth(file, userFullName, { sessionId });
23
39
  };
24
40
 
25
41
  return <DocScan onCapture={handleCapture} />;
@@ -39,7 +55,7 @@ function DocumentCapture() {
39
55
 
40
56
  ### FaceCapture
41
57
 
42
- Captures facial images with an oval guidance overlay.
58
+ Captures facial images with an oval guidance overlay. Ideal for [Face Match](https://developer.biometrysolutions.com/api/facematch/) and [Face Enrollment](https://developer.biometrysolutions.com/api/face-enrollment/).
43
59
 
44
60
  ```tsx
45
61
  import { FaceCapture } from 'biometry-react-components';
@@ -47,6 +63,9 @@ import { FaceCapture } from 'biometry-react-components';
47
63
  function FaceCapture() {
48
64
  const handleCapture = (file: File) => {
49
65
  console.log('Captured face:', file);
66
+ // Send file to your endpoint that will process DocAuth (we recommend this way, because you will not expose the API key on client side)
67
+ // or
68
+ // const response = await sdk.enrollFace(file, 'John Doe');
50
69
  };
51
70
 
52
71
  return <FaceCapture onCapture={handleCapture} />;
@@ -64,6 +83,192 @@ function FaceCapture() {
64
83
  | `style` | `React.CSSProperties` | - | Custom inline styles |
65
84
  | `noShadow` | `boolean` | `false` | Remove shadow and border radius |
66
85
 
86
+ ### FaceRecorder
87
+
88
+ Records video with facial guidance overlay. This component could be used for [Process Video](https://developer.biometrysolutions.com/api/process-video/)
89
+
90
+ ```tsx
91
+ import { FaceRecorder } from 'biometry-react-components';
92
+
93
+ function FaceRecorder() {
94
+ const handleCapture = (file: File, phrase: string) => {
95
+ console.log('Captured video:', file);
96
+ console.log('Phrase:', phrase);
97
+ // Send file to your endpoint that will process DocAuth (we recommend this way, because you will not expose the API key on client side)
98
+ // or
99
+ // const response = await sdk.processVideo(file, phrase, userFullName);
100
+ };
101
+
102
+ return <FaceRecorder onCapture={handleCapture} />;
103
+ }
104
+ ```
105
+
106
+ #### Props
107
+
108
+ | Prop | Type | Default | Description |
109
+ |------|------|---------|-------------|
110
+ | `onCapture` | `(file: File) => void` | **required** | Callback with captured video file |
111
+ | `rectWidth` | `number` | `360` | Width of camera area |
112
+ | `rectHeight` | `number` | `576` | Height of camera area |
113
+ | `className` | `string` | - | Custom CSS class |
114
+ | `style` | `React.CSSProperties` | - | Custom inline styles |
115
+ | `noShadow` | `boolean` | `false` | Remove shadow and border radius |
116
+
117
+ ### VoiceRecorder
118
+
119
+ Records audio with real-time waveform visualization and adaptive quality settings. Use this for [Voice Enrollment](https://developer.biometrysolutions.com/api/voice-enrollment/)
120
+
121
+ ```tsx
122
+ import { VoiceRecorder } from 'biometry-react-components';
123
+
124
+ function VoiceRecorder() {
125
+ const handleCapture = (file: File, phrase: string) => {
126
+ console.log('Captured audio:', file);
127
+ console.log('Phrase:', phrase);
128
+ // Send file to your endpoint that will process DocAuth (we recommend this way, because you will not expose the API key on client side)
129
+ // or
130
+ // const response = await sdk.enrollVoice(file, 'John Doe');
131
+ };
132
+
133
+ return <VoiceRecorder onCapture={handleCapture} />;
134
+ }
135
+ ```
136
+
137
+ #### Props
138
+
139
+ | Prop | Type | Default | Description |
140
+ |------|------|---------|-------------|
141
+ | `onCapture` | `(file: File) => void` | **required** | Callback with captured audio file |
142
+ | `rectWidth` | `number` | `360` | Width of component area |
143
+ | `rectHeight` | `number` | `undefined` | Height of component area (optional) |
144
+ | `className` | `string` | - | Custom CSS class |
145
+ | `style` | `React.CSSProperties` | - | Custom inline styles |
146
+ | `noShadow` | `boolean` | `false` | Remove shadow and border radius |
147
+
148
+
149
+ ## Custom Hooks
150
+
151
+ ### useRecorder
152
+
153
+ A powerful hook for recording audio and video with adaptive quality settings and automatic format detection.
154
+
155
+ ```tsx
156
+ import { useRecorder } from 'biometry-react-components';
157
+
158
+ function CustomRecorder() {
159
+ const mediaStream = // ... your media stream
160
+
161
+ const {
162
+ isRecording,
163
+ startRecording,
164
+ stopRecording,
165
+ cancelRecording
166
+ } = useRecorder(mediaStream, "video", (blob) => {
167
+ console.log('Recording completed:', blob);
168
+ });
169
+
170
+ return (
171
+ ...
172
+ );
173
+ }
174
+ ```
175
+
176
+ #### Parameters
177
+
178
+ | Parameter | Type | Description |
179
+ |-----------|------|-------------|
180
+ | `stream` | `MediaStream \| null` | Media stream to record from |
181
+ | `type` | `"audio" \| "video"` | Type of media to record |
182
+ | `onStopRecording` | `(blob: Blob) => void` | Callback when recording stops |
183
+
184
+ #### Returns
185
+
186
+ | Property | Type | Description |
187
+ |----------|------|-------------|
188
+ | `isRecording` | `boolean` | Current recording state |
189
+ | `startRecording` | `() => void` | Start recording function |
190
+ | `stopRecording` | `() => void` | Stop recording function |
191
+ | `cancelRecording` | `() => void` | Cancel recording function |
192
+
193
+ ### usePermissions
194
+
195
+ Hook for managing camera and microphone permissions with adaptive quality constraints.
196
+
197
+ ```tsx
198
+ import usePermissions from 'biometry-react-components';
199
+
200
+ function PermissionManager() {
201
+ const {
202
+ permission,
203
+ stream,
204
+ stopStreamTracks,
205
+ requestPermissions,
206
+ isLoading
207
+ } = usePermissions({ rectWidth: 1280, rectHeight: 720 });
208
+
209
+ if (isLoading) return <div>Loading...</div>;
210
+
211
+ if (!permission) {
212
+ return <button onClick={requestPermissions}>Grant Permissions</button>;
213
+ }
214
+
215
+ return <div>Camera and microphone access granted!</div>;
216
+ }
217
+ ```
218
+
219
+ #### Parameters
220
+
221
+ | Parameter | Type | Default | Description |
222
+ |-----------|------|---------|-------------|
223
+ | `rectWidth` | `number` | `1920` | Desired video width |
224
+ | `rectHeight` | `number` | `1080` | Desired video height |
225
+
226
+ #### Returns
227
+
228
+ | Property | Type | Description |
229
+ |----------|------|-------------|
230
+ | `permission` | `boolean` | Permission granted status |
231
+ | `stream` | `MediaStream \| null` | Active media stream |
232
+ | `stopStreamTracks` | `() => void` | Stop all media tracks |
233
+ | `requestPermissions` | `() => Promise<void>` | Request camera/microphone permissions |
234
+ | `isLoading` | `boolean` | Loading state during permission request |
235
+
236
+ ### useAudioPermissions
237
+
238
+ Specialized hook for audio-only permissions with optimized audio constraints.
239
+
240
+ ```tsx
241
+ import useAudioPermissions from 'biometry-react-components';
242
+
243
+ function AudioPermissionManager() {
244
+ const {
245
+ permission,
246
+ stream,
247
+ stopStreamTracks,
248
+ requestPermissions,
249
+ isLoading
250
+ } = useAudioPermissions();
251
+
252
+ if (isLoading) return <div>Loading...</div>;
253
+
254
+ if (!permission) {
255
+ return <button onClick={requestPermissions}>Grant Microphone Access</button>;
256
+ }
257
+
258
+ return <div>Microphone access granted!</div>;
259
+ }
260
+ ```
261
+
262
+ #### Returns
263
+
264
+ | Property | Type | Description |
265
+ |----------|------|-------------|
266
+ | `permission` | `boolean` | Audio permission granted status |
267
+ | `stream` | `MediaStream \| null` | Active audio stream |
268
+ | `stopStreamTracks` | `() => void` | Stop all audio tracks |
269
+ | `requestPermissions` | `() => Promise<void>` | Request microphone permissions |
270
+ | `isLoading` | `boolean` | Loading state during permission request |
271
+
67
272
  ## License
68
273
 
69
- MIT
274
+ MIT License - see the [LICENSE](LICENSE) file for details.
package/dist/index.d.ts CHANGED
@@ -20,4 +20,52 @@ interface FaceCaptureProps {
20
20
  }
21
21
  declare const FaceCapture: React.FC<FaceCaptureProps>;
22
22
 
23
- export { DocScan, FaceCapture };
23
+ interface FaceRecorderProps {
24
+ rectWidth?: number;
25
+ rectHeight?: number;
26
+ onCapture: (file: File, phrase: string) => void;
27
+ className?: string;
28
+ style?: React.CSSProperties;
29
+ noShadow?: boolean;
30
+ }
31
+ declare const FaceRecorder: React.FC<FaceRecorderProps>;
32
+
33
+ interface VoiceRecorderProps {
34
+ rectWidth?: number;
35
+ rectHeight?: number | undefined;
36
+ onCapture: (file: File, phrase: string) => void;
37
+ className?: string;
38
+ style?: React.CSSProperties;
39
+ noShadow?: boolean;
40
+ }
41
+ declare const VoiceRecorder: React.FC<VoiceRecorderProps>;
42
+
43
+ type OnStopRecordingFunc = (blob: Blob) => void;
44
+ declare const useRecorder: (stream: MediaStream | null, type: "audio" | "video", onStopRecording: OnStopRecordingFunc) => {
45
+ isRecording: boolean;
46
+ startRecording: () => void;
47
+ stopRecording: () => void;
48
+ cancelRecording: () => void;
49
+ };
50
+
51
+ interface UsePermissionsProps {
52
+ rectWidth?: number;
53
+ rectHeight?: number;
54
+ }
55
+ declare const usePermissions: ({ rectWidth, rectHeight }?: UsePermissionsProps) => {
56
+ permission: boolean;
57
+ stream: MediaStream | null;
58
+ stopStreamTracks: () => void;
59
+ requestPermissions: () => Promise<void>;
60
+ isLoading: boolean;
61
+ };
62
+
63
+ declare const useAudioPermissions: () => {
64
+ permission: boolean;
65
+ stream: MediaStream | null;
66
+ stopStreamTracks: () => void;
67
+ requestPermissions: () => Promise<void>;
68
+ isLoading: boolean;
69
+ };
70
+
71
+ export { DocScan, FaceCapture, FaceRecorder, VoiceRecorder, useAudioPermissions, usePermissions, useRecorder };