Updated webrtc-adapter; Removed workaround for Chrome

pull/131/head
Christoph Oberhofer 9 years ago
parent 9a91962027
commit 5e90f25b0b

6977
dist/quagga.js vendored

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 one or more lines are too long

@ -108,6 +108,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"
}
}

@ -32,19 +32,24 @@ function waitForVideo(video) {
* @param {Object} video
*/
function initCamera(video, constraints) {
return navigator.mediaDevices.getUserMedia(constraints)
.then((stream) => {
return new Promise((resolve) => {
streamRef = stream;
video.setAttribute("autoplay", 'true');
video.srcObject = stream;
video.addEventListener('loadedmetadata', () => {
video.play();
resolve();
});
});
})
.then(waitForVideo.bind(null, video));
if (navigator.mediaDevices
&& typeof navigator.mediaDevices.getUserMedia === 'function') {
return navigator.mediaDevices
.getUserMedia(constraints)
.then((stream) => {
return new Promise((resolve) => {
streamRef = stream;
video.setAttribute("autoplay", 'true');
video.srcObject = stream;
video.addEventListener('loadedmetadata', () => {
video.play();
resolve();
});
});
})
.then(waitForVideo.bind(null, video));
}
return Promise.reject(new Error('getUserMedia is not defined'));
}
function deprecatedConstraints(videoConstraints) {
@ -63,40 +68,16 @@ function deprecatedConstraints(videoConstraints) {
return normalized;
}
function applyCameraFacing(facing, constraints) {
if (typeof constraints.video.deviceId !== 'undefined' || !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();

@ -90,36 +90,6 @@ describe('success', function() {
});
});
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, {})

Loading…
Cancel
Save