Created
January 27, 2022 11:20
-
-
Save MrMeison/d223bf435360b4834416f438e8d211a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const useVideo = (videoRef: RefObject<HTMLVideoElement>, device: MediaDeviceInfo) => { | |
const [started, setStarted] = useState(false); | |
useEffect(() => { | |
if (!videoRef.current || !device) { | |
return noop; | |
} | |
const videoService = new VideoService(); | |
const start = async () => { | |
try { | |
await videoService.start(videoRef.current, device); | |
setStarted(true); | |
} catch { | |
setStarted(false); | |
} | |
} | |
start(); | |
return () => { | |
videoService.stop(); | |
} | |
}, [videoRef, device]); | |
return started; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment