@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.
@@ -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
- if (videoRef.current) {
75
- videoRef.current.srcObject = stream;
76
- videoRef.current.play();
77
- setStreaming(true);
78
- if (enabled && modelsReady) {
79
- videoRef.current.onloadeddata = () => {
80
- animFrameRef.current = requestAnimationFrame(detectLoop);
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
- if (videoRef.current?.srcObject) {
104
- const tracks = videoRef.current.srcObject.getTracks();
105
- tracks.forEach((track) => track.stop());
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mostajs/face",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Reusable face recognition module — detection, descriptor extraction, 1:N matching",
5
5
  "author": "Dr Hamid MADANI <drmdh@msn.com>",
6
6
  "license": "MIT",