Merged master

This commit is contained in:
Christoph Oberhofer
2016-08-22 23:22:48 +02:00
9 changed files with 1547 additions and 2295 deletions
+5
View File
@@ -60,6 +60,11 @@ The following APIs need to be implemented in your browser:
In addition to the APIs mentioned above:
- [MediaDevices](http://caniuse.com/#feat=stream)
__Important:__ Accessing `getUserMedia` requires a secure origin in most
browsers, meaning that `http://` can only be used on `localhost`. All other
hostnames need to be served via `https://`. You can find more information in the
[Chrome M47 WebRTC Release Notes](https://groups.google.com/forum/#!topic/discuss-webrtc/sq5CVmY69sc).
## <a name="installing">Installing</a>
QuaggaJS can be installed using __npm__, __bower__, or by including it with
+740 -1087
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
File diff suppressed because one or more lines are too long
+4 -4
View File
File diff suppressed because one or more lines are too long
+743 -1091
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "quagga",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "An advanced barcode-scanner written in JavaScript",
"main": "lib/quagga.js",
"browser": "dist/quagga.min.js",
@@ -109,6 +109,6 @@
"lodash": "^4.6.1",
"ndarray": "^1.0.18",
"ndarray-linear-interpolate": "^1.0.0",
"webrtc-adapter": "^1.3.0"
"webrtc-adapter": "^2.0.2"
}
}
+9 -35
View File
@@ -1,4 +1,4 @@
import {merge, pick, omit} from 'lodash';
import {pick} from 'lodash';
var streamRef;
@@ -32,7 +32,10 @@ function waitForVideo(video) {
* @param {Object} video
*/
function initCamera(video, constraints) {
return navigator.mediaDevices.getUserMedia(constraints)
if (navigator.mediaDevices
&& typeof navigator.mediaDevices.getUserMedia === 'function') {
return navigator.mediaDevices
.getUserMedia(constraints)
.then((stream) => {
return new Promise((resolve) => {
streamRef = stream;
@@ -45,6 +48,8 @@ function initCamera(video, constraints) {
});
})
.then(waitForVideo.bind(null, video));
}
return Promise.reject(new Error('getUserMedia is not defined'));
}
function deprecatedConstraints(videoConstraints) {
@@ -63,47 +68,16 @@ function deprecatedConstraints(videoConstraints) {
return normalized;
}
function applyCameraFacing(facing, constraints) {
if (typeof constraints.video.deviceId === 'string' && constraints.video.deviceId.length > 0) {
return Promise.resolve({
...constraints,
video: {
...omit(constraints.video, "facingMode")
}
});
} else if (!facing) {
return Promise.resolve(constraints);
}
if ( typeof MediaStreamTrack !== 'undefined' &&
typeof MediaStreamTrack.getSources !== 'undefined') {
return new Promise((resolve) => {
MediaStreamTrack.getSources((sourceInfos) => {
const videoSource = sourceInfos.filter((sourceInfo) => (
sourceInfo.kind === "video" && sourceInfo.facing === facing
))[0];
if (videoSource) {
return resolve(merge({}, constraints,
{video: {deviceId: videoSource.id}}));
}
return resolve(constraints);
});
});
}
return Promise.resolve(merge({}, constraints, {video: {facingMode: facing}}));
}
function pickConstraints(videoConstraints) {
const constraints = {
return {
audio: false,
video: deprecatedConstraints(videoConstraints)
};
return applyCameraFacing(constraints.video.facingMode, constraints);
}
export default {
request: function(video, videoConstraints) {
return pickConstraints(videoConstraints)
.then(initCamera.bind(null, video));
return initCamera(video, pickConstraints(videoConstraints));
},
release: function() {
var tracks = streamRef && streamRef.getVideoTracks();
-32
View File
@@ -91,37 +91,6 @@ describe("CameraAccess", () => {
});
});
describe('facingMode fallback in Chrome', () => {
beforeEach(() => {
window.MediaStreamTrack.getSources = (cb) => {
return cb([
{kind: "video", facing: "environment", id: "environment"},
{kind: "audio", id: "audio"},
{kind: "video", facing: "user", id: "user"}
]);
};
});
afterEach(() => {
window.MediaStreamTrack = {};
});
it("should set deviceId in case facingMode is not supported", (done) => {
CameraAccess.request(video, {
facing: "user"
})
.then(function () {
const call = navigator.mediaDevices.getUserMedia.getCall(0),
args = call.args;
expect(call).to.be.defined;
expect(args[0].video.facingMode).not.to.be.defined;
expect(args[0].video.deviceId).to.equal("user");
done();
});
});
});
describe('release', function () {
it('should release the camera', function (done) {
CameraAccess.request(video, {})
.then(function () {
@@ -133,7 +102,6 @@ describe("CameraAccess", () => {
});
});
});
});
describe('failure', function() {
describe("permission denied", function(){