video working

This commit is contained in:
Christoph Oberhofer
2016-05-09 08:51:29 +02:00
committed by Christoph Oberhofer
parent f8bc6a705c
commit f1a963f4a0
3 changed files with 51 additions and 32 deletions
+28 -15
View File
@@ -48,42 +48,52 @@ function fromImage(config, imageSrc, inputConfig={}) {
};
}
/*function fromVideo(config, src) {
function fromVideo(config, source, inputConfig = {}) {
// remember last instance
// check if anything but the imagesrc has changed
//
let sourceConfig = {
type : "LiveStream",
type: "LiveStream",
constraints: {
width: 640,
height: 480,
facingMode: "environment"
}
};
if (source instanceof Stream) {
/*if (source instanceof MediaStream) {
// stream
} else if (source instanceof Element) {
} else*/ if (source instanceof Element) {
// video element
} else if (typeof source === 'string') {
// video source
} else if (typeof source === 'object') {
// additional constraints
} else if (typeof source === 'object'
&& (typeof source.constraints !== 'undefined'
|| typeof source.area !== 'undefined')) {
console.log("inputConfig");
inputConfig = source;
} else if (!source) {
// LiveStream
}
config = merge({inputStream: sourceConfig}, config);
config = merge({}, config, {inputStream: sourceConfig}, {inputStream: inputConfig});
console.log(config);
const scanner = createScanner();
return {
addEventListener: (eventType, cb) => {
this.init(config, () => {
start();
addEventListener(eventType, cb) {
scanner.init(config, (error) => {
if (error) {
console.log(error);
return;
}
scanner.start();
});
Events.subscribe(eventType, cb);
scanner.subscribe(eventType, cb);
},
removeEventListener: (cb) => {
Events.unsubscribe(eventType, cb);
removeEventListener(eventType, cb) {
scanner.unsubscribe(eventType, cb);
}
}
} */
};
}
let defaultScanner = createScanner();
@@ -97,6 +107,9 @@ function createApi(configuration = Config) {
fromImage(src, conf) {
return fromImage(configuration, src, conf);
},
fromVideo(src, inputConfig) {
return fromVideo(configuration, src, inputConfig);
},
decoder(conf) {
return setConfig(configuration, "decoder", conf);
},
+6
View File
@@ -498,6 +498,12 @@ function createScanner() {
pause: function() {
_stopped = true;
},
subscribe(eventName, callback) {
_events.subscribe(eventName, callback);
},
unsubscribe(eventName, callback) {
_events.unsubscribe(eventName, callback);
},
onDetected: function(callback) {
_events.subscribe("detected", callback);
},