Merge pull request #89 from davincho/master

Option for specifying an entry point for the video-element.
This commit is contained in:
Christoph Oberhofer
2016-02-15 21:04:57 +01:00
6 changed files with 63 additions and 29 deletions
+5 -1
View File
@@ -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"]
+19 -10
View File
File diff suppressed because one or more lines are too long
+3 -3
View File
File diff suppressed because one or more lines are too long
+19 -10
View File
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -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",
@@ -63,7 +63,7 @@
], ],
"author": "Christoph Oberhofer <ch.oberhofer@gmail.com>", "author": "Christoph Oberhofer <ch.oberhofer@gmail.com>",
"license": "MIT", "license": "MIT",
"engines":{ "engines": {
"node": ">= 4.0" "node": ">= 4.0"
}, },
"dependencies": { "dependencies": {
+15 -3
View File
@@ -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");