Fix switching to native webcam

This commit is contained in:
afiq.hamzah
2023-05-25 15:23:15 +08:00
parent 82e631a5d1
commit cb60ab955c
+20 -26
View File
@@ -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) {
@@ -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 });
}
}