-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDemoCustomVideoFilter.tsx
48 lines (42 loc) · 1.22 KB
/
DemoCustomVideoFilter.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import React, { useEffect, useState } from 'react'
import { Camera, VideoQrScanner } from './webcam-qr-scanner'
function DemoCustomVideoFilter() {
const [qrCode, setQrCode] = useState('')
const [shouldScan, setShouldScan] = useState(false)
const [video, setVideo] = useState<HTMLVideoElement | null>(null)
const [hueRotate, setHueRotate] = useState(0)
useEffect(() => {
const timer = requestAnimationFrame(() => {
setHueRotate((hueRotate) => (hueRotate + 1) % 360)
})
return () => cancelAnimationFrame(timer)
}, [hueRotate])
function startScanner() {
setShouldScan(true)
}
function stopScanner() {
setShouldScan(false)
}
return (
<>
<p>
QR Code: <code>{qrCode}</code>
</p>
{!shouldScan ? (
<button onClick={startScanner}>Scan QR Code</button>
) : (
<>
<button onClick={stopScanner}>Stop Scanning</button>
<Camera
onVideo={setVideo}
style={{
filter: `hue-rotate(${hueRotate}deg) contrast(150%) saturate(3)`,
}}
/>
{video && <VideoQrScanner video={video} onQrCode={setQrCode} />}
</>
)}
</>
)
}
export default DemoCustomVideoFilter