|
|
@ -5,13 +5,14 @@ import ImageDebug from './common/image_debug';
|
|
|
|
import ResultCollector from './analytics/result_collector';
|
|
|
|
import ResultCollector from './analytics/result_collector';
|
|
|
|
import Config from './config/config';
|
|
|
|
import Config from './config/config';
|
|
|
|
import {merge} from 'lodash';
|
|
|
|
import {merge} from 'lodash';
|
|
|
|
import {createConfigForImage} from './input/config_factory';
|
|
|
|
import CameraAccess from './input/camera_access';
|
|
|
|
import * as PixelCapture from './input/PixelCapture';
|
|
|
|
import * as PixelCapture from './input/PixelCapture';
|
|
|
|
import * as Source from './input/Source';
|
|
|
|
import * as Source from './input/Source';
|
|
|
|
|
|
|
|
|
|
|
|
function fromConfig(pixelCapturer, config) {
|
|
|
|
function fromConfig(pixelCapturer, config) {
|
|
|
|
const scanner = createScanner(pixelCapturer);
|
|
|
|
const scanner = createScanner(pixelCapturer);
|
|
|
|
const source = pixelCapturer.getSource();
|
|
|
|
const source = pixelCapturer.getSource();
|
|
|
|
|
|
|
|
let currentConfig = config;
|
|
|
|
let pendingStart = null;
|
|
|
|
let pendingStart = null;
|
|
|
|
let initialized = false;
|
|
|
|
let initialized = false;
|
|
|
|
return {
|
|
|
|
return {
|
|
|
@ -35,7 +36,7 @@ function fromConfig(pixelCapturer, config) {
|
|
|
|
return Promise.resolve(true);
|
|
|
|
return Promise.resolve(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pendingStart = new Promise((resolve, reject) => {
|
|
|
|
pendingStart = new Promise((resolve, reject) => {
|
|
|
|
scanner.init(config, (error) => {
|
|
|
|
scanner.init(currentConfig, (error) => {
|
|
|
|
if (error) {
|
|
|
|
if (error) {
|
|
|
|
console.log(error);
|
|
|
|
console.log(error);
|
|
|
|
reject(error);
|
|
|
|
reject(error);
|
|
|
@ -80,7 +81,7 @@ function fromConfig(pixelCapturer, config) {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
scanner.decodeSingle(config, (result) => {
|
|
|
|
scanner.decodeSingle(currentConfig, (result) => {
|
|
|
|
if (result && result.codeResult && result.codeResult.code) {
|
|
|
|
if (result && result.codeResult && result.codeResult.code) {
|
|
|
|
return resolve(result);
|
|
|
|
return resolve(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -95,6 +96,21 @@ function fromConfig(pixelCapturer, config) {
|
|
|
|
getCanvas() {
|
|
|
|
getCanvas() {
|
|
|
|
return pixelCapturer.getCanvas();
|
|
|
|
return pixelCapturer.getCanvas();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
applyConfig(newConfig) {
|
|
|
|
|
|
|
|
// during runtime?
|
|
|
|
|
|
|
|
// running scanners must know that!
|
|
|
|
|
|
|
|
// apply constraints to source, only if changed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const normalizedConfig = merge({}, Config, newConfig);
|
|
|
|
|
|
|
|
this.stop();
|
|
|
|
|
|
|
|
currentConfig = normalizedConfig;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return source.applyConstraints(currentConfig.constraints)
|
|
|
|
|
|
|
|
.then(() => this.start());
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
getSource() {
|
|
|
|
|
|
|
|
return pixelCapturer.getSource();
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -116,6 +132,12 @@ function createApi() {
|
|
|
|
.fromImage(image, config.constraints)
|
|
|
|
.fromImage(image, config.constraints)
|
|
|
|
.then(fromSource.bind(null, config));
|
|
|
|
.then(fromSource.bind(null, config));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
fromCamera(options) {
|
|
|
|
|
|
|
|
const config = merge({}, Config, options);
|
|
|
|
|
|
|
|
return Source
|
|
|
|
|
|
|
|
.fromCamera(config.constraints)
|
|
|
|
|
|
|
|
.then(fromSource.bind(null, config));
|
|
|
|
|
|
|
|
},
|
|
|
|
fromSource(src, inputConfig) {
|
|
|
|
fromSource(src, inputConfig) {
|
|
|
|
return fromSource(configuration, src, inputConfig);
|
|
|
|
return fromSource(configuration, src, inputConfig);
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -134,6 +156,7 @@ function createApi() {
|
|
|
|
config(conf) {
|
|
|
|
config(conf) {
|
|
|
|
return createApi(merge({}, configuration, conf));
|
|
|
|
return createApi(merge({}, configuration, conf));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
CameraAccess,
|
|
|
|
ImageWrapper,
|
|
|
|
ImageWrapper,
|
|
|
|
ImageDebug,
|
|
|
|
ImageDebug,
|
|
|
|
ResultCollector,
|
|
|
|
ResultCollector,
|
|
|
|