feat(settings): option to show/hide camera button, preview click opens camera
This commit is contained in:
+24
-1
@@ -15,6 +15,7 @@ const camCanvas = document.getElementById('camCanvas');
|
||||
const camModal = document.getElementById('camModal');
|
||||
let capturedBlob = null;
|
||||
let stream = null;
|
||||
let camOpening = false;
|
||||
const descInput = document.getElementById('descInput');
|
||||
const filesInput = document.getElementById('filesInput');
|
||||
const filesList = document.getElementById('filesList');
|
||||
@@ -318,6 +319,10 @@ async function resolveModuleId(name) {
|
||||
if (Number.isFinite(h) && h >= 120 && h <= 4096) captureHeight = h;
|
||||
const q = parseFloat(f.photo_capture_quality);
|
||||
if (Number.isFinite(q) && q >= 0.5 && q <= 1) captureQuality = q;
|
||||
if (f.camera_enabled === 'false') {
|
||||
const camBtns = document.getElementById('camBtns');
|
||||
if (camBtns) camBtns.style.display = 'none';
|
||||
}
|
||||
} catch (e) { /* ignore */ }
|
||||
checkPreviousSend();
|
||||
})();
|
||||
@@ -336,12 +341,22 @@ function removePhoto() {
|
||||
}
|
||||
|
||||
async function openCam() {
|
||||
if (camOpening) return;
|
||||
if (stream && camModal.classList.contains('open')) return;
|
||||
camOpening = true;
|
||||
try {
|
||||
stream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: 'user', width: { ideal: captureWidth }, height: { ideal: captureHeight } } });
|
||||
const s = await navigator.mediaDevices.getUserMedia({ video: { facingMode: 'user', width: { ideal: captureWidth }, height: { ideal: captureHeight } } });
|
||||
if (camModal.classList.contains('open')) {
|
||||
s.getTracks().forEach(t => t.stop());
|
||||
return;
|
||||
}
|
||||
stream = s;
|
||||
camVideo.srcObject = stream;
|
||||
camModal.classList.add('open');
|
||||
} catch (e) {
|
||||
alert('Не удалось открыть камеру: ' + e.message);
|
||||
} finally {
|
||||
camOpening = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,6 +366,10 @@ function closeCam() {
|
||||
}
|
||||
|
||||
function capture() {
|
||||
if (!camVideo.videoWidth || !camVideo.videoHeight) {
|
||||
notify('Камера ещё не готова, попробуйте через секунду', true);
|
||||
return;
|
||||
}
|
||||
camCanvas.width = camVideo.videoWidth;
|
||||
camCanvas.height = camVideo.videoHeight;
|
||||
const ctx = camCanvas.getContext('2d');
|
||||
@@ -420,6 +439,10 @@ form.addEventListener('submit', async (e) => {
|
||||
|
||||
removePhotoBtn.addEventListener('click', removePhoto);
|
||||
document.getElementById('openCamBtn').addEventListener('click', openCam);
|
||||
preview.addEventListener('click', openCam);
|
||||
preview.addEventListener('keydown', e => {
|
||||
if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); openCam(); }
|
||||
});
|
||||
filesClearBtn.addEventListener('click', clearFiles);
|
||||
document.getElementById('filesBtn').addEventListener('click', () => document.getElementById('filesInput').click());
|
||||
document.getElementById('cancelCamBtn').addEventListener('click', closeCam);
|
||||
|
||||
Reference in New Issue
Block a user