-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: try to use rear camera by default
- Loading branch information
Showing
8 changed files
with
162 additions
and
150 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ tsconfig.tsbuildinfo | |
coverage | ||
yarn.lock | ||
.rpt2_cache | ||
|
||
demo/lib/index.min.js |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,48 @@ | ||
<!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.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'); | ||
} | ||
<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> | ||
|
||
let code = await qr.decodeFromCamera(video); | ||
console.log('code', code); | ||
result.innerText = 'Result: ' + code.data; | ||
<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="./lib/index.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'); | ||
} | ||
start.onclick = startScan; | ||
|
||
stop.onclick = function() { | ||
qr.stop(); | ||
}; | ||
let code = await qr.decodeFromCamera(video); | ||
console.log('code', code); | ||
result.innerText = 'Result: ' + code.data; | ||
} | ||
main(); | ||
</script> | ||
</body> | ||
start.onclick = startScan; | ||
|
||
stop.onclick = function () { | ||
qr.stop(); | ||
}; | ||
} | ||
main(); | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,66 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<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 - Image</title> | ||
</head> | ||
<body> | ||
<section> | ||
<h3>Same domain image</h3> | ||
<img id="img1" src="./assets/qrcode.png" alt="qr code" /><br /> | ||
<button id="decode1">Decode!</button><br /> | ||
<span id="result1"></span><br /> | ||
</section> | ||
<hr /> | ||
<section> | ||
<h3>Different domain image</h3> | ||
<input | ||
id="img2" | ||
value="https://yugasun.com/static/wechat.jpg" | ||
style="width: 400px" | ||
/><br /> | ||
<button id="decode2">Decode!</button><br /> | ||
<span id="result2"></span><br /> | ||
</section> | ||
<script src="./lib/vconsole.min.js"></script> | ||
<script src="./index.min.js"></script> | ||
<script type="module"> | ||
var vConsole = new VConsole(); | ||
function main() { | ||
var qr = new QrcodeDecoder(); | ||
|
||
var btn1 = document.querySelector('button#decode1'); | ||
var btn2 = document.querySelector('button#decode2'); | ||
var result1 = document.querySelector('#result1'); | ||
var result2 = document.querySelector('#result2'); | ||
var img1 = document.querySelector('#img1'); | ||
var img2 = document.querySelector('#img2'); | ||
<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 - Image</title> | ||
</head> | ||
|
||
btn1.onclick = async () => { | ||
// you can also decode from image path | ||
// const code = await qr.decodeFromImage('./assets/qrcode.png'); | ||
const code = await qr.decodeFromImage(img1); | ||
console.log(code); | ||
result1.innerText = code.data; | ||
}; | ||
<body> | ||
<section> | ||
<h3>Same domain image</h3> | ||
<img id="img1" src="./assets/qrcode.png" alt="qr code" /><br /> | ||
<button id="decode1">Decode!</button><br /> | ||
<span id="result1"></span><br /> | ||
</section> | ||
<hr /> | ||
<section> | ||
<h3>Different domain image</h3> | ||
<input | ||
id="img2" | ||
value="https://yugasun.com/static/wechat.jpg" | ||
style="width: 400px" /><br /> | ||
<button id="decode2">Decode!</button><br /> | ||
<span id="result2"></span><br /> | ||
</section> | ||
<script src="./lib/vconsole.min.js"></script> | ||
<script src="./lib/index.min.js"></script> | ||
<script type="module"> | ||
var vConsole = new VConsole(); | ||
function main() { | ||
var qr = new QrcodeDecoder(); | ||
|
||
btn2.onclick = async () => { | ||
// you can also decode from image path | ||
// const code = await qr.decodeFromImage('./assets/qrcode.png'); | ||
const code = await qr.decodeFromImage(img2.value, { | ||
crossOrigin: 'anonymous', | ||
}); | ||
console.log(code); | ||
result2.innerText = code.data; | ||
}; | ||
} | ||
window.onload = () => { | ||
main(); | ||
var btn1 = document.querySelector('button#decode1'); | ||
var btn2 = document.querySelector('button#decode2'); | ||
var result1 = document.querySelector('#result1'); | ||
var result2 = document.querySelector('#result2'); | ||
var img1 = document.querySelector('#img1'); | ||
var img2 = document.querySelector('#img2'); | ||
|
||
btn1.onclick = async () => { | ||
// you can also decode from image path | ||
// const code = await qr.decodeFromImage('./assets/qrcode.png'); | ||
const code = await qr.decodeFromImage(img1); | ||
console.log(code); | ||
result1.innerText = code.data; | ||
}; | ||
|
||
btn2.onclick = async () => { | ||
// you can also decode from image path | ||
// const code = await qr.decodeFromImage('./assets/qrcode.png'); | ||
const code = await qr.decodeFromImage(img2.value, { | ||
crossOrigin: 'anonymous', | ||
}); | ||
console.log(code); | ||
result2.innerText = code.data; | ||
}; | ||
</script> | ||
</body> | ||
} | ||
window.onload = () => { | ||
main(); | ||
}; | ||
</script> | ||
</body> | ||
|
||
</html> |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,45 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<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 - Video</title> | ||
</head> | ||
<body> | ||
<button id="start">Start</button> <button id="stop">Stop</button><br /> | ||
<span id="result">Click start to scan qrcode.</span><br /> | ||
|
||
<video src="./assets/qrcode-video.mp4"></video> | ||
<script src="./lib/vconsole.min.js"></script> | ||
<script src="./index.min.js"></script> | ||
<script type="text/javascript"> | ||
var vConsole = new VConsole(); | ||
console.log('Hello world'); | ||
function main() { | ||
var video = document.querySelector('video'); | ||
var result = document.querySelector('#result'); | ||
var start = document.querySelector('#start'); | ||
var stop = document.querySelector('#stop'); | ||
var qr = new QrcodeDecoder(); | ||
<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 - Video</title> | ||
</head> | ||
|
||
start.onclick = startScan; | ||
<body> | ||
<button id="start">Start</button> <button id="stop">Stop</button><br /> | ||
<span id="result">Click start to scan qrcode.</span><br /> | ||
|
||
stop.onclick = function() { | ||
qr.stop(); | ||
video.pause(); | ||
}; | ||
<video src="./assets/qrcode-video.mp4"></video> | ||
<script src="./lib/vconsole.min.js"></script> | ||
<script src="./lib/index.min.js"></script> | ||
<script type="text/javascript"> | ||
var vConsole = new VConsole(); | ||
function main() { | ||
var video = document.querySelector('video'); | ||
var result = document.querySelector('#result'); | ||
var start = document.querySelector('#start'); | ||
var stop = document.querySelector('#stop'); | ||
var qr = new QrcodeDecoder(); | ||
|
||
async function startScan() { | ||
video.play(); | ||
const code = await qr.decodeFromVideo(video); | ||
console.log('code', code); | ||
result.innerText = 'Result: ' + code.data; | ||
} | ||
start.onclick = startScan; | ||
|
||
stop.onclick = function () { | ||
qr.stop(); | ||
video.pause(); | ||
}; | ||
|
||
async function startScan() { | ||
video.play(); | ||
const code = await qr.decodeFromVideo(video); | ||
console.log('code', code); | ||
result.innerText = 'Result: ' + code.data; | ||
} | ||
main(); | ||
</script> | ||
</body> | ||
} | ||
main(); | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains 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
This file contains 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
This file contains 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