summaryrefslogtreecommitdiff
path: root/src/common/components/Scanner/index.tsx
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-11-09 15:40:16 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-11-09 15:40:16 +0700
commitbe0f537dc4fe384eef09436833c6407e6482c16d (patch)
tree194b1ad3f34396cb8149075bbbd38b854aedf361 /src/common/components/Scanner/index.tsx
parent5d5401ae36e7e0c8eb38ccd943c1aa44a9573d35 (diff)
Initial commit
Diffstat (limited to 'src/common/components/Scanner/index.tsx')
-rw-r--r--src/common/components/Scanner/index.tsx39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/common/components/Scanner/index.tsx b/src/common/components/Scanner/index.tsx
new file mode 100644
index 0000000..56d2495
--- /dev/null
+++ b/src/common/components/Scanner/index.tsx
@@ -0,0 +1,39 @@
+import { useZxing } from "react-zxing";
+import styles from "./scanner.module.css"
+
+type Props = {
+ paused: boolean,
+ onScan: (string: string) => void
+}
+
+const Scanner = (props: Props) => {
+ const { ref } = useZxing({
+ constraints: {
+ video: {
+ facingMode: 'environment',
+ width: { ideal: 1280 },
+ height: { ideal: 720 },
+ frameRate: { ideal: 30, max: 60 }
+ }
+ },
+ timeBetweenDecodingAttempts: 100,
+ paused: props.paused,
+ onDecodeResult(result) {
+ props.onScan(result.getText());
+ },
+ })
+
+ const restartCam = () => {
+ ref.current?.pause()
+ ref.current?.play()
+ }
+
+ return (
+ <div className={styles.wrapper}>
+ <video ref={ref} onClick={restartCam} className={styles.video} />
+ <div className={styles.videoFrame} />
+ </div>
+ )
+}
+
+export default Scanner \ No newline at end of file