From ea404f8c543fbded271cd0d3b974a0d76b537206 Mon Sep 17 00:00:00 2001 From: John Beaumier Date: Fri, 15 Mar 2019 18:18:01 -0700 Subject: [PATCH] passing error back to decodeSingle through callbacks --- lib/input_stream.js | 12 ++++++------ lib/quagga.js | 29 ++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/lib/input_stream.js b/lib/input_stream.js index 8e481e8b..86d888d2 100644 --- a/lib/input_stream.js +++ b/lib/input_stream.js @@ -1,4 +1,4 @@ -const GetPixels = require("get-pixels"); +const getPixels = require("get-pixels"); var InputStream = {}; @@ -22,12 +22,12 @@ InputStream.createImageStream = function() { _topRight = {x: 0, y: 0}, _canvasSize = {x: 0, y: 0}; - function loadImages() { + function loadImages(callback) { loaded = false; - GetPixels(baseUrl, _config.mime, function(err, pixels) { + getPixels(baseUrl, _config.mime, function (err, pixels) { if (err) { console.log(err); - exit(1); + return callback(err); } loaded = true; console.log(pixels.shape); @@ -84,11 +84,11 @@ InputStream.createImageStream = function() { return height; }; - that.setInputStream = function(stream) { + that.setInputStream = function(stream, callback) { _config = stream; baseUrl = _config.src; size = 1; - loadImages(); + loadImages(callback); }; that.ended = function() { diff --git a/lib/quagga.js b/lib/quagga.js index 6ca71437..1b469640 100644 --- a/lib/quagga.js +++ b/lib/quagga.js @@ -3645,7 +3645,11 @@ function initInputStream(cb) { } _inputStream.setAttribute("preload", "auto"); - _inputStream.setInputStream(_config.inputStream); + _inputStream.setInputStream(_config.inputStream, function (err) { + if (err) { + cb(err); + } + }); _inputStream.addEventListener("canrecord", canRecord.bind(undefined, cb)); } @@ -3839,6 +3843,10 @@ function locateAndDecode() { function update() { var availableWorker; + if (!_framegrabber) { + return; + } + if (_onUIThread) { if (_workerPool.length > 0) { availableWorker = _workerPool.filter(function (workerThread) { @@ -4099,7 +4107,10 @@ exports.default = { halfSample: false } }, config); - this.init(config, function () { + this.init(config, function (err) { + if (err) { + return resultCallback.call(null); + } _events2.default.once("processed", function (result) { _this.stop(); resultCallback.call(null, result); @@ -4219,7 +4230,7 @@ module.exports = FrameGrabber; "use strict"; -var GetPixels = __webpack_require__(164); +var getPixels = __webpack_require__(164); var InputStream = {}; @@ -4243,13 +4254,13 @@ InputStream.createImageStream = function () { _topRight = { x: 0, y: 0 }, _canvasSize = { x: 0, y: 0 }; - function loadImages() { + function loadImages(callback) { loaded = false; - GetPixels(baseUrl, _config.mime, function (err, pixels) { + getPixels(baseUrl, _config.mime, function (err, pixels) { if (err) { - console.log(err); - exit(1); + return callback(err); } + loaded = true; console.log(pixels.shape); frame = pixels; @@ -4304,11 +4315,11 @@ InputStream.createImageStream = function () { return height; }; - that.setInputStream = function (stream) { + that.setInputStream = function (stream, callback) { _config = stream; baseUrl = _config.src; size = 1; - loadImages(); + loadImages(callback); }; that.ended = function () {