|
|
@ -1,33 +1,103 @@
|
|
|
|
$(function() {
|
|
|
|
$(function() {
|
|
|
|
var App = {
|
|
|
|
var App = {
|
|
|
|
init : function() {
|
|
|
|
init : function() {
|
|
|
|
Quagga.init({
|
|
|
|
Quagga.init(this.state, function() {
|
|
|
|
inputStream : {
|
|
|
|
|
|
|
|
name : "Live",
|
|
|
|
|
|
|
|
type : "LiveStream"
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
decoder : {
|
|
|
|
|
|
|
|
readers : ["ean_8_reader"]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, function() {
|
|
|
|
|
|
|
|
App.attachListeners();
|
|
|
|
App.attachListeners();
|
|
|
|
Quagga.start();
|
|
|
|
Quagga.start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
attachListeners: function() {
|
|
|
|
attachListeners: function() {
|
|
|
|
$(".controls .reader-group").on("change", "input", function(e) {
|
|
|
|
var self = this;
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
Quagga.setReaders([e.target.value + "_reader"]);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$(".controls").on("click", "button.stop", function(e) {
|
|
|
|
$(".controls").on("click", "button.stop", function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.preventDefault();
|
|
|
|
Quagga.stop();
|
|
|
|
Quagga.stop();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$(".controls .reader-config-group").on("change", "input, select", function(e) {
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
var $target = $(e.target),
|
|
|
|
|
|
|
|
value = $target.attr("type") === "checkbox" ? $target.prop("checked") : $target.val(),
|
|
|
|
|
|
|
|
name = $target.attr("name"),
|
|
|
|
|
|
|
|
state = self._convertNameToState(name);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log("Value of "+ state + " changed to " + value);
|
|
|
|
|
|
|
|
self.setState(state, value);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
_accessByPath: function(obj, path, val) {
|
|
|
|
|
|
|
|
var parts = path.split('.'),
|
|
|
|
|
|
|
|
depth = parts.length,
|
|
|
|
|
|
|
|
setter = (typeof val !== "undefined") ? true : false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return parts.reduce(function(o, key, i) {
|
|
|
|
|
|
|
|
if (setter && (i + 1) === depth) {
|
|
|
|
|
|
|
|
o[key] = val;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return key in o ? o[key] : {};
|
|
|
|
|
|
|
|
}, obj);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
_convertNameToState: function(name) {
|
|
|
|
|
|
|
|
return name.replace("_", ".").split("-").reduce(function(result, value) {
|
|
|
|
|
|
|
|
return result + value.charAt(0).toUpperCase() + value.substring(1);
|
|
|
|
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
detachListeners: function() {
|
|
|
|
detachListeners: function() {
|
|
|
|
$(".controls .reader-group").off("change", "input");
|
|
|
|
|
|
|
|
$(".controls").off("click", "button.stop");
|
|
|
|
$(".controls").off("click", "button.stop");
|
|
|
|
|
|
|
|
$(".controls .reader-config-group").off("change", "input, select");
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
setState: function(path, value) {
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof self._accessByPath(self.inputMapper, path) === "function") {
|
|
|
|
|
|
|
|
value = self._accessByPath(self.inputMapper, path)(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self._accessByPath(self.state, path, value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(JSON.stringify(self.state));
|
|
|
|
|
|
|
|
App.detachListeners();
|
|
|
|
|
|
|
|
Quagga.stop();
|
|
|
|
|
|
|
|
App.init();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
inputMapper: {
|
|
|
|
|
|
|
|
inputStream: {
|
|
|
|
|
|
|
|
constraints: function(value){
|
|
|
|
|
|
|
|
var values = value.split('x');
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
width: parseInt(values[0]),
|
|
|
|
|
|
|
|
height: parseInt(values[1]),
|
|
|
|
|
|
|
|
facing: "environment"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
numOfWorkers: function(value) {
|
|
|
|
|
|
|
|
return parseInt(value);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
decoder: {
|
|
|
|
|
|
|
|
readers: function(value) {
|
|
|
|
|
|
|
|
return [value + "_reader"];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
state: {
|
|
|
|
|
|
|
|
inputStream: {
|
|
|
|
|
|
|
|
type : "LiveStream",
|
|
|
|
|
|
|
|
constraints: {
|
|
|
|
|
|
|
|
width: 640,
|
|
|
|
|
|
|
|
height: 480,
|
|
|
|
|
|
|
|
facing: "environment" // or user
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
locator: {
|
|
|
|
|
|
|
|
patchSize: "medium",
|
|
|
|
|
|
|
|
halfSample: true
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
numOfWorkers: 4,
|
|
|
|
|
|
|
|
decoder: {
|
|
|
|
|
|
|
|
readers : ["ean_reader"]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
locate: true
|
|
|
|
},
|
|
|
|
},
|
|
|
|
lastResult : null
|
|
|
|
lastResult : null
|
|
|
|
};
|
|
|
|
};
|
|
|
|