-
Notifications
You must be signed in to change notification settings - Fork 980
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
Changes from 3 commits
3f12bfb
893a3bc
3c85675
944d92c
6338aad
a16d398
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
|
@@ -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", | ||
|
@@ -63,7 +63,7 @@ | |
], | ||
"author": "Christoph Oberhofer <[email protected]>", | ||
"license": "MIT", | ||
"engines":{ | ||
"engines": { | ||
"node": ">= 4.0" | ||
}, | ||
"dependencies": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"); | ||
|
||
var $viewport = getViewPort(_config); | ||
|
||
if ($viewport) { | ||
video = $viewport.querySelector("video"); | ||
if (!video) { | ||
|
@@ -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) { | ||
|
@@ -92,9 +106,9 @@ function ready(cb){ | |
cb(); | ||
} | ||
|
||
function initCanvas() { | ||
function initCanvas(_config) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of passing in the |
||
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"); | ||
|
There was a problem hiding this comment.
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