Merged master

1.0 v1.0.0-beta.2
Christoph Oberhofer 9 years ago
commit 0cecadfd3a

@ -60,6 +60,11 @@ The following APIs need to be implemented in your browser:
In addition to the APIs mentioned above: In addition to the APIs mentioned above:
- [MediaDevices](http://caniuse.com/#feat=stream) - [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> ## <a name="installing">Installing</a>
QuaggaJS can be installed using __npm__, __bower__, or by including it with QuaggaJS can be installed using __npm__, __bower__, or by including it with

1829
dist/quagga.js vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

@ -1,6 +1,6 @@
{ {
"name": "quagga", "name": "quagga",
"version": "1.0.0-beta.1", "version": "1.0.0-beta.2",
"description": "An advanced barcode-scanner written in JavaScript", "description": "An advanced barcode-scanner written in JavaScript",
"main": "lib/quagga.js", "main": "lib/quagga.js",
"browser": "dist/quagga.min.js", "browser": "dist/quagga.min.js",
@ -109,6 +109,6 @@
"lodash": "^4.6.1", "lodash": "^4.6.1",
"ndarray": "^1.0.18", "ndarray": "^1.0.18",
"ndarray-linear-interpolate": "^1.0.0", "ndarray-linear-interpolate": "^1.0.0",
"webrtc-adapter": "^1.3.0" "webrtc-adapter": "^2.0.2"
} }
} }

@ -1,4 +1,4 @@
import {merge, pick, omit} from 'lodash'; import {pick} from 'lodash';
var streamRef; var streamRef;
@ -32,7 +32,10 @@ function waitForVideo(video) {
* @param {Object} video * @param {Object} video
*/ */
function initCamera(video, constraints) { function initCamera(video, constraints) {
return navigator.mediaDevices.getUserMedia(constraints) if (navigator.mediaDevices
&& typeof navigator.mediaDevices.getUserMedia === 'function') {
return navigator.mediaDevices
.getUserMedia(constraints)
.then((stream) => { .then((stream) => {
return new Promise((resolve) => { return new Promise((resolve) => {
streamRef = stream; streamRef = stream;
@ -46,6 +49,8 @@ function initCamera(video, constraints) {
}) })
.then(waitForVideo.bind(null, video)); .then(waitForVideo.bind(null, video));
} }
return Promise.reject(new Error('getUserMedia is not defined'));
}
function deprecatedConstraints(videoConstraints) { function deprecatedConstraints(videoConstraints) {
const normalized = pick(videoConstraints, ["width", "height", "facingMode", const normalized = pick(videoConstraints, ["width", "height", "facingMode",
@ -63,47 +68,16 @@ function deprecatedConstraints(videoConstraints) {
return normalized; 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) { function pickConstraints(videoConstraints) {
const constraints = { return {
audio: false, audio: false,
video: deprecatedConstraints(videoConstraints) video: deprecatedConstraints(videoConstraints)
}; };
return applyCameraFacing(constraints.video.facingMode, constraints);
} }
export default { export default {
request: function(video, videoConstraints) { request: function(video, videoConstraints) {
return pickConstraints(videoConstraints) return initCamera(video, pickConstraints(videoConstraints));
.then(initCamera.bind(null, video));
}, },
release: function() { release: function() {
var tracks = streamRef && streamRef.getVideoTracks(); var tracks = streamRef && streamRef.getVideoTracks();

@ -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) { it('should release the camera', function (done) {
CameraAccess.request(video, {}) CameraAccess.request(video, {})
.then(function () { .then(function () {
@ -133,7 +102,6 @@ describe("CameraAccess", () => {
}); });
}); });
}); });
});
describe('failure', function() { describe('failure', function() {
describe("permission denied", function(){ describe("permission denied", function(){

Loading…
Cancel
Save