|
|
@ -1,7 +1,6 @@
|
|
|
|
import {merge, pick} from 'lodash';
|
|
|
|
import {merge, pick} from 'lodash';
|
|
|
|
|
|
|
|
|
|
|
|
var streamRef,
|
|
|
|
var streamRef;
|
|
|
|
loadedDataHandler;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function waitForVideo(video) {
|
|
|
|
function waitForVideo(video) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
@ -35,13 +34,14 @@ function waitForVideo(video) {
|
|
|
|
function initCamera(video, constraints) {
|
|
|
|
function initCamera(video, constraints) {
|
|
|
|
return navigator.mediaDevices.getUserMedia(constraints)
|
|
|
|
return navigator.mediaDevices.getUserMedia(constraints)
|
|
|
|
.then((stream) => {
|
|
|
|
.then((stream) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
streamRef = stream;
|
|
|
|
streamRef = stream;
|
|
|
|
video.src = window.URL.createObjectURL(stream);
|
|
|
|
video.setAttribute("autoplay", 'true');
|
|
|
|
video.onloadedmetadata = (e) => {
|
|
|
|
video.srcObject = stream;
|
|
|
|
|
|
|
|
video.addEventListener('loadedmetadata', () => {
|
|
|
|
video.play();
|
|
|
|
video.play();
|
|
|
|
resolve();
|
|
|
|
resolve();
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.then(waitForVideo.bind(null, video));
|
|
|
|
.then(waitForVideo.bind(null, video));
|
|
|
@ -51,13 +51,13 @@ function deprecatedConstraints(videoConstraints) {
|
|
|
|
const normalized = pick(videoConstraints, ["width", "height", "facingMode",
|
|
|
|
const normalized = pick(videoConstraints, ["width", "height", "facingMode",
|
|
|
|
"aspectRatio", "deviceId"]);
|
|
|
|
"aspectRatio", "deviceId"]);
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof videoConstraints["minAspectRatio"] !== 'undefined' &&
|
|
|
|
if (typeof videoConstraints.minAspectRatio !== 'undefined' &&
|
|
|
|
videoConstraints["minAspectRatio"] > 0) {
|
|
|
|
videoConstraints.minAspectRatio > 0) {
|
|
|
|
normalized["aspectRatio"] = videoConstraints["minAspectRatio"];
|
|
|
|
normalized.aspectRatio = videoConstraints.minAspectRatio;
|
|
|
|
console.log("WARNING: Constraint 'minAspectRatio' is deprecated; Use 'aspectRatio' instead");
|
|
|
|
console.log("WARNING: Constraint 'minAspectRatio' is deprecated; Use 'aspectRatio' instead");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (typeof videoConstraints["facing"] !== 'undefined') {
|
|
|
|
if (typeof videoConstraints.facing !== 'undefined') {
|
|
|
|
normalized["facingMode"] = videoConstraints["facing"];
|
|
|
|
normalized.facingMode = videoConstraints.facing;
|
|
|
|
console.log("WARNING: Constraint 'facing' is deprecated. Use 'facingMode' instead'");
|
|
|
|
console.log("WARNING: Constraint 'facing' is deprecated. Use 'facingMode' instead'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return normalized;
|
|
|
|
return normalized;
|
|
|
@ -69,7 +69,7 @@ function applyCameraFacing(facing, constraints) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( typeof MediaStreamTrack !== 'undefined' &&
|
|
|
|
if ( typeof MediaStreamTrack !== 'undefined' &&
|
|
|
|
typeof MediaStreamTrack.getSources !== 'undefined') {
|
|
|
|
typeof MediaStreamTrack.getSources !== 'undefined') {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
MediaStreamTrack.getSources((sourceInfos) => {
|
|
|
|
MediaStreamTrack.getSources((sourceInfos) => {
|
|
|
|
const videoSource = sourceInfos.filter((sourceInfo) => (
|
|
|
|
const videoSource = sourceInfos.filter((sourceInfo) => (
|
|
|
|
sourceInfo.kind === "video" && sourceInfo.facing === facing
|
|
|
|
sourceInfo.kind === "video" && sourceInfo.facing === facing
|
|
|
|