mirror of
https://github.com/yugasun/qrcode-decoder.git
synced 2026-08-12 20:27:56 +08:00
fix: try to use rear camera by default
This commit is contained in:
@@ -9,3 +9,5 @@ tsconfig.tsbuildinfo
|
|||||||
coverage
|
coverage
|
||||||
yarn.lock
|
yarn.lock
|
||||||
.rpt2_cache
|
.rpt2_cache
|
||||||
|
|
||||||
|
demo/lib/index.min.js
|
||||||
|
|||||||
+4
-1
@@ -1,11 +1,13 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
||||||
<title>QrcodeDecoder - Camera</title>
|
<title>QrcodeDecoder - Camera</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<button id="start">Start</button> <button id="stop">Stop</button><br />
|
<button id="start">Start</button> <button id="stop">Stop</button><br />
|
||||||
<span id="result">Click start to scan qrcode.</span><br />
|
<span id="result">Click start to scan qrcode.</span><br />
|
||||||
@@ -13,7 +15,7 @@
|
|||||||
<video id="video" autoplay></video>
|
<video id="video" autoplay></video>
|
||||||
|
|
||||||
<script src="./lib/vconsole.min.js"></script>
|
<script src="./lib/vconsole.min.js"></script>
|
||||||
<script src="./index.min.js"></script>
|
<script src="./lib/index.min.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var vConsole = new VConsole();
|
var vConsole = new VConsole();
|
||||||
console.log('Hello world');
|
console.log('Hello world');
|
||||||
@@ -42,4 +44,5 @@
|
|||||||
main();
|
main();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+5
-3
@@ -1,11 +1,13 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
||||||
<title>QrcodeDecoder - Image</title>
|
<title>QrcodeDecoder - Image</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<section>
|
<section>
|
||||||
<h3>Same domain image</h3>
|
<h3>Same domain image</h3>
|
||||||
@@ -19,13 +21,12 @@
|
|||||||
<input
|
<input
|
||||||
id="img2"
|
id="img2"
|
||||||
value="https://yugasun.com/static/wechat.jpg"
|
value="https://yugasun.com/static/wechat.jpg"
|
||||||
style="width: 400px"
|
style="width: 400px" /><br />
|
||||||
/><br />
|
|
||||||
<button id="decode2">Decode!</button><br />
|
<button id="decode2">Decode!</button><br />
|
||||||
<span id="result2"></span><br />
|
<span id="result2"></span><br />
|
||||||
</section>
|
</section>
|
||||||
<script src="./lib/vconsole.min.js"></script>
|
<script src="./lib/vconsole.min.js"></script>
|
||||||
<script src="./index.min.js"></script>
|
<script src="./lib/index.min.js"></script>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
var vConsole = new VConsole();
|
var vConsole = new VConsole();
|
||||||
function main() {
|
function main() {
|
||||||
@@ -61,4 +62,5 @@
|
|||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Vendored
-1
File diff suppressed because one or more lines are too long
+4
-2
@@ -1,21 +1,22 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
||||||
<title>QrcodeDecoder - Video</title>
|
<title>QrcodeDecoder - Video</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<button id="start">Start</button> <button id="stop">Stop</button><br />
|
<button id="start">Start</button> <button id="stop">Stop</button><br />
|
||||||
<span id="result">Click start to scan qrcode.</span><br />
|
<span id="result">Click start to scan qrcode.</span><br />
|
||||||
|
|
||||||
<video src="./assets/qrcode-video.mp4"></video>
|
<video src="./assets/qrcode-video.mp4"></video>
|
||||||
<script src="./lib/vconsole.min.js"></script>
|
<script src="./lib/vconsole.min.js"></script>
|
||||||
<script src="./index.min.js"></script>
|
<script src="./lib/index.min.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var vConsole = new VConsole();
|
var vConsole = new VConsole();
|
||||||
console.log('Hello world');
|
|
||||||
function main() {
|
function main() {
|
||||||
var video = document.querySelector('video');
|
var video = document.querySelector('video');
|
||||||
var result = document.querySelector('#result');
|
var result = document.querySelector('#result');
|
||||||
@@ -40,4 +41,5 @@
|
|||||||
main();
|
main();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+4
-2
@@ -11,9 +11,10 @@
|
|||||||
"prettier:fix": "prettier --write '**/*.{ts,tsx,md}' --config .prettierrc",
|
"prettier:fix": "prettier --write '**/*.{ts,tsx,md}' --config .prettierrc",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"codecov": "jest --coverage && codecov",
|
"codecov": "jest --coverage && codecov",
|
||||||
"copy-file": "cp dist/index.min.js demo/",
|
"copy-file": "cp dist/index.min.js demo/lib",
|
||||||
"release": "git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags",
|
"release": "git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags",
|
||||||
"pages": "gh-pages -d demo --remote origin"
|
"pages": "gh-pages -d demo --remote origin",
|
||||||
|
"demo": "http-server demo -c-1"
|
||||||
},
|
},
|
||||||
"husky": {
|
"husky": {
|
||||||
"hooks": {
|
"hooks": {
|
||||||
@@ -56,6 +57,7 @@
|
|||||||
"cross-env": "^6.0.3",
|
"cross-env": "^6.0.3",
|
||||||
"fancy-log": "^1.3.3",
|
"fancy-log": "^1.3.3",
|
||||||
"gh-pages": "^3.1.0",
|
"gh-pages": "^3.1.0",
|
||||||
|
"http-server": "^14.1.0",
|
||||||
"husky": "^3.0.9",
|
"husky": "^3.0.9",
|
||||||
"jest": "^24.9.0",
|
"jest": "^24.9.0",
|
||||||
"lint-staged": "^9.5.0",
|
"lint-staged": "^9.5.0",
|
||||||
|
|||||||
+2
-12
@@ -20,16 +20,6 @@ const plugins: rollup.Plugin[] = [
|
|||||||
commonjs(),
|
commonjs(),
|
||||||
typescript2({
|
typescript2({
|
||||||
tsconfig: path.join(__dirname, '..', 'tsconfig.json'),
|
tsconfig: path.join(__dirname, '..', 'tsconfig.json'),
|
||||||
typescript: ts, // ensure we're using the same typescript (3.x) for rollup as for regular builds etc
|
|
||||||
tsconfigOverride: {
|
|
||||||
module: 'esnext',
|
|
||||||
stripInternal: true,
|
|
||||||
emitDeclarationOnly: false,
|
|
||||||
composite: false,
|
|
||||||
declaration: false,
|
|
||||||
declarationMap: false,
|
|
||||||
sourceMap: false,
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -77,7 +67,7 @@ async function bundleAio() {
|
|||||||
uglify({
|
uglify({
|
||||||
compress: {
|
compress: {
|
||||||
drop_debugger: true,
|
drop_debugger: true,
|
||||||
drop_console: true,
|
drop_console: false,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@@ -86,7 +76,7 @@ async function bundleAio() {
|
|||||||
file: 'dist/index.min.js',
|
file: 'dist/index.min.js',
|
||||||
name: 'QrcodeDecoder',
|
name: 'QrcodeDecoder',
|
||||||
format: 'iife',
|
format: 'iife',
|
||||||
sourcemap: false,
|
sourcemap: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+18
-6
@@ -19,7 +19,8 @@ class QrcodeDecoder {
|
|||||||
this.videoElem = null;
|
this.videoElem = null;
|
||||||
this.getUserMediaHandler = null;
|
this.getUserMediaHandler = null;
|
||||||
this.videoConstraints = {
|
this.videoConstraints = {
|
||||||
video: true,
|
// default use rear camera
|
||||||
|
video: { facingMode: { exact: 'environment' } },
|
||||||
audio: false,
|
audio: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -160,10 +161,23 @@ class QrcodeDecoder {
|
|||||||
throw new Error("Couldn't get video from camera");
|
throw new Error("Couldn't get video from camera");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let stream: MediaStream;
|
||||||
try {
|
try {
|
||||||
const stream = await navigator.mediaDevices.getUserMedia(
|
stream = await navigator.mediaDevices.getUserMedia(this.videoConstraints);
|
||||||
this.videoConstraints,
|
} catch (e) {
|
||||||
);
|
if ((e as OverconstrainedError).name === 'OverconstrainedError') {
|
||||||
|
console.log('[OverconstrainedError] Can not use rear camera.');
|
||||||
|
|
||||||
|
stream = await navigator.mediaDevices.getUserMedia({
|
||||||
|
video: true,
|
||||||
|
audio: false,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stream) {
|
||||||
videoElem.srcObject = stream;
|
videoElem.srcObject = stream;
|
||||||
// videoElem.src = window.URL.createObjectURL(stream);
|
// videoElem.src = window.URL.createObjectURL(stream);
|
||||||
this.videoElem = videoElem;
|
this.videoElem = videoElem;
|
||||||
@@ -171,8 +185,6 @@ class QrcodeDecoder {
|
|||||||
|
|
||||||
const code = await this.decodeFromVideo(videoElem, opts);
|
const code = await this.decodeFromVideo(videoElem, opts);
|
||||||
return code;
|
return code;
|
||||||
} catch (e) {
|
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user