@mostajs/face 1.3.0 → 1.3.1
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/dist/components/FaceDetector.js +23 -13
- package/package.json +1 -1
|
@@ -71,15 +71,18 @@ function FaceDetector({ photo, onCapture, onClear, verifyDescriptor, onVerifyRes
|
|
|
71
71
|
const stream = await navigator.mediaDevices.getUserMedia({
|
|
72
72
|
video: { width: 320, height: 240, facingMode: 'user' },
|
|
73
73
|
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
74
|
+
// If component unmounted while awaiting getUserMedia, stop tracks immediately
|
|
75
|
+
if (!videoRef.current) {
|
|
76
|
+
stream.getTracks().forEach((track) => track.stop());
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
videoRef.current.srcObject = stream;
|
|
80
|
+
await videoRef.current.play().catch(() => { });
|
|
81
|
+
setStreaming(true);
|
|
82
|
+
if (enabled && modelsReady) {
|
|
83
|
+
videoRef.current.onloadeddata = () => {
|
|
84
|
+
animFrameRef.current = requestAnimationFrame(detectLoop);
|
|
85
|
+
};
|
|
83
86
|
}
|
|
84
87
|
}
|
|
85
88
|
catch {
|
|
@@ -96,13 +99,20 @@ function FaceDetector({ photo, onCapture, onClear, verifyDescriptor, onVerifyRes
|
|
|
96
99
|
setStreaming(false);
|
|
97
100
|
setFaceDetected(false);
|
|
98
101
|
}, []);
|
|
99
|
-
// Cleanup on unmount
|
|
102
|
+
// Cleanup on unmount — stop all tracks and detach stream
|
|
100
103
|
(0, react_1.useEffect)(() => {
|
|
101
104
|
return () => {
|
|
102
105
|
cancelAnimationFrame(animFrameRef.current);
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
+
const video = videoRef.current;
|
|
107
|
+
if (video) {
|
|
108
|
+
video.pause();
|
|
109
|
+
const stream = video.srcObject;
|
|
110
|
+
if (stream) {
|
|
111
|
+
stream.getTracks().forEach((track) => track.stop());
|
|
112
|
+
}
|
|
113
|
+
video.srcObject = null;
|
|
114
|
+
video.removeAttribute('src');
|
|
115
|
+
video.load();
|
|
106
116
|
}
|
|
107
117
|
};
|
|
108
118
|
}, []);
|
package/package.json
CHANGED