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
+3134
-2845
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
+3152
-2861
File diff suppressed because one or more lines are too long
+1
-1
@@ -108,6 +108,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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-39
@@ -32,19 +32,24 @@ 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
|
||||||
.then((stream) => {
|
&& typeof navigator.mediaDevices.getUserMedia === 'function') {
|
||||||
return new Promise((resolve) => {
|
return navigator.mediaDevices
|
||||||
streamRef = stream;
|
.getUserMedia(constraints)
|
||||||
video.setAttribute("autoplay", 'true');
|
.then((stream) => {
|
||||||
video.srcObject = stream;
|
return new Promise((resolve) => {
|
||||||
video.addEventListener('loadedmetadata', () => {
|
streamRef = stream;
|
||||||
video.play();
|
video.setAttribute("autoplay", 'true');
|
||||||
resolve();
|
video.srcObject = stream;
|
||||||
});
|
video.addEventListener('loadedmetadata', () => {
|
||||||
});
|
video.play();
|
||||||
})
|
resolve();
|
||||||
.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) {
|
||||||
@@ -63,40 +68,16 @@ function deprecatedConstraints(videoConstraints) {
|
|||||||
return normalized;
|
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) {
|
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();
|
||||||
|
|||||||
@@ -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 () {
|
describe('release', function () {
|
||||||
it('should release the camera', function (done) {
|
it('should release the camera', function (done) {
|
||||||
CameraAccess.request(video, {})
|
CameraAccess.request(video, {})
|
||||||
|
|||||||
Reference in New Issue
Block a user