feat(fusion_clock): camera capture on NFC kiosk
Replace camera stub with real getUserMedia + canvas capture. Setup button now starts NFC reader and camera together; camera failure is non-fatal when photo is not required. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -177,10 +177,33 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ──────────────────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────────────────
|
||||||
// Camera capture (real implementation in Task 17, stub for now)
|
// Camera
|
||||||
// ──────────────────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────────────────
|
||||||
|
let cameraStream = null;
|
||||||
|
const videoEl = document.getElementById("nfc_camera_feed");
|
||||||
|
const canvasEl = document.getElementById("nfc_camera_canvas");
|
||||||
|
|
||||||
|
async function startCamera() {
|
||||||
|
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
|
||||||
|
throw new Error("Camera not supported on this browser/device.");
|
||||||
|
}
|
||||||
|
cameraStream = await navigator.mediaDevices.getUserMedia({
|
||||||
|
video: { facingMode: "user", width: { ideal: 640 }, height: { ideal: 480 } },
|
||||||
|
audio: false,
|
||||||
|
});
|
||||||
|
videoEl.srcObject = cameraStream;
|
||||||
|
await videoEl.play();
|
||||||
|
}
|
||||||
|
|
||||||
async function capturePhoto() {
|
async function capturePhoto() {
|
||||||
return ""; // overridden in Task 17
|
if (!videoEl || !canvasEl || !videoEl.videoWidth) return "";
|
||||||
|
const w = videoEl.videoWidth;
|
||||||
|
const h = videoEl.videoHeight;
|
||||||
|
canvasEl.width = w;
|
||||||
|
canvasEl.height = h;
|
||||||
|
const ctx = canvasEl.getContext("2d");
|
||||||
|
ctx.drawImage(videoEl, 0, 0, w, h);
|
||||||
|
return canvasEl.toDataURL("image/jpeg", 0.7);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ──────────────────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────────────────
|
||||||
@@ -191,6 +214,12 @@
|
|||||||
setupBtn.addEventListener("click", async () => {
|
setupBtn.addEventListener("click", async () => {
|
||||||
try {
|
try {
|
||||||
await startNfcReader();
|
await startNfcReader();
|
||||||
|
try {
|
||||||
|
await startCamera();
|
||||||
|
} catch (camErr) {
|
||||||
|
if (photoRequired) throw camErr;
|
||||||
|
console.warn("[nfc-kiosk] camera unavailable, continuing (photo not required)", camErr);
|
||||||
|
}
|
||||||
setState(STATE.IDLE);
|
setState(STATE.IDLE);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
stateContainer.innerHTML = `
|
stateContainer.innerHTML = `
|
||||||
|
|||||||
Reference in New Issue
Block a user