CARDS / components /HandDetector.js
ginipick's picture
Update components/HandDetector.js
c3ece2d verified
raw
history blame
3.7 kB
import { useRef, useState, useEffect } from 'react';
import ParticleEffects, { useParticleEffects } from './ParticleEffects'
import MainContent from './MainContent';
import { AnimationStyles, AudioEffects } from './UIUtils';
import useDeviceAndCanvas from '../hooks/useDeviceAndCanvas';
import useHandDetection from '../hooks/useHandDetection';
import useThoughtGeneration from '../hooks/useThoughtGeneration';
const HandDetector = () => {
// Refs
const videoRef = useRef(null);
const canvasRef = useRef(null);
const containerRef = useRef(null);
// Camera state
const [facingMode, setFacingMode] = useState('user'); // 'user' for front camera, 'environment' for back camera
const [cameraError, setCameraError] = useState(false);
// Prompt state
const [customPrompt, setCustomPrompt] = useState(
"์ด ์ด๋ฏธ์ง€๋ฅผ ๋ณด๊ณ  (๋ณด์ผ ์ˆ˜๋„ ์žˆ๋Š” ์†์ด๋‚˜ ์†๊ฐ€๋ฝ์€ ๋ฌด์‹œํ•œ ์ฑ„) ์ฃผ์š” ๊ฐ์ฒด๋‚˜ ์žฅ๋ฉด์„ ์‹๋ณ„ํ•˜์„ธ์š”. ๊ทธ ๊ฐ์ฒด๋‚˜ ์žฅ๋ฉด์— ๋Œ€ํ•ด ์งง๊ณ  ํ†ต์ฐฐ๋ ฅ ์žˆ๋Š” ์ƒ๊ฐ(์ตœ๋Œ€ 5๋‹จ์–ด)์„ ํ•˜๋‚˜ ์ƒ์„ฑํ•˜์„ธ์š”. ํฅ๋ฏธ๋กญ๊ฑฐ๋‚˜ ์žฌ๋ฏธ์žˆ๊ฑฐ๋‚˜ ์˜ˆ์ƒ์น˜ ๋ชปํ•œ ์ ์— ์ง‘์ค‘ํ•˜์„ธ์š”. ์†, ์†๊ฐ€๋ฝ, ํฌ์ฆˆ ์ถ”์ •, ๋ชจ์…˜ ํŠธ๋ž˜ํ‚น, ์ปดํ“จํ„ฐ ๋น„์ „ ๊ธฐ์ˆ ์€ ์–ธ๊ธ‰ํ•˜์ง€ ๋งˆ์„ธ์š”. ์ƒ๊ฐ๋งŒ ์‘๋‹ตํ•˜๊ณ , ์ถ”๊ฐ€ ํ…์ŠคํŠธ๋Š” ๋„ฃ์ง€ ๋งˆ์„ธ์š”."
);
// Custom hooks
const {
isMobile,
isMac,
canvasWidth,
canvasHeight,
videoAspectRatio,
setVideoAspectRatio,
updateCanvasSize
} = useDeviceAndCanvas();
const {
handDetected,
isMouthOpen,
isLeftHand,
thumbPosition,
isFirstLoad
} = useHandDetection(videoRef, canvasRef, isMobile);
const {
thought,
isThinking,
animateThinking
} = useThoughtGeneration(canvasRef, isMouthOpen, customPrompt);
const {
particles,
popParticles,
createSparkleParticles,
createPopParticles
} = useParticleEffects(containerRef, isMobile);
// Clean up all component mounted refs on unmount
useEffect(() => {
return () => {
// This will run when the component unmounts
console.log("HandDetector component unmounting");
};
}, []);
return (
<div className="relative flex flex-col items-center w-full">
{/* Add animations and styles */}
<AnimationStyles />
{/* Add audio effects */}
<AudioEffects isThinking={isThinking} />
{cameraError ? (
<div className="bg-red-500 text-white p-4 rounded-lg mb-4 w-full max-w-md">
<p className="font-medium">Camera access denied. Please allow camera access to use this app.</p>
</div>
) : (
<MainContent
videoRef={videoRef}
canvasRef={canvasRef}
containerRef={containerRef}
facingMode={facingMode}
setFacingMode={setFacingMode}
setCameraError={setCameraError}
customPrompt={customPrompt}
setCustomPrompt={setCustomPrompt}
isMac={isMac}
isMobile={isMobile}
canvasWidth={canvasWidth}
canvasHeight={canvasHeight}
setVideoAspectRatio={setVideoAspectRatio}
updateCanvasSize={updateCanvasSize}
handDetected={handDetected}
isMouthOpen={isMouthOpen}
isLeftHand={isLeftHand}
thumbPosition={thumbPosition}
isFirstLoad={isFirstLoad}
thought={thought}
isThinking={isThinking}
animateThinking={animateThinking}
particles={particles}
popParticles={popParticles}
createSparkleParticles={createSparkleParticles}
createPopParticles={createPopParticles}
/>
)}
</div>
);
};
export default HandDetector;