|
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 = () => { |
|
|
|
const videoRef = useRef(null); |
|
const canvasRef = useRef(null); |
|
const containerRef = useRef(null); |
|
|
|
|
|
const [facingMode, setFacingMode] = useState('user'); |
|
const [cameraError, setCameraError] = useState(false); |
|
|
|
|
|
const [customPrompt, setCustomPrompt] = useState( |
|
"μ΄ μ΄λ―Έμ§λ₯Ό λ³΄κ³ (λ³΄μΌ μλ μλ μμ΄λ μκ°λ½μ 무μν μ±) μ€λ‘μ§ playing cardsλ§ μλ³νμΈμ. μλ³λ μΉ΄λμ μ νν μ λ³΄λ§ μΆλ ₯νμΈμ(μ, A μ€νμ΄λ, 10 ννΈ, J λ€μ΄μλͺ¬λ" |
|
); |
|
|
|
|
|
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); |
|
|
|
|
|
useEffect(() => { |
|
return () => { |
|
|
|
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; |