feat(scanner): transform barcode scanner into continuous live camera stream with instant redirect
This commit is contained in:
@@ -546,93 +546,75 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{-- MODAL 3: IN-APP CAMERA SCANNER QR CODE / BARCODE UNIT LV --}}
|
{{-- MODAL 3: IN-APP LIVE QR/BARCODE SCANNER UNIT (LANGSUNG LIVE STREAMING KAMERA KE FORM) --}}
|
||||||
<div id="unitQrScannerModal"
|
<div id="unitQrScannerModal"
|
||||||
onclick="if(event.target === this) closeUnitQrScannerModal()"
|
onclick="if(event.target === this) closeUnitQrScannerModal()"
|
||||||
class="hidden fixed inset-0 z-50 bg-slate-900/70 backdrop-blur-xs flex items-center justify-center p-4 overflow-y-auto"
|
class="hidden fixed inset-0 z-50 bg-slate-900/80 backdrop-blur-xs flex items-center justify-center p-4 overflow-y-auto"
|
||||||
aria-labelledby="qr-scanner-title" role="dialog" aria-modal="true">
|
aria-labelledby="qr-scanner-title" role="dialog" aria-modal="true">
|
||||||
<div class="relative z-10 bg-white rounded-2xl text-left overflow-hidden shadow-2xl transform transition-all my-8 max-w-md w-full border border-slate-200 animate-scale-in">
|
<div class="relative z-10 bg-slate-900 rounded-3xl text-left overflow-hidden shadow-2xl transform transition-all my-8 max-w-md w-full border border-slate-800 animate-scale-in text-white">
|
||||||
<!-- Input File Tersembunyi untuk Kamera Native HP & Galeri -->
|
<!-- Input File Tersembunyi (Hanya sebagai fallback darurat) -->
|
||||||
<input type="file" id="qrNativeCameraInput" accept="image/*" capture="environment" class="hidden" onchange="handleQrFileSelected(event)">
|
<input type="file" id="qrNativeCameraInput" accept="image/*" capture="environment" class="hidden" onchange="handleQrFileSelected(event)">
|
||||||
<input type="file" id="qrGalleryInput" accept="image/*" class="hidden" onchange="handleQrFileSelected(event)">
|
<input type="file" id="qrGalleryInput" accept="image/*" class="hidden" onchange="handleQrFileSelected(event)">
|
||||||
|
|
||||||
<!-- Header Modal Scanner -->
|
<!-- Header Modal Scanner Modern -->
|
||||||
<div class="p-4 bg-slate-900 text-white flex items-center justify-between">
|
<div class="p-4 bg-slate-900 border-b border-slate-800 flex items-center justify-between">
|
||||||
<div class="flex items-center space-x-2.5">
|
<div class="flex items-center space-x-3">
|
||||||
<div class="w-8 h-8 rounded-lg bg-emerald-500/20 text-emerald-400 flex items-center justify-center text-sm flex-shrink-0">
|
<div class="w-9 h-9 rounded-xl bg-emerald-500/20 text-emerald-400 flex items-center justify-center text-sm flex-shrink-0">
|
||||||
<i class="fa-solid fa-qrcode"></i>
|
<i class="fa-solid fa-barcode"></i>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<h3 id="qr-scanner-title" class="font-bold text-sm text-white">Scan Barcode Unit Mobil</h3>
|
<h3 id="qr-scanner-title" class="font-extrabold text-sm text-white">Live Scanner Barcode Unit</h3>
|
||||||
<p class="text-[11px] text-slate-400">Arahkan kamera ke stiker barcode di kaca unit</p>
|
<p class="text-[11px] text-slate-400">Arahkan kamera langsung ke stiker barcode/QR unit</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button type="button" onclick="closeUnitQrScannerModal()" class="text-slate-400 hover:text-white p-1 rounded-lg hover:bg-slate-800 transition cursor-pointer">
|
<button type="button" onclick="closeUnitQrScannerModal()" class="w-8 h-8 rounded-full bg-slate-800 hover:bg-slate-700 text-slate-400 hover:text-white flex items-center justify-center transition cursor-pointer">
|
||||||
<i class="fa-solid fa-xmark text-base"></i>
|
<i class="fa-solid fa-xmark text-sm"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Tombol Aksi Cepat Kamera HP Native (Selalu Bisa Digunakan di HTTP maupun HTTPS) -->
|
<!-- Viewport Kamera Live dengan Efek Scanner Viewfinder -->
|
||||||
<div class="px-4 py-2.5 bg-slate-800 border-b border-slate-700/60 flex items-center justify-between gap-2">
|
<div class="relative bg-black flex flex-col items-center justify-center overflow-hidden min-h-[340px]">
|
||||||
<button type="button"
|
<!-- Kontainer Video Html5Qrcode -->
|
||||||
onclick="document.getElementById('qrNativeCameraInput').click()"
|
<div id="qr-reader" class="w-full"></div>
|
||||||
class="flex-1 bg-emerald-600 hover:bg-emerald-500 text-white font-bold py-2 px-3 rounded-xl text-xs transition flex items-center justify-center space-x-1.5 shadow-sm cursor-pointer">
|
|
||||||
<i class="fa-solid fa-camera text-sm"></i>
|
|
||||||
<span>Ambil Foto Barcode (Kamera HP)</span>
|
|
||||||
</button>
|
|
||||||
<button type="button"
|
|
||||||
onclick="document.getElementById('qrGalleryInput').click()"
|
|
||||||
class="bg-slate-700 hover:bg-slate-600 text-slate-200 font-semibold py-2 px-3 rounded-xl text-xs transition flex items-center justify-center space-x-1 cursor-pointer"
|
|
||||||
title="Pilih gambar dari galeri">
|
|
||||||
<i class="fa-solid fa-image"></i>
|
|
||||||
<span>Galeri</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Area Viewport Kamera -->
|
<!-- Viewfinder Overlay (Corner Brackets & Laser Scan Line) -->
|
||||||
<div class="p-4 bg-slate-950 flex flex-col items-center justify-center relative min-h-[300px]">
|
<div id="qrScanOverlay" class="absolute inset-0 pointer-events-none flex items-center justify-center">
|
||||||
<div id="qr-reader" class="w-full rounded-xl overflow-hidden bg-black"></div>
|
<div class="relative w-64 h-64 border border-emerald-500/25 rounded-2xl">
|
||||||
|
<!-- Corner Highlights -->
|
||||||
|
<div class="absolute -top-1 -left-1 w-6 h-6 border-t-3 border-l-3 border-emerald-400 rounded-tl-xl"></div>
|
||||||
|
<div class="absolute -top-1 -right-1 w-6 h-6 border-t-3 border-r-3 border-emerald-400 rounded-tr-xl"></div>
|
||||||
|
<div class="absolute -bottom-1 -left-1 w-6 h-6 border-b-3 border-l-3 border-emerald-400 rounded-bl-xl"></div>
|
||||||
|
<div class="absolute -bottom-1 -right-1 w-6 h-6 border-b-3 border-r-3 border-emerald-400 rounded-br-xl"></div>
|
||||||
|
|
||||||
|
<!-- Animated Laser Sweep Line -->
|
||||||
|
<div class="scanner-laser-line"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Loading Indicator Live Video -->
|
<!-- Loading Indicator Live Video -->
|
||||||
<div id="qrScannerLoading" class="absolute inset-0 flex flex-col items-center justify-center bg-slate-950/95 text-white space-y-2.5 z-20">
|
<div id="qrScannerLoading" class="absolute inset-0 flex flex-col items-center justify-center bg-slate-950/90 text-white space-y-3 z-20">
|
||||||
<i class="fa-solid fa-circle-notch fa-spin text-2xl text-emerald-500"></i>
|
<i class="fa-solid fa-circle-notch fa-spin text-3xl text-emerald-400"></i>
|
||||||
<span class="text-xs text-slate-300 font-medium">Menghubungkan ke live kamera perangkat...</span>
|
<span class="text-xs text-slate-200 font-bold">Membuka Kamera Live...</span>
|
||||||
|
<span class="text-[11px] text-slate-400">Pastikan izin kamera diizinkan di peramban</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Loading Indicator Analisis File / Foto -->
|
<!-- Loading Indicator Analisis Foto (Fallback) -->
|
||||||
<div id="qrScannerFileLoadingOverlay" class="hidden absolute inset-0 flex flex-col items-center justify-center bg-slate-950/95 text-white space-y-3 z-30 p-4 text-center">
|
<div id="qrScannerFileLoadingOverlay" class="hidden absolute inset-0 flex flex-col items-center justify-center bg-slate-950/95 text-white space-y-3 z-30 p-4 text-center">
|
||||||
<i class="fa-solid fa-spinner fa-spin text-3xl text-emerald-400"></i>
|
<i class="fa-solid fa-spinner fa-spin text-3xl text-emerald-400"></i>
|
||||||
<span class="text-xs text-slate-200 font-bold">Membaca Barcode dari Foto...</span>
|
<span class="text-xs text-slate-200 font-bold">Membaca Barcode dari Foto...</span>
|
||||||
<span class="text-[11px] text-slate-400">Mohon tunggu beberapa detik</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Tampilan Khusus Akses Non-Secure (HTTP) -->
|
<!-- Error State / Izin Kamera Ditolak / HTTP Limitation -->
|
||||||
<div id="qrScannerHttpNotice" class="hidden absolute inset-0 p-5 flex flex-col items-center justify-center bg-slate-950 text-center text-white space-y-3 z-25">
|
<div id="qrScannerError" class="hidden absolute inset-0 p-6 flex flex-col items-center justify-center bg-slate-950/95 text-center text-white space-y-3.5 z-25">
|
||||||
<div class="w-12 h-12 rounded-full bg-amber-500/20 text-amber-400 flex items-center justify-center text-xl">
|
<div class="w-12 h-12 rounded-full bg-amber-500/20 text-amber-400 flex items-center justify-center text-xl">
|
||||||
<i class="fa-solid fa-camera"></i>
|
<i class="fa-solid fa-triangle-exclamation"></i>
|
||||||
</div>
|
</div>
|
||||||
<h4 class="font-bold text-sm text-amber-200">Mode Kamera HP Siap</h4>
|
<h4 class="font-bold text-sm text-amber-200" id="qrScannerErrorTitle">Kamera Live Memerlukan Izin / HTTPS</h4>
|
||||||
<p class="text-xs text-slate-300 leading-relaxed max-w-xs">
|
<p class="text-xs text-slate-300 leading-relaxed max-w-xs" id="qrScannerErrorMsg">
|
||||||
Peramban membatasi streaming video langsung karena alamat web diakses lewat <strong>HTTP</strong>.<br>
|
Peramban membatasi streaming video langsung. Silakan gunakan tombol jepret foto di bawah atau izinkan akses kamera di setelan browser.
|
||||||
Klik tombol di bawah ini untuk membuka kamera ponsel Anda dan jepret barcode!
|
|
||||||
</p>
|
</p>
|
||||||
<button type="button"
|
|
||||||
onclick="document.getElementById('qrNativeCameraInput').click()"
|
|
||||||
class="w-full max-w-xs bg-emerald-600 hover:bg-emerald-500 text-white font-bold py-2.5 px-4 rounded-xl text-xs shadow-md transition flex items-center justify-center space-x-2 cursor-pointer">
|
|
||||||
<i class="fa-solid fa-camera"></i>
|
|
||||||
<span>Jepret Foto Barcode Sekarang</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Error State (Izin Kamera ditolak / tidak tersedia) -->
|
<div class="w-full space-y-2 pt-2 max-w-xs">
|
||||||
<div id="qrScannerError" class="hidden absolute inset-0 p-6 flex flex-col items-center justify-center bg-slate-950 text-center text-white space-y-3 z-25">
|
|
||||||
<div class="w-12 h-12 rounded-full bg-rose-500/20 text-rose-400 flex items-center justify-center text-xl">
|
|
||||||
<i class="fa-solid fa-video-slash"></i>
|
|
||||||
</div>
|
|
||||||
<h4 class="font-bold text-sm text-rose-200">Live Kamera Tidak Terbuka</h4>
|
|
||||||
<p class="text-xs text-slate-300 leading-relaxed" id="qrScannerErrorMsg">Izin akses kamera belum diaktifkan di peramban browser.</p>
|
|
||||||
|
|
||||||
<div class="w-full space-y-2 pt-1 max-w-xs">
|
|
||||||
<button type="button"
|
<button type="button"
|
||||||
onclick="document.getElementById('qrNativeCameraInput').click()"
|
onclick="document.getElementById('qrNativeCameraInput').click()"
|
||||||
class="w-full bg-emerald-600 hover:bg-emerald-500 text-white font-bold py-2.5 px-4 rounded-xl text-xs shadow-md transition flex items-center justify-center space-x-2 cursor-pointer">
|
class="w-full bg-emerald-600 hover:bg-emerald-500 text-white font-bold py-2.5 px-4 rounded-xl text-xs shadow-md transition flex items-center justify-center space-x-2 cursor-pointer">
|
||||||
@@ -650,26 +632,41 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Overlay Sukses Terdeteksi -->
|
<!-- Overlay Sukses Terdeteksi (Instan) -->
|
||||||
<div id="qrScannerSuccessOverlay" class="hidden absolute inset-0 flex flex-col items-center justify-center bg-emerald-950/90 text-white space-y-2 z-40">
|
<div id="qrScannerSuccessOverlay" class="hidden absolute inset-0 flex flex-col items-center justify-center bg-emerald-950/95 text-white space-y-3 z-40 animate-fade-in">
|
||||||
<div class="w-12 h-12 rounded-full bg-emerald-500/20 text-emerald-400 flex items-center justify-center text-xl">
|
<div class="w-14 h-14 rounded-full bg-emerald-500 text-slate-950 flex items-center justify-center text-2xl shadow-lg">
|
||||||
<i class="fa-solid fa-circle-check"></i>
|
<i class="fa-solid fa-check"></i>
|
||||||
|
</div>
|
||||||
|
<div class="text-center">
|
||||||
|
<h4 class="text-sm font-black text-emerald-300" id="qrScannedUnitCode">Barcode Terdeteksi!</h4>
|
||||||
|
<p class="text-[11px] text-slate-300 mt-0.5">Membuka formulir timesheet unit...</p>
|
||||||
</div>
|
</div>
|
||||||
<span class="text-sm font-bold text-emerald-200">Unit Terdeteksi! Membuka Timesheet...</span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Footer / Opsi Manual -->
|
<!-- Bar Kontrol Bawah: Switch Kamera & Opsi Darurat -->
|
||||||
<div class="p-3.5 bg-slate-50 border-t border-slate-100 flex items-center justify-between gap-2">
|
<div class="p-3 bg-slate-900 border-t border-slate-800 flex items-center justify-between text-xs">
|
||||||
<span class="text-[11px] text-slate-500 flex items-center">
|
<!-- Tombol Switch Kamera Depan/Belakang -->
|
||||||
<i class="fa-solid fa-circle-info text-emerald-600 mr-1.5"></i>
|
<button type="button"
|
||||||
Kamera buram / kendala scan?
|
id="btnSwitchCamera"
|
||||||
</span>
|
onclick="switchCamera()"
|
||||||
<a href="{{ route('timesheet.index') }}" class="text-xs font-bold text-[#1b5e20] hover:text-[#144918] hover:underline flex-shrink-0">
|
class="hidden items-center space-x-1.5 px-3 py-1.5 rounded-lg bg-slate-800 hover:bg-slate-700 text-slate-300 font-semibold transition cursor-pointer">
|
||||||
Pilih Manual dari Katalog →
|
<i class="fa-solid fa-camera-rotate text-emerald-400"></i>
|
||||||
|
<span>Ganti Kamera</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<!-- Link Darurat Manual / Galeri -->
|
||||||
|
<div class="flex items-center space-x-3 ml-auto text-slate-400 text-[11px]">
|
||||||
|
<button type="button" onclick="document.getElementById('qrGalleryInput').click()" class="hover:text-emerald-400 font-semibold transition cursor-pointer">
|
||||||
|
<i class="fa-solid fa-image mr-1"></i> Dari Galeri
|
||||||
|
</button>
|
||||||
|
<span class="text-slate-700">•</span>
|
||||||
|
<a href="{{ route('timesheet.index') }}" class="hover:text-emerald-400 font-semibold transition">
|
||||||
|
Pilih Manual →
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{-- MODAL 4: NOTIFIKASI HASIL VALIDASI POS GERBANG (POLLING REAL-TIME) --}}
|
{{-- MODAL 4: NOTIFIKASI HASIL VALIDASI POS GERBANG (POLLING REAL-TIME) --}}
|
||||||
@@ -723,18 +720,37 @@
|
|||||||
<style>
|
<style>
|
||||||
#qr-reader {
|
#qr-reader {
|
||||||
border: none !important;
|
border: none !important;
|
||||||
|
width: 100% !important;
|
||||||
}
|
}
|
||||||
#qr-reader video {
|
#qr-reader video {
|
||||||
width: 100% !important;
|
width: 100% !important;
|
||||||
height: auto !important;
|
height: auto !important;
|
||||||
border-radius: 0.75rem;
|
max-height: 380px !important;
|
||||||
|
border-radius: 1rem;
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
}
|
}
|
||||||
#qr-reader__scan_region {
|
#qr-reader__scan_region {
|
||||||
background: transparent !important;
|
background: transparent !important;
|
||||||
}
|
}
|
||||||
#qr-reader__scan_region video {
|
#qr-reader__scan_region video {
|
||||||
border-radius: 0.75rem;
|
border-radius: 1rem;
|
||||||
|
}
|
||||||
|
#qr-reader__dashboard {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
@keyframes scanLaserLine {
|
||||||
|
0% { top: 6%; opacity: 0.2; }
|
||||||
|
50% { top: 92%; opacity: 1; }
|
||||||
|
100% { top: 6%; opacity: 0.2; }
|
||||||
|
}
|
||||||
|
.scanner-laser-line {
|
||||||
|
position: absolute;
|
||||||
|
left: 6%;
|
||||||
|
right: 6%;
|
||||||
|
height: 2.5px;
|
||||||
|
background: linear-gradient(90deg, transparent, #10b981 25%, #34d399 50%, #10b981 75%, transparent);
|
||||||
|
box-shadow: 0 0 12px #10b981, 0 0 4px #34d399;
|
||||||
|
animation: scanLaserLine 2s ease-in-out infinite;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
@@ -802,24 +818,56 @@
|
|||||||
document.getElementById('driverCancelModal').classList.add('hidden');
|
document.getElementById('driverCancelModal').classList.add('hidden');
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- IN-APP QR CODE SCANNER LOGIC ---
|
// --- IN-APP LIVE QR/BARCODE SCANNER LOGIC ---
|
||||||
let html5QrScanner = null;
|
let html5QrScanner = null;
|
||||||
let isScanProcessing = false;
|
let isScanProcessing = false;
|
||||||
|
let availableCameras = [];
|
||||||
|
let currentCameraIndex = 0;
|
||||||
|
|
||||||
|
// Suara Beep saat Barcode Berhasil Terdeteksi (Web Audio API)
|
||||||
|
function playScanBeep() {
|
||||||
|
try {
|
||||||
|
const AudioCtx = window.AudioContext || window.webkitAudioContext;
|
||||||
|
if (AudioCtx) {
|
||||||
|
const audioCtx = new AudioCtx();
|
||||||
|
const oscillator = audioCtx.createOscillator();
|
||||||
|
const gainNode = audioCtx.createGain();
|
||||||
|
|
||||||
|
oscillator.type = 'sine';
|
||||||
|
oscillator.frequency.setValueAtTime(880, audioCtx.currentTime); // 880 Hz beep nada tinggi
|
||||||
|
gainNode.gain.setValueAtTime(0.25, audioCtx.currentTime);
|
||||||
|
gainNode.gain.exponentialRampToValueAtTime(0.01, audioCtx.currentTime + 0.15);
|
||||||
|
|
||||||
|
oscillator.connect(gainNode);
|
||||||
|
gainNode.connect(audioCtx.destination);
|
||||||
|
|
||||||
|
oscillator.start();
|
||||||
|
oscillator.stop(audioCtx.currentTime + 0.15);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Audio context tidak diizinkan atau dinonaktifkan
|
||||||
|
}
|
||||||
|
|
||||||
|
if (navigator.vibrate) {
|
||||||
|
try { navigator.vibrate([80, 40, 80]); } catch (e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function parseScannedCode(decodedText) {
|
function parseScannedCode(decodedText) {
|
||||||
if (!decodedText) return null;
|
if (!decodedText) return null;
|
||||||
decodedText = decodedText.trim();
|
decodedText = decodedText.trim();
|
||||||
|
|
||||||
// Check if it's already a full URL
|
// 1. Cek jika barcode berupa URL penuh (misal: http://.../gate-activity/LV-01)
|
||||||
try {
|
try {
|
||||||
const url = new URL(decodedText);
|
const url = new URL(decodedText);
|
||||||
if (url.pathname.includes('/gate-activity/')) {
|
if (url.pathname.includes('/gate-activity/')) {
|
||||||
return url.pathname;
|
return url.pathname + (url.search || '');
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Not a full URL, continue
|
// Bukan URL lengkap, lanjutkan parsing teks biasa
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2. Format path parsial /gate-activity/...
|
||||||
if (decodedText.startsWith('/gate-activity/')) {
|
if (decodedText.startsWith('/gate-activity/')) {
|
||||||
return decodedText;
|
return decodedText;
|
||||||
}
|
}
|
||||||
@@ -829,10 +877,10 @@
|
|||||||
return '/gate-activity/' + match[1];
|
return '/gate-activity/' + match[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Direct code string (misal "LV01" atau "LV-01")
|
// 3. Format kode unit langsung (misal: "LV-01", "LV01", "KMH-LV-05")
|
||||||
const cleanCode = decodedText.replace(/[^a-zA-Z0-9_\-]/g, '');
|
const cleanCode = decodedText.replace(/[^a-zA-Z0-9_\-]/g, '');
|
||||||
if (cleanCode.length >= 2) {
|
if (cleanCode.length >= 2) {
|
||||||
return '/gate-activity/' + cleanCode;
|
return '/gate-activity/' + encodeURIComponent(cleanCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -868,7 +916,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handler untuk scan barcode dari foto (Kamera HP Native atau Galeri File)
|
// Handler cadangan jika scan lewat foto galeri atau kamera native HP
|
||||||
async function handleQrFileSelected(event) {
|
async function handleQrFileSelected(event) {
|
||||||
const file = event.target.files && event.target.files[0];
|
const file = event.target.files && event.target.files[0];
|
||||||
if (!file) return;
|
if (!file) return;
|
||||||
@@ -876,12 +924,11 @@
|
|||||||
const fileLoadingEl = document.getElementById('qrScannerFileLoadingOverlay');
|
const fileLoadingEl = document.getElementById('qrScannerFileLoadingOverlay');
|
||||||
if (fileLoadingEl) fileLoadingEl.classList.remove('hidden');
|
if (fileLoadingEl) fileLoadingEl.classList.remove('hidden');
|
||||||
|
|
||||||
// Pastikan scanner live dimatikan saat menganalisis foto file
|
|
||||||
await stopQrScanner();
|
await stopQrScanner();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (typeof Html5Qrcode === 'undefined') {
|
if (typeof Html5Qrcode === 'undefined') {
|
||||||
throw new Error('Komponen pemindai barcode belum selesai dimuat. Silakan muat ulang halaman.');
|
throw new Error('Komponen pemindai barcode belum selesai dimuat.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const scanner = new Html5Qrcode("qr-reader");
|
const scanner = new Html5Qrcode("qr-reader");
|
||||||
@@ -890,18 +937,22 @@
|
|||||||
|
|
||||||
const targetUrl = parseScannedCode(decodedText);
|
const targetUrl = parseScannedCode(decodedText);
|
||||||
if (targetUrl) {
|
if (targetUrl) {
|
||||||
|
playScanBeep();
|
||||||
const successOverlay = document.getElementById('qrScannerSuccessOverlay');
|
const successOverlay = document.getElementById('qrScannerSuccessOverlay');
|
||||||
|
const unitTitle = document.getElementById('qrScannedUnitCode');
|
||||||
|
if (unitTitle) unitTitle.textContent = 'Unit Terdeteksi!';
|
||||||
if (successOverlay) successOverlay.classList.remove('hidden');
|
if (successOverlay) successOverlay.classList.remove('hidden');
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.location.href = targetUrl;
|
window.location.href = targetUrl;
|
||||||
}, 350);
|
}, 300);
|
||||||
} else {
|
} else {
|
||||||
alert(`Barcode terdeteksi: "${decodedText}", namun format bukan kode unit LV yang valid.`);
|
alert(`Barcode terdeteksi: "${decodedText}", namun format bukan kode unit yang valid.`);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (fileLoadingEl) fileLoadingEl.classList.add('hidden');
|
if (fileLoadingEl) fileLoadingEl.classList.add('hidden');
|
||||||
console.error('File scan error:', err);
|
console.error('File scan error:', err);
|
||||||
alert('Barcode tidak terbaca dari foto yang diambil. Pastikan stiker barcode tampak jelas, tidak buram, dan pencahayaan cukup.');
|
alert('Barcode tidak terbaca dari foto. Pastikan stiker barcode tampak jelas dan tidak silau.');
|
||||||
} finally {
|
} finally {
|
||||||
event.target.value = '';
|
event.target.value = '';
|
||||||
}
|
}
|
||||||
@@ -911,54 +962,55 @@
|
|||||||
const loadingEl = document.getElementById('qrScannerLoading');
|
const loadingEl = document.getElementById('qrScannerLoading');
|
||||||
const errorEl = document.getElementById('qrScannerError');
|
const errorEl = document.getElementById('qrScannerError');
|
||||||
const errorMsg = document.getElementById('qrScannerErrorMsg');
|
const errorMsg = document.getElementById('qrScannerErrorMsg');
|
||||||
const httpNoticeEl = document.getElementById('qrScannerHttpNotice');
|
const errorTitle = document.getElementById('qrScannerErrorTitle');
|
||||||
|
const switchBtn = document.getElementById('btnSwitchCamera');
|
||||||
|
const overlay = document.getElementById('qrScanOverlay');
|
||||||
|
|
||||||
loadingEl.classList.remove('hidden');
|
loadingEl.classList.remove('hidden');
|
||||||
errorEl.classList.add('hidden');
|
errorEl.classList.add('hidden');
|
||||||
if (httpNoticeEl) httpNoticeEl.classList.add('hidden');
|
if (overlay) overlay.classList.remove('hidden');
|
||||||
|
|
||||||
await stopQrScanner();
|
await stopQrScanner();
|
||||||
|
|
||||||
if (typeof Html5Qrcode === 'undefined') {
|
if (typeof Html5Qrcode === 'undefined') {
|
||||||
loadingEl.classList.add('hidden');
|
loadingEl.classList.add('hidden');
|
||||||
errorEl.classList.remove('hidden');
|
errorEl.classList.remove('hidden');
|
||||||
errorMsg.textContent = 'Komponen scanner kamera gagal dimuat. Periksa koneksi internet Anda atau gunakan tombol Ambil Foto Barcode di atas.';
|
if (errorTitle) errorTitle.textContent = 'Gagal Memuat Scanner';
|
||||||
|
errorMsg.textContent = 'Komponen scanner kamera gagal dimuat. Periksa koneksi internet Anda atau gunakan tombol Ambil Foto Barcode di bawah.';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cek dukungan HTTPS / Secure Context
|
// Polyfill navigator.mediaDevices untuk peramban mobile
|
||||||
const isSecure = window.isSecureContext || window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
|
if (navigator.mediaDevices === undefined) {
|
||||||
const hasMediaDevices = !!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia);
|
navigator.mediaDevices = {};
|
||||||
|
|
||||||
if (!isSecure || !hasMediaDevices) {
|
|
||||||
loadingEl.classList.add('hidden');
|
|
||||||
if (httpNoticeEl) {
|
|
||||||
httpNoticeEl.classList.remove('hidden');
|
|
||||||
} else {
|
|
||||||
errorEl.classList.remove('hidden');
|
|
||||||
errorMsg.textContent = 'Browser membatasi video streaming live karena halaman dibuka via HTTP. Gunakan tombol "Ambil Foto Barcode (Kamera HP)" di atas untuk scan langsung via kamera ponsel Anda.';
|
|
||||||
}
|
}
|
||||||
return;
|
if (navigator.mediaDevices.getUserMedia === undefined) {
|
||||||
|
navigator.mediaDevices.getUserMedia = function(constraints) {
|
||||||
|
const legacyGetUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
|
||||||
|
if (!legacyGetUserMedia) {
|
||||||
|
return Promise.reject(new Error('Kamera live tidak didukung pada peramban ini'));
|
||||||
}
|
}
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
try {
|
legacyGetUserMedia.call(navigator, constraints, resolve, reject);
|
||||||
// Minta izin kamera secara eksplisit untuk memicu dialog izin bawaan browser
|
|
||||||
try {
|
|
||||||
const testStream = await navigator.mediaDevices.getUserMedia({
|
|
||||||
video: { facingMode: { ideal: "environment" } }
|
|
||||||
});
|
});
|
||||||
if (testStream) {
|
};
|
||||||
testStream.getTracks().forEach(track => track.stop());
|
|
||||||
}
|
|
||||||
} catch (permErr) {
|
|
||||||
console.warn('getUserMedia prompt warning:', permErr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
html5QrScanner = new Html5Qrcode("qr-reader");
|
html5QrScanner = new Html5Qrcode("qr-reader");
|
||||||
|
|
||||||
|
// Konfigurasi performa tinggi (20 FPS) & scan box fleksibel
|
||||||
const config = {
|
const config = {
|
||||||
fps: 10,
|
fps: 20,
|
||||||
qrbox: { width: 220, height: 220 },
|
qrbox: (viewfinderWidth, viewfinderHeight) => {
|
||||||
aspectRatio: 1.0
|
const minEdge = Math.min(viewfinderWidth, viewfinderHeight);
|
||||||
|
const qrboxEdge = Math.max(180, Math.floor(minEdge * 0.72));
|
||||||
|
return { width: qrboxEdge, height: qrboxEdge };
|
||||||
|
},
|
||||||
|
aspectRatio: 1.0,
|
||||||
|
experimentalFeatures: {
|
||||||
|
useBarCodeDetectorIfSupported: true
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onScanSuccess = (decodedText) => {
|
const onScanSuccess = (decodedText) => {
|
||||||
@@ -966,49 +1018,58 @@
|
|||||||
const targetUrl = parseScannedCode(decodedText);
|
const targetUrl = parseScannedCode(decodedText);
|
||||||
if (targetUrl) {
|
if (targetUrl) {
|
||||||
isScanProcessing = true;
|
isScanProcessing = true;
|
||||||
|
playScanBeep();
|
||||||
|
|
||||||
const successOverlay = document.getElementById('qrScannerSuccessOverlay');
|
const successOverlay = document.getElementById('qrScannerSuccessOverlay');
|
||||||
|
const unitTitle = document.getElementById('qrScannedUnitCode');
|
||||||
|
if (unitTitle) {
|
||||||
|
const parts = targetUrl.split('/');
|
||||||
|
const code = parts[parts.length - 1];
|
||||||
|
unitTitle.textContent = `Unit "${decodeURIComponent(code)}" Terdeteksi!`;
|
||||||
|
}
|
||||||
if (successOverlay) successOverlay.classList.remove('hidden');
|
if (successOverlay) successOverlay.classList.remove('hidden');
|
||||||
|
|
||||||
stopQrScanner().then(() => {
|
stopQrScanner().finally(() => {
|
||||||
window.location.href = targetUrl;
|
|
||||||
}).catch(() => {
|
|
||||||
window.location.href = targetUrl;
|
window.location.href = targetUrl;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onScanFailure = (error) => {
|
|
||||||
// Frame scanning failure, continue silently
|
|
||||||
};
|
|
||||||
|
|
||||||
// Dapatkan daftar kamera perangkat
|
// Dapatkan daftar kamera perangkat
|
||||||
let cameras = [];
|
|
||||||
try {
|
try {
|
||||||
cameras = await Html5Qrcode.getCameras();
|
availableCameras = await Html5Qrcode.getCameras();
|
||||||
} catch (camErr) {
|
} catch (camErr) {
|
||||||
console.warn('Gagal ambil daftar kamera:', camErr);
|
console.warn('Gagal ambil daftar kamera:', camErr);
|
||||||
|
availableCameras = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cameras && cameras.length > 0) {
|
if (availableCameras && availableCameras.length > 1 && switchBtn) {
|
||||||
// Cari kamera belakang
|
switchBtn.classList.remove('hidden');
|
||||||
const rearCamera = cameras.find(c => {
|
switchBtn.classList.add('inline-flex');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (availableCameras && availableCameras.length > 0) {
|
||||||
|
// Pilih kamera belakang secara default
|
||||||
|
let rearIdx = availableCameras.findIndex(c => {
|
||||||
const label = (c.label || '').toLowerCase();
|
const label = (c.label || '').toLowerCase();
|
||||||
return label.includes('back') || label.includes('rear') || label.includes('belakang') || label.includes('environment');
|
return label.includes('back') || label.includes('rear') || label.includes('belakang') || label.includes('environment');
|
||||||
}) || cameras[cameras.length - 1];
|
});
|
||||||
|
if (rearIdx === -1) rearIdx = availableCameras.length - 1;
|
||||||
|
currentCameraIndex = rearIdx;
|
||||||
|
|
||||||
await html5QrScanner.start(
|
await html5QrScanner.start(
|
||||||
rearCamera.id,
|
availableCameras[currentCameraIndex].id,
|
||||||
config,
|
config,
|
||||||
onScanSuccess,
|
onScanSuccess,
|
||||||
onScanFailure
|
() => {}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// Fallback ke constraints facingMode
|
// Fallback jika getCameras kosong tapi getUserMedia didukung
|
||||||
await html5QrScanner.start(
|
await html5QrScanner.start(
|
||||||
{ facingMode: "environment" },
|
{ facingMode: "environment" },
|
||||||
config,
|
config,
|
||||||
onScanSuccess,
|
onScanSuccess,
|
||||||
onScanFailure
|
() => {}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1017,10 +1078,15 @@
|
|||||||
console.error('Kamera scanner error:', err);
|
console.error('Kamera scanner error:', err);
|
||||||
loadingEl.classList.add('hidden');
|
loadingEl.classList.add('hidden');
|
||||||
errorEl.classList.remove('hidden');
|
errorEl.classList.remove('hidden');
|
||||||
|
if (overlay) overlay.classList.add('hidden');
|
||||||
|
|
||||||
let customMsg = 'Live kamera tidak dapat diakses. Gunakan tombol "Ambil Foto Barcode (Kamera HP)" di atas.';
|
let customMsg = 'Live kamera tidak dapat diakses di browser ini.';
|
||||||
if (err && err.name === 'NotAllowedError') {
|
if (err && (err.name === 'NotAllowedError' || err.name === 'PermissionDeniedError')) {
|
||||||
customMsg = 'Izin kamera ditolak di browser. Silakan klik ikon gembok / opsi situs di sebelah URL browser Anda, lalu izinkan Kamera, ATAU gunakan tombol Kamera HP di atas.';
|
if (errorTitle) errorTitle.textContent = 'Izin Kamera Belum Diaktifkan';
|
||||||
|
customMsg = 'Izin kamera ditolak di peramban. Silakan klik ikon gembok / setelan situs di samping alamat URL browser, lalu izinkan akses Kamera.';
|
||||||
|
} else if (!window.isSecureContext && window.location.protocol === 'http:') {
|
||||||
|
if (errorTitle) errorTitle.textContent = 'Akses Kamera Dibatasi oleh HTTP';
|
||||||
|
customMsg = 'Browser Chrome membatasi streaming kamera langsung di jaringan HTTP. Silakan gunakan tombol "Gunakan Kamera HP" di bawah ATAU akses aplikasi melalui HTTPS.';
|
||||||
} else if (err && err.message) {
|
} else if (err && err.message) {
|
||||||
customMsg = err.message;
|
customMsg = err.message;
|
||||||
}
|
}
|
||||||
@@ -1029,6 +1095,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function switchCamera() {
|
||||||
|
if (!availableCameras || availableCameras.length <= 1 || !html5QrScanner) return;
|
||||||
|
currentCameraIndex = (currentCameraIndex + 1) % availableCameras.length;
|
||||||
|
await stopQrScanner();
|
||||||
|
await startQrScanner();
|
||||||
|
}
|
||||||
|
|
||||||
// Countdown Timer Tiket Pending (Batas Waktu 5 Jam)
|
// Countdown Timer Tiket Pending (Batas Waktu 5 Jam)
|
||||||
const countdownContainer = document.getElementById('pendingTripCountdownContainer');
|
const countdownContainer = document.getElementById('pendingTripCountdownContainer');
|
||||||
if (countdownContainer) {
|
if (countdownContainer) {
|
||||||
|
|||||||
Reference in New Issue
Block a user