@meeeetup/camera-web 0.8.0 → 0.10.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 +233 -167
- package/dist/camera-loop.d.ts +3 -0
- package/dist/camera-loop.d.ts.map +1 -1
- package/dist/camera-loop.js +27 -6
- package/dist/camera-loop.js.map +1 -1
- package/dist/detectors/mediapipe-detector.d.ts +1 -1
- package/dist/detectors/mediapipe-detector.js +2 -2
- package/dist/detectors/tensorflow-detector.js +2 -2
- package/dist/detectors/tensorflow-detector.js.map +1 -1
- package/dist/frame-buffer.d.ts +2 -0
- package/dist/frame-buffer.d.ts.map +1 -1
- package/dist/frame-buffer.js +2 -0
- package/dist/frame-buffer.js.map +1 -1
- package/dist/index.d.ts +9 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -17
- package/dist/index.js.map +1 -1
- package/dist/react/components/AlignmentRing.js +2 -2
- package/dist/react/components/AlignmentRing.js.map +1 -1
- package/dist/react/components/CameraToggle.js +2 -2
- package/dist/react/components/CameraToggle.js.map +1 -1
- package/dist/react/components/CameraViewport.d.ts +4 -2
- package/dist/react/components/CameraViewport.d.ts.map +1 -1
- package/dist/react/components/CameraViewport.js +12 -10
- package/dist/react/components/CameraViewport.js.map +1 -1
- package/dist/react/components/CaptureButton.js +2 -2
- package/dist/react/components/CaptureButton.js.map +1 -1
- package/dist/react/components/DevicePicker.js +2 -2
- package/dist/react/components/DevicePicker.js.map +1 -1
- package/dist/react/components/FaceCounter.js +2 -2
- package/dist/react/components/FaceCounter.js.map +1 -1
- package/dist/react/components/FaceGrid.d.ts.map +1 -1
- package/dist/react/components/FaceGrid.js +23 -11
- package/dist/react/components/FaceGrid.js.map +1 -1
- package/dist/react/components/SingleAlignmentOverlay.js +2 -2
- package/dist/react/components/SingleAlignmentOverlay.js.map +1 -1
- package/dist/react/context/{MeeeetUpCamContext.d.ts → CameraContext.d.ts} +31 -6
- package/dist/react/context/CameraContext.d.ts.map +1 -0
- package/dist/react/context/CameraContext.js +3 -0
- package/dist/react/context/CameraContext.js.map +1 -0
- package/dist/react/context/CameraProvider.d.ts +105 -0
- package/dist/react/context/CameraProvider.d.ts.map +1 -0
- package/dist/react/context/{MeeeetUpCamProvider.js → CameraProvider.js} +39 -62
- package/dist/react/context/CameraProvider.js.map +1 -0
- package/dist/react/context/useCamera.d.ts +15 -0
- package/dist/react/context/useCamera.d.ts.map +1 -0
- package/dist/react/context/useCamera.js +22 -0
- package/dist/react/context/useCamera.js.map +1 -0
- package/dist/react/usePassiveCamera.d.ts +21 -1
- package/dist/react/usePassiveCamera.d.ts.map +1 -1
- package/dist/react/usePassiveCamera.js +35 -2
- package/dist/react/usePassiveCamera.js.map +1 -1
- package/dist/react/useSingleCapture.d.ts +22 -1
- package/dist/react/useSingleCapture.d.ts.map +1 -1
- package/dist/react/useSingleCapture.js +35 -4
- package/dist/react/useSingleCapture.js.map +1 -1
- package/dist/ui/index.d.ts +19 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +18 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/utils/feature-visibility.d.ts +70 -0
- package/dist/utils/feature-visibility.d.ts.map +1 -0
- package/dist/utils/feature-visibility.js +192 -0
- package/dist/utils/feature-visibility.js.map +1 -0
- package/package.json +7 -2
- package/dist/react/context/MeeeetUpCamContext.d.ts.map +0 -1
- package/dist/react/context/MeeeetUpCamContext.js +0 -3
- package/dist/react/context/MeeeetUpCamContext.js.map +0 -1
- package/dist/react/context/MeeeetUpCamProvider.d.ts +0 -87
- package/dist/react/context/MeeeetUpCamProvider.d.ts.map +0 -1
- package/dist/react/context/MeeeetUpCamProvider.js.map +0 -1
- package/dist/react/context/useMeeeetUpCam.d.ts +0 -15
- package/dist/react/context/useMeeeetUpCam.d.ts.map +0 -1
- package/dist/react/context/useMeeeetUpCam.js +0 -22
- package/dist/react/context/useMeeeetUpCam.js.map +0 -1
- package/dist/react/useAutoUpload.d.ts +0 -17
- package/dist/react/useAutoUpload.d.ts.map +0 -1
- package/dist/react/useAutoUpload.js +0 -46
- package/dist/react/useAutoUpload.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,91 +1,120 @@
|
|
|
1
1
|
# @meeeetup/camera-web
|
|
2
2
|
|
|
3
|
-
Browser face-capture SDK
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
Browser face-capture SDK. Detects faces with MediaPipe BlazeFace, tracks each
|
|
4
|
+
one, picks the best-quality frame per person, and hands you the images through
|
|
5
|
+
a callback. **No network, no credentials, no vendor lock-in** — the SDK runs
|
|
6
|
+
entirely on the device and the transport is yours.
|
|
7
|
+
|
|
8
|
+
- **Headless-first.** The data surface (`CameraProvider`, `useCamera`) is the
|
|
9
|
+
package default. Pre-built UI (viewport, overlay, face grid) is a separate
|
|
10
|
+
entry under `/ui` — import it only if you want the stock visuals.
|
|
11
|
+
- **BYOT (bring your own transport).** The SDK calls `onBatchCapture` (passive)
|
|
12
|
+
or `onCapture` (single, interactive) with base64 JPEG data URLs. Sending
|
|
13
|
+
them is your code — any backend, any auth scheme, any retry strategy.
|
|
14
|
+
- **Pre-GA.** Breaking API changes land without deprecation shims; version
|
|
15
|
+
bumps document them in `CHANGELOG.md`.
|
|
12
16
|
|
|
13
17
|
Requires React 18 or 19. ESM-only. Served over HTTPS or `localhost` —
|
|
14
18
|
`getUserMedia` is a secure-context API.
|
|
15
19
|
|
|
20
|
+
---
|
|
21
|
+
|
|
16
22
|
## Install
|
|
17
23
|
|
|
18
24
|
```bash
|
|
19
25
|
npm i @meeeetup/camera-web react react-dom
|
|
20
26
|
```
|
|
21
27
|
|
|
22
|
-
|
|
23
|
-
import from it directly (this package already re-exports `SelectedFace`,
|
|
24
|
-
`LiveFacePreview` and `PersonResult`).
|
|
28
|
+
Optional (only if you use the stock components):
|
|
25
29
|
|
|
26
30
|
```ts
|
|
27
31
|
import "@meeeetup/camera-web/styles.css";
|
|
28
32
|
```
|
|
29
33
|
|
|
30
|
-
|
|
34
|
+
`@meeeetup/camera-core` arrives as a transitive dependency — add it explicitly
|
|
35
|
+
only if you import from it directly (`SelectedFace`, `LiveFacePreview`,
|
|
36
|
+
`PersonResult`, `TrackSnapshot` are already re-exported here).
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## The two entry points
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
// Headless API — Provider, hook, types. ~zero visual bytes.
|
|
44
|
+
import { CameraProvider, useCamera } from "@meeeetup/camera-web";
|
|
45
|
+
|
|
46
|
+
// Pre-built components — only if you want our visuals. Opt-in bundle cost.
|
|
47
|
+
import { CameraViewport, FaceGrid, FaceCounter } from "@meeeetup/camera-web/ui";
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Everything renders inside a single `<CameraProvider>`. Children — stock
|
|
51
|
+
components or your own — read live state through `useCamera()`.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Three capture modes
|
|
56
|
+
|
|
57
|
+
| Dimension | `passive` | `interactive` | `single` |
|
|
58
|
+
|---|---|---|---|
|
|
59
|
+
| Who triggers capture? | SDK (auto) | User (button) | SDK (best-shot window) |
|
|
60
|
+
| Faces tracked | Multi | Single | Single |
|
|
61
|
+
| Upload timing | Batch (10s) | Per shutter | Per completion |
|
|
62
|
+
| UX overlay | Canvas tracks | Alignment ring | Alignment + progress |
|
|
63
|
+
| Retake? | N/A (continuous) | Re-press button | `rearm()` |
|
|
64
|
+
| Quality gate | `minFrontalness` default 50 | Minimal (user decides) | Strict (`minFrontalness` default 10 + pose penalty) |
|
|
65
|
+
| Example | Surveillance, attendance | Kiosk check-in | Registration |
|
|
31
66
|
|
|
32
|
-
|
|
33
|
-
SDK's own uploader if you set `autoUpload`.
|
|
67
|
+
### Passive — continuous, batched
|
|
34
68
|
|
|
35
69
|
```tsx
|
|
36
|
-
import {
|
|
37
|
-
|
|
38
|
-
CameraViewport,
|
|
39
|
-
FaceCounter,
|
|
40
|
-
FaceGrid,
|
|
41
|
-
type SelectedFace,
|
|
42
|
-
} from "@meeeetup/camera-web";
|
|
70
|
+
import { CameraProvider, useCamera, type SelectedFace } from "@meeeetup/camera-web";
|
|
71
|
+
import { CameraViewport, FaceCounter, FaceGrid } from "@meeeetup/camera-web/ui";
|
|
43
72
|
|
|
44
73
|
export function PassiveCamera({ captureKey }: { captureKey: string }) {
|
|
74
|
+
const handleBatch = async (faces: SelectedFace[]) => {
|
|
75
|
+
const res = await fetch("https://api.example.com/capture", {
|
|
76
|
+
method: "POST",
|
|
77
|
+
headers: {
|
|
78
|
+
Authorization: `Bearer ${captureKey}`,
|
|
79
|
+
"Content-Type": "application/json",
|
|
80
|
+
},
|
|
81
|
+
body: JSON.stringify({
|
|
82
|
+
images: faces.map((f) => ({
|
|
83
|
+
image: f.dataUrl,
|
|
84
|
+
capturedAt: new Date(f.createdAt).toISOString(),
|
|
85
|
+
})),
|
|
86
|
+
}),
|
|
87
|
+
});
|
|
88
|
+
// Throw to report failure. The SDK re-queues on throw; a 4xx would
|
|
89
|
+
// livelock a retry, so swallow those at the sink.
|
|
90
|
+
if (!res.ok && res.status >= 500) throw new Error(`send failed: ${res.status}`);
|
|
91
|
+
};
|
|
92
|
+
|
|
45
93
|
return (
|
|
46
|
-
<
|
|
47
|
-
mode="passive"
|
|
48
|
-
onBatchCapture={async (faces: SelectedFace[]) => {
|
|
49
|
-
const res = await fetch("https://api.example.com/capture", {
|
|
50
|
-
method: "POST",
|
|
51
|
-
headers: {
|
|
52
|
-
Authorization: `Bearer ${captureKey}`,
|
|
53
|
-
"Content-Type": "application/json",
|
|
54
|
-
},
|
|
55
|
-
body: JSON.stringify({
|
|
56
|
-
images: faces.map((f) => ({
|
|
57
|
-
image: f.dataUrl,
|
|
58
|
-
capturedAt: new Date(f.createdAt).toISOString(),
|
|
59
|
-
})),
|
|
60
|
-
}),
|
|
61
|
-
});
|
|
62
|
-
// Throw to report failure. A missing status, <400 or >=500 is retried;
|
|
63
|
-
// 4xx drops that batch (resending an unchanged rejected payload
|
|
64
|
-
// livelocks).
|
|
65
|
-
if (!res.ok) throw Object.assign(new Error("send failed"), { status: res.status });
|
|
66
|
-
}}
|
|
67
|
-
>
|
|
94
|
+
<CameraProvider mode="passive" onBatchCapture={handleBatch}>
|
|
68
95
|
<CameraViewport />
|
|
69
96
|
<FaceCounter />
|
|
70
97
|
<FaceGrid />
|
|
71
|
-
</
|
|
98
|
+
</CameraProvider>
|
|
72
99
|
);
|
|
73
100
|
}
|
|
74
101
|
```
|
|
75
102
|
|
|
76
|
-
|
|
103
|
+
Faces flush every 10 s or when the buffer reaches the key's
|
|
104
|
+
`maxFacesPerRequest` cap. A face is handed over once per selection event — if a
|
|
105
|
+
better frame arrives later the SDK commits again. On the default settle path
|
|
106
|
+
every selection is `final: true`; set `captureWindowMs` and tracks publish
|
|
107
|
+
with `final: false` intermediate updates until the window expires.
|
|
108
|
+
|
|
109
|
+
### Interactive — user-triggered
|
|
77
110
|
|
|
78
111
|
```tsx
|
|
79
|
-
import {
|
|
80
|
-
|
|
81
|
-
CameraViewport,
|
|
82
|
-
AlignmentRing,
|
|
83
|
-
CaptureButton,
|
|
84
|
-
} from "@meeeetup/camera-web";
|
|
112
|
+
import { CameraProvider } from "@meeeetup/camera-web";
|
|
113
|
+
import { CameraViewport, AlignmentRing, CaptureButton } from "@meeeetup/camera-web/ui";
|
|
85
114
|
|
|
86
115
|
export function KioskCamera() {
|
|
87
116
|
return (
|
|
88
|
-
<
|
|
117
|
+
<CameraProvider
|
|
89
118
|
mode="interactive"
|
|
90
119
|
onCapture={async (faceImage, fullCircleImage) => {
|
|
91
120
|
await upload(faceImage, fullCircleImage);
|
|
@@ -94,163 +123,202 @@ export function KioskCamera() {
|
|
|
94
123
|
<CameraViewport />
|
|
95
124
|
<AlignmentRing />
|
|
96
125
|
<CaptureButton />
|
|
97
|
-
</
|
|
126
|
+
</CameraProvider>
|
|
98
127
|
);
|
|
99
128
|
}
|
|
100
129
|
```
|
|
101
130
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
`autoUpload` is accepted by `MeeeetUpCamProvider` in all three modes
|
|
105
|
-
(`passive`, `single`, `interactive`) and makes the SDK post captures itself.
|
|
106
|
-
Omit it and no capture ever leaves the device — your callback stays the only
|
|
107
|
-
output path. With it, a passive camera needs no transport code at all:
|
|
131
|
+
### Single — automatic one-shot
|
|
108
132
|
|
|
109
133
|
```tsx
|
|
110
|
-
import {
|
|
111
|
-
|
|
112
|
-
CameraViewport,
|
|
113
|
-
FaceCounter,
|
|
114
|
-
FaceGrid,
|
|
115
|
-
} from "@meeeetup/camera-web";
|
|
134
|
+
import { CameraProvider } from "@meeeetup/camera-web";
|
|
135
|
+
import { CameraViewport } from "@meeeetup/camera-web/ui";
|
|
116
136
|
|
|
117
|
-
export function
|
|
137
|
+
export function EnrollCamera() {
|
|
118
138
|
return (
|
|
119
|
-
<
|
|
139
|
+
<CameraProvider
|
|
140
|
+
mode="single"
|
|
141
|
+
onCapture={async (faceImage, _fullCircleImage, meta) => {
|
|
142
|
+
console.log("frontalness", meta.frontalness, "face size", meta.faceSize);
|
|
143
|
+
await upload(faceImage);
|
|
144
|
+
}}
|
|
145
|
+
>
|
|
120
146
|
<CameraViewport />
|
|
121
|
-
|
|
122
|
-
<FaceGrid />
|
|
123
|
-
</MeeeetUpCamProvider>
|
|
147
|
+
</CameraProvider>
|
|
124
148
|
);
|
|
125
149
|
}
|
|
126
150
|
```
|
|
127
151
|
|
|
128
|
-
|
|
129
|
-
`Authorization: Bearer <captureKey>` and `Content-Type: application/json`, and
|
|
130
|
-
a body of `{ images: [{ image, capturedAt }], channelId? }` — the `POST
|
|
131
|
-
/capture` contract of the Meeeetup face-ID API. `capturedAt` is each face's
|
|
132
|
-
`createdAt` as an ISO-8601 string.
|
|
152
|
+
---
|
|
133
153
|
|
|
134
|
-
|
|
154
|
+
## Custom UI (`useCamera`)
|
|
135
155
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
| `captureKey` | `string` | required — sent as `Authorization: Bearer <captureKey>` |
|
|
139
|
-
| `endpoint` | `string` | `DEFAULT_CAPTURE_ENDPOINT` (`https://api.meeeetup.com/capture`) |
|
|
140
|
-
| `channelId` | `string` | unset — omitted from the body entirely, not sent empty |
|
|
141
|
-
| `maxRetries` | `number` | `2` — extra attempts after a transient failure |
|
|
142
|
-
| `retryDelayMs` | `number` | `1000` — base backoff, doubled each attempt |
|
|
143
|
-
| `fetch` | `CaptureFetch` | the global `fetch` — override for tests or a proxy |
|
|
144
|
-
| `onUploaded` | `(result: AutoUploadResult) => void` | — fires per accepted request with `{ count, status, attempts }` |
|
|
145
|
-
| `onError` | `(error: unknown) => void` | — fires once per upload that exhausted its attempts |
|
|
146
|
-
|
|
147
|
-
### Capture callbacks become observers
|
|
148
|
-
|
|
149
|
-
With `autoUpload` set, `onBatchCapture` / `onCapture` are optional and purely
|
|
150
|
-
observational — a counter, a preview, analytics. They are fired without being
|
|
151
|
-
awaited, so they can neither delay nor fail the upload, and anything they throw
|
|
152
|
-
surfaces on `autoUpload.onError` rather than in the capture pipeline. Without
|
|
153
|
-
`autoUpload` they are the only output path and behave as before: a rejection
|
|
154
|
-
requeues the batch.
|
|
155
|
-
|
|
156
|
-
In single and interactive mode only the face crop is uploaded.
|
|
157
|
-
`fullCircleImage` is framing for your own UI and never leaves the device.
|
|
158
|
-
|
|
159
|
-
### Retries and failures
|
|
160
|
-
|
|
161
|
-
5xx, 429, 408 and transport-level failures are retried up to `maxRetries`, each
|
|
162
|
-
attempt resending a byte-identical payload after
|
|
163
|
-
`retryDelayMs * 2 ** (attempt - 1)` ms. Any other 4xx fails immediately — the
|
|
164
|
-
server rejected that payload, and resending it unchanged would livelock.
|
|
165
|
-
|
|
166
|
-
Once the attempts are spent the uploader throws `CaptureUploadError`:
|
|
167
|
-
|
|
168
|
-
| Field | Meaning |
|
|
169
|
-
|---|---|
|
|
170
|
-
| `status` | HTTP status; absent when the request never completed |
|
|
171
|
-
| `retryable` | `true` for 408 / 429 / 5xx / transport failure, `false` for any other 4xx |
|
|
172
|
-
| `attempts` | attempts spent before giving up |
|
|
173
|
-
| `cause` | the underlying transport error, when there was one |
|
|
174
|
-
|
|
175
|
-
The passive session reads that flag: a retryable batch is requeued and retried
|
|
176
|
-
on a later flush, a non-retryable one is dropped. Batches reach the uploader
|
|
177
|
-
already chunked to 50 images (`maxFacesPerRequest`), which must not exceed the
|
|
178
|
-
key's `maxImagesPerRequest` from `GET /capture/keys/me`.
|
|
179
|
-
|
|
180
|
-
### Driving the low-level hooks
|
|
181
|
-
|
|
182
|
-
`createAutoUploader`, `CaptureUploadError`, `DEFAULT_CAPTURE_ENDPOINT` and the
|
|
183
|
-
`AutoUpload*` / `Capture*` types are re-exported from this package, so code
|
|
184
|
-
driving the low-level hooks (`usePassiveCamera`, `useSingleCapture`) instead of
|
|
185
|
-
the provider gets the same transport. `uploadFaces` takes `SelectedFace[]` from
|
|
186
|
-
a passive batch; `uploadImages` takes the single-shot data URLs.
|
|
156
|
+
`useCamera()` is the data surface. Narrow on `cam.mode` first; the hook throws
|
|
157
|
+
if used outside a provider.
|
|
187
158
|
|
|
188
159
|
```tsx
|
|
189
|
-
import {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
const cam =
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
160
|
+
import { useCamera } from "@meeeetup/camera-web";
|
|
161
|
+
|
|
162
|
+
function Status() {
|
|
163
|
+
const cam = useCamera();
|
|
164
|
+
if (cam.mode !== "passive") return null;
|
|
165
|
+
return (
|
|
166
|
+
<p>
|
|
167
|
+
{cam.trackedCount} in frame — {cam.capturedFaces.length} captured
|
|
168
|
+
</p>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
198
171
|
```
|
|
199
172
|
|
|
200
|
-
|
|
173
|
+
### Shared across modes
|
|
174
|
+
|
|
175
|
+
`ready`, `error`, `videoRef`, `devices`, `currentDeviceId`, `setDeviceId`,
|
|
176
|
+
`currentFacingMode`, `toggleCamera`.
|
|
177
|
+
|
|
178
|
+
### Passive mode (`cam.mode === "passive"`)
|
|
179
|
+
|
|
180
|
+
| Field | Shape | What it is |
|
|
181
|
+
|---|---|---|
|
|
182
|
+
| `activeTracks` | `TrackSnapshot[]` | Per-frame snapshot of every live track — `cx`/`cy`/`width`/`height` in normalised 0–1 coords, the latest six `keypoints`, plus `smoothedFrontalness` / `selectedFrontalness` / `lastSeenAt` / `lastSentAt`. Drive custom overlays off this |
|
|
183
|
+
| `liveFaces` | `LiveFacePreview[]` | Tracks currently in frame that have NOT yet been committed — your "watching" row |
|
|
184
|
+
| `capturedFaces` | `SelectedFace[]` | Everything committed this session, newest first — your "captured" row |
|
|
185
|
+
| `livePreviews` | `LiveFacePreview[]` | Raw: all tracked faces that have a best crop yet |
|
|
186
|
+
| `selectedFaces` | `SelectedFace[]` | Raw: SDK's committed buffer, order defined by the pipeline |
|
|
187
|
+
| `trackedCount` / `totalCount` | `number` | Faces in frame now / unique faces seen this session |
|
|
188
|
+
| `flushBatch` | `() => Promise<void>` | Drive the batch flush yourself instead of waiting 10 s |
|
|
189
|
+
| `rearm` | `() => void` | Re-open every track's capture window (no-op without `captureWindowMs`) |
|
|
190
|
+
| `overlayRef` | `RefObject<HTMLCanvasElement>` | Where the stock green-box overlay draws — attach to your own `<canvas>` to let the SDK render into it |
|
|
191
|
+
|
|
192
|
+
### Interactive mode (`cam.mode === "interactive"`)
|
|
193
|
+
|
|
194
|
+
| Field | Shape | What it is |
|
|
195
|
+
|---|---|---|
|
|
196
|
+
| `videoStream` | `MediaStream \| null` | Raw camera stream — attach to secondary `<video>` elements for picture-in-picture |
|
|
197
|
+
| `isLoading` / `isCapturing` / `isSwitchingCamera` / `isFlipped` / `isFaceAligned` | `boolean` | Pipeline state |
|
|
198
|
+
| `captureProgress` / `alignmentCountdown` | `number` | 0–1 progress for the alignment ring and auto-capture countdown |
|
|
199
|
+
| `faceBoundingBox` | `{ originX, originY, width, height } \| null` | Current face box in video coords |
|
|
200
|
+
| `captureImage()` / `toggleFlip()` | `() => void` | Trigger capture / mirror the preview |
|
|
201
|
+
| `canvasRef` | `RefObject<HTMLCanvasElement>` | Full-circle framing canvas |
|
|
202
|
+
|
|
203
|
+
### Single mode (`cam.mode === "single"`)
|
|
204
|
+
|
|
205
|
+
| Field | Shape | What it is |
|
|
206
|
+
|---|---|---|
|
|
207
|
+
| `state` | `SingleCaptureState` | `idle` / `searching` / `low-score` / `too-small` / `not-straight` / `occluded` / `tracking` / `done`. `occluded` only appears with `requireVisibleFeatures` |
|
|
208
|
+
| `bbox` | `SingleCaptureBox \| null` | Current face box |
|
|
209
|
+
| `isAligned` / `locked` | `boolean` | Alignment / lock state |
|
|
210
|
+
| `captureProgress` / `faceSize` / `frontalness` / `score` | `number` | Per-frame readings |
|
|
211
|
+
| `keypoints` | `Array<{ x, y }>` | Current subject's six keypoints, normalised 0–1; empty when no subject. For custom overlays |
|
|
212
|
+
| `featureVisibility` | `FeatureVisibility \| null` | Per-feature `skin` share (0–1), `visible` flags and `allVisible` for the subject. `null` unless `requireVisibleFeatures` |
|
|
213
|
+
| `result` | `SingleCaptureResult \| null` | Published best-shot + meta |
|
|
214
|
+
| `trigger()` / `rearm()` | `() => void` | Open a fresh capture window / restart search |
|
|
215
|
+
|
|
216
|
+
---
|
|
201
217
|
|
|
202
|
-
|
|
203
|
-
|
|
218
|
+
## Declarative overlays (`CameraViewport` children)
|
|
219
|
+
|
|
220
|
+
`<CameraViewport>` passes any children through to a `pointer-events: none`
|
|
221
|
+
layer on top of the camera. Anything that reads `useCamera()` can position
|
|
222
|
+
itself over the video — Mapbox-style composition.
|
|
204
223
|
|
|
205
224
|
```tsx
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
225
|
+
<CameraProvider mode="passive" overlayEnabled={false} onBatchCapture={handleBatch}>
|
|
226
|
+
<CameraViewport>
|
|
227
|
+
<TrackBoxes /> {/* reads activeTracks, draws DOM boxes */}
|
|
228
|
+
<ThresholdLine />
|
|
229
|
+
<DebugHud />
|
|
230
|
+
</CameraViewport>
|
|
231
|
+
</CameraProvider>
|
|
232
|
+
|
|
233
|
+
function TrackBoxes() {
|
|
234
|
+
const cam = useCamera();
|
|
235
|
+
if (cam.mode !== "passive") return null;
|
|
236
|
+
return (
|
|
237
|
+
<>
|
|
238
|
+
{cam.activeTracks.map((t) => (
|
|
239
|
+
<div
|
|
240
|
+
key={t.trackId}
|
|
241
|
+
style={{
|
|
242
|
+
position: "absolute",
|
|
243
|
+
left: `${(t.cx - t.width / 2) * 100}%`,
|
|
244
|
+
top: `${(t.cy - t.height / 2) * 100}%`,
|
|
245
|
+
width: `${t.width * 100}%`,
|
|
246
|
+
height: `${t.height * 100}%`,
|
|
247
|
+
border: `2px solid ${t.smoothedFrontalness > 50 ? "lime" : "red"}`,
|
|
248
|
+
}}
|
|
249
|
+
/>
|
|
250
|
+
))}
|
|
251
|
+
</>
|
|
252
|
+
);
|
|
210
253
|
}
|
|
211
254
|
```
|
|
212
255
|
|
|
213
|
-
|
|
214
|
-
|
|
256
|
+
`overlayEnabled={false}` turns off the SDK's green-box canvas so your DOM
|
|
257
|
+
boxes are the only overlay. Omit it (or set `true`) to layer custom children
|
|
258
|
+
on top of the stock overlay.
|
|
215
259
|
|
|
216
|
-
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## Pre-built components (`@meeeetup/camera-web/ui`)
|
|
217
263
|
|
|
218
264
|
| Component | Mode | Renders |
|
|
219
265
|
|---|---|---|
|
|
220
266
|
| `CameraViewport` | both | `<video>` + overlay canvas (passive) / circular viewport (interactive) |
|
|
221
267
|
| `FaceCounter` | passive | Tracked + total badge |
|
|
222
|
-
| `FaceGrid` | passive | Grid of selected face crops |
|
|
268
|
+
| `FaceGrid` | passive | Grid of selected face crops (live / committed / ready) |
|
|
223
269
|
| `DevicePicker` | both | Camera dropdown |
|
|
224
270
|
| `CameraToggle` | both | Front/back switch |
|
|
225
271
|
| `AlignmentRing` | interactive | Alignment ring, progress, countdown |
|
|
226
272
|
| `CaptureButton` | interactive | Manual capture trigger |
|
|
227
273
|
|
|
228
|
-
Every component
|
|
229
|
-
|
|
230
|
-
|
|
274
|
+
Every component accepts `className`. The skin is CSS custom properties
|
|
275
|
+
(`--mfc-*`) with dark defaults — re-theme by setting them on any ancestor.
|
|
276
|
+
|
|
277
|
+
---
|
|
231
278
|
|
|
232
279
|
## Provider props
|
|
233
280
|
|
|
234
|
-
Every mode
|
|
235
|
-
|
|
281
|
+
Every mode: `children`, `mediapipeWasmUrl`, `deviceId`, `onDeviceChange`,
|
|
282
|
+
`overlayEnabled`. Mode-specific props below. Capture gates (`cooldownMs`,
|
|
283
|
+
`minFrontalness`, `captureWindowMs`, …) are passive-only.
|
|
236
284
|
|
|
237
285
|
| Prop | Mode | Type | Default |
|
|
238
286
|
|---|---|---|---|
|
|
239
|
-
| `
|
|
240
|
-
| `
|
|
241
|
-
| `
|
|
287
|
+
| `onBatchCapture` | passive | `(faces: SelectedFace[]) => void \| Promise<void>` | **required** |
|
|
288
|
+
| `onCapture` | single, interactive | mode-specific signature | **required** |
|
|
289
|
+
| `deviceId` | all | `string` | unset — browser picks a default camera |
|
|
290
|
+
| `onDeviceChange` | all | `(id: string \| undefined) => void` | — fires when a child picker changes the device |
|
|
291
|
+
| `overlayEnabled` | passive | `boolean` | `true` — set `false` to disable the SDK's green boxes and render custom overlays |
|
|
242
292
|
| `cooldownMs` | passive | `number` | `10000` — minimum ms between sends for the same face |
|
|
243
|
-
| `
|
|
244
|
-
| `
|
|
245
|
-
| `minDetectionScore` | passive | `number` | `0.5` — detector confidence floor, applied before any pose analysis |
|
|
293
|
+
| `captureWindowMs` | passive | `number` | `0` — per-track best-shot window; `0` keeps settle-based capture |
|
|
294
|
+
| `minDetectionScore` | passive | `number` | `0.5` — detector confidence floor, applied before pose analysis |
|
|
246
295
|
| `minFaceHeight` | passive | `number` | `0` — minimum face-box height as a fraction of frame height (0–1); off by default |
|
|
247
296
|
| `minFrontalness` | passive | `number` | `50` — minimum pose score (0–100) a frame must reach to be captured |
|
|
248
|
-
| `
|
|
297
|
+
| `matchThreshold` | passive | `number` | `0.20` — max normalised centroid distance for a detection to continue an existing track |
|
|
298
|
+
| `mediapipeWasmUrl` | all | `string` | jsDelivr CDN — override to self-host MediaPipe WASM |
|
|
299
|
+
| `alignmentCaptureDelayMs` | interactive | `number` | `2000` — how long a face must stay aligned before auto-capture |
|
|
300
|
+
| `requireVisibleFeatures` | single | `boolean` | `false` — skip frames where an eye, the nose or the mouth is covered (mask, sunglasses, hand) |
|
|
249
301
|
|
|
250
|
-
With `captureWindowMs
|
|
251
|
-
best frame is published as final at expiry. `
|
|
302
|
+
With `captureWindowMs > 0`, each tracked face is searched for that long and
|
|
303
|
+
the best frame is published as final at expiry. `useCamera()` in passive mode
|
|
252
304
|
returns `rearm()`, which starts every window's search again.
|
|
253
305
|
|
|
306
|
+
### Occlusion check
|
|
307
|
+
|
|
308
|
+
`requireVisibleFeatures` samples the frame over each eye, the nose and the
|
|
309
|
+
mouth and compares it with the subject's own skin (forehead / under-eye
|
|
310
|
+
patches). A patch whose skin share falls below `FEATURE_SKIN_FLOOR` counts as
|
|
311
|
+
covered, and that frame is never selected. Show your own "remove mask /
|
|
312
|
+
sunglasses" prompt while `state === "occluded"`. The same check is exported
|
|
313
|
+
as `measureFeatureVisibility(source, width, height, keypoints)` for custom
|
|
314
|
+
pipelines; it needs all six keypoints.
|
|
315
|
+
|
|
316
|
+
Thresholds are calibrated on synthetic masks and sunglasses only. Treat the
|
|
317
|
+
flag as a hint and keep server-side `faceOccluded` (`?include=attributes`) as
|
|
318
|
+
the authority.
|
|
319
|
+
|
|
320
|
+
---
|
|
321
|
+
|
|
254
322
|
## Runtime network access
|
|
255
323
|
|
|
256
324
|
MediaPipe assets are fetched on demand, so the browser must reach:
|
|
@@ -258,12 +326,10 @@ MediaPipe assets are fetched on demand, so the browser must reach:
|
|
|
258
326
|
- `https://cdn.jsdelivr.net` — WASM runtime (override with `mediapipeWasmUrl`)
|
|
259
327
|
- `https://storage.googleapis.com` — the `.tflite` detection model
|
|
260
328
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
- `https://api.meeeetup.com` — capture ingest (override with `autoUpload.endpoint`)
|
|
329
|
+
The SDK itself makes no other requests. A strict CSP needs the two asset
|
|
330
|
+
origins in `connect-src`, plus `script-src 'wasm-unsafe-eval'`.
|
|
264
331
|
|
|
265
|
-
|
|
266
|
-
'wasm-unsafe-eval'`; add the capture origin when you use `autoUpload`.
|
|
332
|
+
---
|
|
267
333
|
|
|
268
334
|
## Licence
|
|
269
335
|
|
package/dist/camera-loop.d.ts
CHANGED
|
@@ -20,6 +20,9 @@ export declare class CameraLoop {
|
|
|
20
20
|
private vcbHandle;
|
|
21
21
|
private rafHandle;
|
|
22
22
|
private running;
|
|
23
|
+
/** Last timestamp handed to the detector; MediaPipe VIDEO mode rejects non-increasing ones. */
|
|
24
|
+
private lastDetectTs;
|
|
25
|
+
private detectorErrorLogged;
|
|
23
26
|
constructor(video: HTMLVideoElement, detector: SupportedDetector, callbacks: CameraLoopCallbacks);
|
|
24
27
|
start(deviceId?: string, facingMode?: "user" | "environment"): Promise<void>;
|
|
25
28
|
stop(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"camera-loop.d.ts","sourceRoot":"","sources":["../src/camera-loop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGvD,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG,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AiB,EAC3B,SAAS,EAAE,mBAAmB;IAG3C,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,UAAU,GAAE,MAAM,GAAG,aAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAoC1F,IAAI,IAAI,IAAI;IAcZ,kEAAkE;IAClE,IAAI,eAAe,IAAI,iBAAiB,GAAG,IAAI,CAA2B;IAE1E;;;;;;;OAOG;YACW,gBAAgB;IAkB9B,OAAO,CAAC,eAAe;IAUvB,OAAO,CAAC,YAAY;CA+CrB"}
|
package/dist/camera-loop.js
CHANGED
|
@@ -14,6 +14,9 @@ export class CameraLoop {
|
|
|
14
14
|
this.vcbHandle = null;
|
|
15
15
|
this.rafHandle = null;
|
|
16
16
|
this.running = false;
|
|
17
|
+
/** Last timestamp handed to the detector; MediaPipe VIDEO mode rejects non-increasing ones. */
|
|
18
|
+
this.lastDetectTs = 0;
|
|
19
|
+
this.detectorErrorLogged = false;
|
|
17
20
|
}
|
|
18
21
|
async start(deviceId, facingMode = "user") {
|
|
19
22
|
let constraint;
|
|
@@ -114,20 +117,38 @@ export class CameraLoop {
|
|
|
114
117
|
this.offscreen.height = vh;
|
|
115
118
|
}
|
|
116
119
|
this.offscreen.getContext("2d")?.drawImage(this.video, 0, 0, vw, vh);
|
|
117
|
-
|
|
120
|
+
// MediaPipe VIDEO mode throws on a timestamp that does not strictly
|
|
121
|
+
// increase (frame stalls, tab switches), so never hand it a repeat.
|
|
122
|
+
const ts = nowPerf > this.lastDetectTs ? nowPerf : this.lastDetectTs + 1;
|
|
123
|
+
this.lastDetectTs = ts;
|
|
124
|
+
// A single failing frame must never stop detection: log once, reschedule.
|
|
125
|
+
const onDetectorError = (err) => {
|
|
126
|
+
if (!this.detectorErrorLogged) {
|
|
127
|
+
console.error("[camera-loop] detector frame failed; continuing", err);
|
|
128
|
+
this.detectorErrorLogged = true;
|
|
129
|
+
}
|
|
130
|
+
if (this.running)
|
|
131
|
+
this._scheduleDetect(this._detectFrame.bind(this));
|
|
132
|
+
};
|
|
118
133
|
// MediapipeDetector is synchronous; TensorFlowDetector returns a Promise
|
|
119
|
-
|
|
134
|
+
let result;
|
|
135
|
+
try {
|
|
136
|
+
result = this.detector.detectForVideo?.(this.offscreen, ts);
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
onDetectorError(err);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
120
142
|
if (result instanceof Promise) {
|
|
121
143
|
result.then((dets) => {
|
|
122
144
|
if (!this.running)
|
|
123
145
|
return;
|
|
124
|
-
this.callbacks.onFrame(dets, new CanvasFrameBuffer(this.offscreen),
|
|
146
|
+
this.callbacks.onFrame(dets, new CanvasFrameBuffer(this.offscreen), ts);
|
|
125
147
|
this._scheduleDetect(this._detectFrame.bind(this));
|
|
126
|
-
});
|
|
148
|
+
}, onDetectorError);
|
|
127
149
|
return; // don't re-schedule synchronously
|
|
128
150
|
}
|
|
129
|
-
|
|
130
|
-
this.callbacks.onFrame(detections, new CanvasFrameBuffer(this.offscreen), nowPerf);
|
|
151
|
+
this.callbacks.onFrame(result, new CanvasFrameBuffer(this.offscreen), ts);
|
|
131
152
|
this._scheduleDetect(this._detectFrame.bind(this));
|
|
132
153
|
}
|
|
133
154
|
}
|
package/dist/camera-loop.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"camera-loop.js","sourceRoot":"","sources":["../src/camera-loop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAItD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AASjE;;;GAGG;AACH,MAAM,OAAO,UAAU;
|
|
1
|
+
{"version":3,"file":"camera-loop.js","sourceRoot":"","sources":["../src/camera-loop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAItD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AASj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AAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACrD,CAAC;CACF"}
|
|
@@ -4,7 +4,7 @@ import type { Detection } from "@meeeetup/camera-core";
|
|
|
4
4
|
*
|
|
5
5
|
* MediaPipe keypoint order: [0] rightEye [1] leftEye [2] noseTip [3] mouth
|
|
6
6
|
* [4] rightEar [5] leftEar
|
|
7
|
-
*
|
|
7
|
+
* All six are kept; getFrontalness() uses [3..5] when present.
|
|
8
8
|
*/
|
|
9
9
|
export declare class MediapipeDetector {
|
|
10
10
|
private readonly detector;
|
|
@@ -5,7 +5,7 @@ const DEFAULT_MODEL_URL = "https://storage.googleapis.com/mediapipe-models/face_
|
|
|
5
5
|
*
|
|
6
6
|
* MediaPipe keypoint order: [0] rightEye [1] leftEye [2] noseTip [3] mouth
|
|
7
7
|
* [4] rightEar [5] leftEar
|
|
8
|
-
*
|
|
8
|
+
* All six are kept; getFrontalness() uses [3..5] when present.
|
|
9
9
|
*/
|
|
10
10
|
export class MediapipeDetector {
|
|
11
11
|
constructor(detector) {
|
|
@@ -40,7 +40,7 @@ export class MediapipeDetector {
|
|
|
40
40
|
width: d.boundingBox.width / W,
|
|
41
41
|
height: d.boundingBox.height / H,
|
|
42
42
|
},
|
|
43
|
-
keypoints: (d.keypoints ?? []).slice(0,
|
|
43
|
+
keypoints: (d.keypoints ?? []).slice(0, 6).map((kp) => ({
|
|
44
44
|
x: kp.x,
|
|
45
45
|
y: kp.y,
|
|
46
46
|
})),
|
|
@@ -43,8 +43,8 @@ export class TensorFlowDetector {
|
|
|
43
43
|
width: bw / W,
|
|
44
44
|
height: bh / H,
|
|
45
45
|
},
|
|
46
|
-
// BlazeFace landmarks
|
|
47
|
-
keypoints: p.landmarks.slice(0,
|
|
46
|
+
// BlazeFace landmarks share MediaPipe's order: eyes, nose, mouth, ears
|
|
47
|
+
keypoints: p.landmarks.slice(0, 6).map(([lx, ly]) => ({
|
|
48
48
|
x: lx / W,
|
|
49
49
|
y: ly / H,
|
|
50
50
|
})),
|