forked from yugasun/qrcode-decoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.html
45 lines (42 loc) · 1.68 KB
/
camera.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>QrcodeDecoder - Camera</title>
</head>
<body>
<button id="start">Start</button> <button id="stop">Stop</button><br />
<span id="result">Click start to scan qrcode.</span><br />
<hr />
<video id="video" autoplay></video>
<script src="./lib/vconsole.min.js"></script>
<script src="./index.aio.min.js"></script>
<script type="text/javascript">
var vConsole = new VConsole();
console.log("Hello world");
function main() {
var qr = new QrcodeDecoder();
var video = document.querySelector("#video");
var start = document.querySelector("#start");
var stop = document.querySelector("#stop");
var result = document.querySelector("#result");
async function startScan() {
if (!qr.isCanvasSupported()) {
alert("Your browser doesn't match the required specs.");
throw new Error("Canvas and getUserMedia are required");
}
let code = await qr.decodeFromCamera(video);
console.log("code", code);
result.innerText = "Result: " + code.data;
}
start.onclick = startScan;
stop.onclick = function() {
qr.stop();
};
}
main();
</script>
</body>
</html>