mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-12 21:21:42 +08:00
Updated webrtc-adapter; Removed workaround for Chrome
This commit is contained in:
Vendored
+2736
-2447
File diff suppressed because one or more lines are too long
Vendored
+4
-3
File diff suppressed because one or more lines are too long
+2754
-2463
File diff suppressed because one or more lines are too long
+1
-1
@@ -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,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;
|
||||
@@ -46,6 +49,8 @@ function initCamera(video, constraints) {
|
||||
})
|
||||
.then(waitForVideo.bind(null, video));
|
||||
}
|
||||
return Promise.reject(new Error('getUserMedia is not defined'));
|
||||
}
|
||||
|
||||
function deprecatedConstraints(videoConstraints) {
|
||||
const normalized = pick(videoConstraints, ["width", "height", "facingMode",
|
||||
@@ -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, {})
|
||||
|
||||
Reference in New Issue
Block a user