Fix switching to native webcam
This commit is contained in:
Vendored
+22
-28
@@ -18,13 +18,20 @@ function marhunPhotoCapturerFactory(modal_selector) {
|
||||
let canvas = document.createElement('canvas');
|
||||
|
||||
let captureImage = () => {
|
||||
let videoTag = modal.querySelector('.video-tag-overallmarhun.video-data');
|
||||
return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
let modal = document.querySelector(modal_selector);
|
||||
let videoTag = modal.querySelector('.video-tag-overallmarhun.video-data');
|
||||
canvas.width = 3200;
|
||||
canvas.height = 1800;
|
||||
|
||||
let isfirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
|
||||
if (isfirefox) {
|
||||
canvas.width = 1280;
|
||||
canvas.height = 720;
|
||||
}
|
||||
|
||||
|
||||
canvas.getContext("2d").drawImage(videoTag, 0, 0, canvas.width, canvas.height)
|
||||
resolve(canvas);
|
||||
} catch (error) {
|
||||
@@ -91,9 +98,9 @@ function marhunPhotoCapturerFactory(modal_selector) {
|
||||
|
||||
getCamera: function () {
|
||||
function getCameraList() {
|
||||
let getUserMedia = () => navigator.mediaDevices.getUserMedia({ video: {width: 3256, height: 2440} });
|
||||
let getUserMedia = () => navigator.mediaDevices.getUserMedia({ video: { width: 3256, height: 2440 } });
|
||||
|
||||
let enumerateDevices = () => navigator.mediaDevices.enumerateDevices()
|
||||
let enumerateDevices = () => navigator.mediaDevices.enumerateDevices()
|
||||
.then(devices => devices.filter(x => x.kind === 'videoinput'))
|
||||
getUserMedia();
|
||||
|
||||
@@ -125,22 +132,6 @@ function marhunPhotoCapturerFactory(modal_selector) {
|
||||
return marhun_camera_config_chrome.includes(camera.label);
|
||||
})
|
||||
|
||||
const filteredCameraFirefox = available_cameras.filter(camera => {
|
||||
return marhun_camera_config_firefox.includes(camera.deviceId);
|
||||
});
|
||||
|
||||
|
||||
let isfirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
|
||||
if (isfirefox) {
|
||||
|
||||
if (filteredCameraFirefox.length > 0) {
|
||||
return filteredCameraFirefox.splice(-1);
|
||||
}
|
||||
|
||||
const filteredCameraFirefoxLastDevice = available_cameras.splice(-1);
|
||||
return filteredCameraFirefoxLastDevice;
|
||||
}
|
||||
|
||||
// Get the first available priority referencing to env
|
||||
return filteredCameraChrome.at(-1);
|
||||
}
|
||||
@@ -156,22 +147,25 @@ function marhunPhotoCapturerFactory(modal_selector) {
|
||||
}
|
||||
|
||||
function composeConstraint(camera) {
|
||||
let constraints = null;
|
||||
|
||||
let constraints = {
|
||||
width: { min: 1280, max: 3200 },
|
||||
height: { min: 720, max: 1800 },
|
||||
aspectRatio: {exact: 1.7777777778},
|
||||
constraints = {
|
||||
width: { exact: 3200 },
|
||||
height: { exact: 1800 },
|
||||
};
|
||||
|
||||
let isfirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
|
||||
if (isfirefox) {
|
||||
constraints = {
|
||||
width: { exact: 1280 },
|
||||
height: { exact: 720 },
|
||||
};
|
||||
}
|
||||
|
||||
if (camera.deviceId !== '') {
|
||||
constraints.deviceId = { exact: camera.deviceId };
|
||||
return navigator.mediaDevices.getUserMedia({ video: constraints });
|
||||
}
|
||||
|
||||
|
||||
if (camera.groupId !== '') {
|
||||
constraints.groupId = { exact: camera.groudId };
|
||||
return navigator.mediaDevices.getUserMedia({ video: constraints });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user