Skip to content

Commit

Permalink
fixes after code review
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaDemchenko committed Jan 17, 2024
1 parent 9f39219 commit a142112
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/components/camera-stream/CameraStream.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@ import styles from './CameraStream.module.css'

export const CameraStream = () => {
const videoRef = useRef<HTMLVideoElement>(null)
const [showCam, setShowCam] = useState(false)
const [isVideoVisible, setIsVideoVisible] = useState(false)

const getVideo = async () => {
try {
const stream = await navigator.mediaDevices.getUserMedia({
video: { width: 1280, height: 720 },
})
useEffect(() => {
const initializeCamera = async () => {
try {
const stream = await navigator.mediaDevices.getUserMedia({
video: { width: 1280, height: 720 },
})

const video = videoRef.current
const video = videoRef.current

if (!video) return
if (!video) return

video.srcObject = stream
video.play()
} catch (error) {
console.log(error)
video.srcObject = stream
video.play()
} catch (error) {
console.log(error)
}
}
}

useEffect(() => {
getVideo()
initializeCamera()
}, [])

const handleChange = () => {
setShowCam(!showCam)
setIsVideoVisible(!isVideoVisible)
}

return (
Expand All @@ -36,14 +36,14 @@ export const CameraStream = () => {
<input
type="checkbox"
id="showVideo"
checked={showCam}
checked={isVideoVisible}
onChange={handleChange}
></input>
/>
<label htmlFor="showVideo">Show video</label>
</div>
<div>
<video
className={showCam ? styles.videoStream : styles.displayNone}
className={isVideoVisible ? styles.videoStream : styles.displayNone}
ref={videoRef}
></video>
</div>
Expand Down

0 comments on commit a142112

Please sign in to comment.