mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-12 21:21:42 +08:00
Merge pull request #89 from davincho/master
Option for specifying an entry point for the video-element.
This commit is contained in:
@@ -120,11 +120,15 @@ may be the `inputStream.type` is set to `LiveStream`, but the browser does
|
|||||||
not support this API, or simply if the user denies the permission to use the
|
not support this API, or simply if the user denies the permission to use the
|
||||||
camera.
|
camera.
|
||||||
|
|
||||||
|
If you do not specify a target, QuaggaJS would look for an element that matches the CSS selector `#interactive.viewport` (for backwards compatibility).
|
||||||
|
`target` can be a string (CSS selector matching one of your DOM node) or a DOM node.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
Quagga.init({
|
Quagga.init({
|
||||||
inputStream : {
|
inputStream : {
|
||||||
name : "Live",
|
name : "Live",
|
||||||
type : "LiveStream"
|
type : "LiveStream",
|
||||||
|
target: document.querySelector('#yourElement') // Or '#yourElement' (optional)
|
||||||
},
|
},
|
||||||
decoder : {
|
decoder : {
|
||||||
readers : ["code_128_reader"]
|
readers : ["code_128_reader"]
|
||||||
|
|||||||
Vendored
+19
-10
File diff suppressed because one or more lines are too long
Vendored
+3
-3
File diff suppressed because one or more lines are too long
+19
-10
File diff suppressed because one or more lines are too long
+1
-1
@@ -12,6 +12,7 @@
|
|||||||
"chai": "^3.4.1",
|
"chai": "^3.4.1",
|
||||||
"core-js": "^1.2.1",
|
"core-js": "^1.2.1",
|
||||||
"grunt": "^0.4.5",
|
"grunt": "^0.4.5",
|
||||||
|
"grunt-cli": "0.1.13",
|
||||||
"grunt-contrib-nodeunit": "^0.4.1",
|
"grunt-contrib-nodeunit": "^0.4.1",
|
||||||
"grunt-karma": "^0.12.1",
|
"grunt-karma": "^0.12.1",
|
||||||
"isparta-loader": "^1.0.0",
|
"isparta-loader": "^1.0.0",
|
||||||
@@ -21,7 +22,6 @@
|
|||||||
"karma-coverage": "^0.5.2",
|
"karma-coverage": "^0.5.2",
|
||||||
"karma-mocha": "~0.2.0",
|
"karma-mocha": "~0.2.0",
|
||||||
"karma-phantomjs-launcher": "^0.2.1",
|
"karma-phantomjs-launcher": "^0.2.1",
|
||||||
"karma-sinon-chai": "^1.1.0",
|
|
||||||
"karma-sinon": "^1.0.4",
|
"karma-sinon": "^1.0.4",
|
||||||
"karma-sinon-chai": "~0.2.0",
|
"karma-sinon-chai": "~0.2.0",
|
||||||
"karma-source-map-support": "^1.1.0",
|
"karma-source-map-support": "^1.1.0",
|
||||||
|
|||||||
+15
-3
@@ -47,7 +47,7 @@ function initInputStream(cb) {
|
|||||||
} else if (_config.inputStream.type === "ImageStream") {
|
} else if (_config.inputStream.type === "ImageStream") {
|
||||||
_inputStream = InputStream.createImageStream();
|
_inputStream = InputStream.createImageStream();
|
||||||
} else if (_config.inputStream.type === "LiveStream") {
|
} else if (_config.inputStream.type === "LiveStream") {
|
||||||
var $viewport = document.querySelector("#interactive.viewport");
|
var $viewport = getViewPort();
|
||||||
if ($viewport) {
|
if ($viewport) {
|
||||||
video = $viewport.querySelector("video");
|
video = $viewport.querySelector("video");
|
||||||
if (!video) {
|
if (!video) {
|
||||||
@@ -71,9 +71,21 @@ function initInputStream(cb) {
|
|||||||
_inputStream.addEventListener("canrecord", canRecord.bind(undefined, cb));
|
_inputStream.addEventListener("canrecord", canRecord.bind(undefined, cb));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getViewPort() {
|
||||||
|
var target = _config.inputStream.target;
|
||||||
|
// Check if target is already a DOM element
|
||||||
|
if(target && target.nodeName && target.nodeType === 1) {
|
||||||
|
return target;
|
||||||
|
} else {
|
||||||
|
// Use '#interactive.viewport' as a fallback selector (backwards compatibility)
|
||||||
|
var selector = typeof target === 'string' ? target : '#interactive.viewport';
|
||||||
|
return document.querySelector(selector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function canRecord(cb) {
|
function canRecord(cb) {
|
||||||
BarcodeLocator.checkImageConstraints(_inputStream, _config.locator);
|
BarcodeLocator.checkImageConstraints(_inputStream, _config.locator);
|
||||||
initCanvas();
|
initCanvas(_config);
|
||||||
_framegrabber = FrameGrabber.create(_inputStream, _canvasContainer.dom.image);
|
_framegrabber = FrameGrabber.create(_inputStream, _canvasContainer.dom.image);
|
||||||
|
|
||||||
if (_config.numOfWorkers > 0) {
|
if (_config.numOfWorkers > 0) {
|
||||||
@@ -94,7 +106,7 @@ function ready(cb){
|
|||||||
|
|
||||||
function initCanvas() {
|
function initCanvas() {
|
||||||
if (typeof document !== "undefined") {
|
if (typeof document !== "undefined") {
|
||||||
var $viewport = document.querySelector("#interactive.viewport");
|
var $viewport = getViewPort();
|
||||||
_canvasContainer.dom.image = document.querySelector("canvas.imgBuffer");
|
_canvasContainer.dom.image = document.querySelector("canvas.imgBuffer");
|
||||||
if (!_canvasContainer.dom.image) {
|
if (!_canvasContainer.dom.image) {
|
||||||
_canvasContainer.dom.image = document.createElement("canvas");
|
_canvasContainer.dom.image = document.createElement("canvas");
|
||||||
|
|||||||
Reference in New Issue
Block a user