Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New option for livestream #89

Merged
merged 6 commits into from
Feb 15, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions dist/quagga.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/quagga.min.js

Large diffs are not rendered by default.

29 changes: 19 additions & 10 deletions lib/quagga.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"chai": "^3.4.1",
"core-js": "^1.2.1",
"grunt": "^0.4.5",
"grunt-cli": "0.1.13",
"grunt-contrib-nodeunit": "^0.4.1",
"grunt-karma": "^0.12.1",
"isparta-loader": "^1.0.0",
Expand All @@ -21,7 +22,6 @@
"karma-coverage": "^0.5.2",
"karma-mocha": "~0.2.0",
"karma-phantomjs-launcher": "^0.2.1",
"karma-sinon-chai": "^1.1.0",
"karma-sinon": "^1.0.4",
"karma-sinon-chai": "~0.2.0",
"karma-source-map-support": "^1.1.0",
Expand Down Expand Up @@ -63,7 +63,7 @@
],
"author": "Christoph Oberhofer <[email protected]>",
"license": "MIT",
"engines":{
"engines": {
"node": ">= 4.0"
},
"dependencies": {
Expand Down
22 changes: 18 additions & 4 deletions src/quagga.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ function initInputStream(cb) {
} else if (_config.inputStream.type === "ImageStream") {
_inputStream = InputStream.createImageStream();
} else if (_config.inputStream.type === "LiveStream") {
var $viewport = document.querySelector("#interactive.viewport");

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the unused witespace

var $viewport = getViewPort(_config);

if ($viewport) {
video = $viewport.querySelector("video");
if (!video) {
Expand All @@ -71,9 +73,21 @@ function initInputStream(cb) {
_inputStream.addEventListener("canrecord", canRecord.bind(undefined, cb));
}

function getViewPort(_config) {
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) {
BarcodeLocator.checkImageConstraints(_inputStream, _config.locator);
initCanvas();
initCanvas(_config);
_framegrabber = FrameGrabber.create(_inputStream, _canvasContainer.dom.image);

if (_config.numOfWorkers > 0) {
Expand All @@ -92,9 +106,9 @@ function ready(cb){
cb();
}

function initCanvas() {
function initCanvas(_config) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of passing in the _config parameter, you could also use the global one (see L51)

if (typeof document !== "undefined") {
var $viewport = document.querySelector("#interactive.viewport");
var $viewport = getViewPort(_config);
_canvasContainer.dom.image = document.querySelector("canvas.imgBuffer");
if (!_canvasContainer.dom.image) {
_canvasContainer.dom.image = document.createElement("canvas");
Expand Down