feat(pos): integracion de pistola handheld con celular via SSE y PWA dedicada
This commit is contained in:
@@ -1046,6 +1046,17 @@ function openPistolaModal(mode = 'cobro') {
|
|||||||
|
|
||||||
startModalCamera();
|
startModalCamera();
|
||||||
|
|
||||||
|
// Notificar al teléfono vinculado que la caja está lista para escanear
|
||||||
|
try {
|
||||||
|
const total = posModalMode === 'cobro' ? posCart.reduce((sum, item) => sum + (item.product.precio_colones * item.cantidad), 0) : 0;
|
||||||
|
const totalItems = posCart.reduce((sum, item) => sum + item.cantidad, 0);
|
||||||
|
fetch('/api/pos/notify-scan-ready', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ mode: posModalMode, total, itemsCount: totalItems })
|
||||||
|
}).catch(() => {});
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const input = document.getElementById('inputPistolaDirectScan');
|
const input = document.getElementById('inputPistolaDirectScan');
|
||||||
if (input) input.focus();
|
if (input) input.focus();
|
||||||
@@ -1063,6 +1074,11 @@ function closePistolaModal(e) {
|
|||||||
// SIEMPRE apagar la cámara de inmediato al salir del modal
|
// SIEMPRE apagar la cámara de inmediato al salir del modal
|
||||||
stopModalCamera();
|
stopModalCamera();
|
||||||
|
|
||||||
|
// Notificar al teléfono vinculado que la sesión de escaneo terminó
|
||||||
|
try {
|
||||||
|
fetch('/api/pos/notify-scan-cancel', { method: 'POST' }).catch(() => {});
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
const modal = document.getElementById('modalPistolaCobro');
|
const modal = document.getElementById('modalPistolaCobro');
|
||||||
if (modal) modal.style.display = 'none';
|
if (modal) modal.style.display = 'none';
|
||||||
}
|
}
|
||||||
@@ -1393,6 +1409,37 @@ function initSSE() {
|
|||||||
loadPreOrders();
|
loadPreOrders();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Disparo recibido desde pistola remota (teléfono celular)
|
||||||
|
sseSource.addEventListener('pistola_scan', async (e) => {
|
||||||
|
try {
|
||||||
|
const data = JSON.parse(e.data);
|
||||||
|
if (data && data.token) {
|
||||||
|
console.log('📡 [POS] Disparo recibido desde pistola remota (teléfono):', data.token);
|
||||||
|
|
||||||
|
// Feedback visual en la barra superior
|
||||||
|
const badge = document.getElementById('pistolaStatusBadge');
|
||||||
|
if (badge) {
|
||||||
|
const prevHtml = badge.innerHTML;
|
||||||
|
badge.innerHTML = `<span class="saas-dot" style="background: #10b981;"></span> 📱 Disparo: ${data.token}`;
|
||||||
|
badge.style.background = '#dcfce7';
|
||||||
|
badge.style.borderColor = '#86efac';
|
||||||
|
badge.style.color = '#15803d';
|
||||||
|
setTimeout(() => {
|
||||||
|
badge.innerHTML = prevHtml;
|
||||||
|
badge.style.background = '#e0f2fe';
|
||||||
|
badge.style.borderColor = '#bae6fd';
|
||||||
|
badge.style.color = '#0369a1';
|
||||||
|
}, 2500);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ejecutar procesamiento del carné escaneado
|
||||||
|
await onQrCodeDetected(data.token);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error procesando disparo remoto:', err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
sseSource.addEventListener('producto_actualizado', (e) => {
|
sseSource.addEventListener('producto_actualizado', (e) => {
|
||||||
try {
|
try {
|
||||||
const prod = JSON.parse(e.data);
|
const prod = JSON.parse(e.data);
|
||||||
@@ -1883,3 +1930,47 @@ function posLogout() {
|
|||||||
}
|
}
|
||||||
window.posLogout = posLogout;
|
window.posLogout = posLogout;
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// VINCULACIÓN DE TELÉFONO COMO PISTOLA QR
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
|
function openPhonePairingModal() {
|
||||||
|
const modal = document.getElementById('modalPhonePairing');
|
||||||
|
if (!modal) return;
|
||||||
|
const pistolaUrl = window.location.origin + '/pistola.html';
|
||||||
|
const img = document.getElementById('imgPairingQr');
|
||||||
|
const link = document.getElementById('linkDirectPistola');
|
||||||
|
if (img) img.src = `/api/qr-image/${encodeURIComponent(pistolaUrl)}`;
|
||||||
|
if (link) {
|
||||||
|
link.href = pistolaUrl;
|
||||||
|
}
|
||||||
|
modal.style.display = 'flex';
|
||||||
|
}
|
||||||
|
window.openPhonePairingModal = openPhonePairingModal;
|
||||||
|
|
||||||
|
function closePhonePairingModal(e) {
|
||||||
|
if (e && e.target && e.target.id !== 'modalPhonePairing') return;
|
||||||
|
const modal = document.getElementById('modalPhonePairing');
|
||||||
|
if (modal) modal.style.display = 'none';
|
||||||
|
}
|
||||||
|
window.closePhonePairingModal = closePhonePairingModal;
|
||||||
|
|
||||||
|
function copyPistolaUrl() {
|
||||||
|
const pistolaUrl = window.location.origin + '/pistola.html';
|
||||||
|
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||||
|
navigator.clipboard.writeText(pistolaUrl).then(() => {
|
||||||
|
const feedback = document.getElementById('lblCopyPistolaFeedback');
|
||||||
|
if (feedback) {
|
||||||
|
feedback.style.display = 'block';
|
||||||
|
setTimeout(() => { if (feedback) feedback.style.display = 'none'; }, 3000);
|
||||||
|
}
|
||||||
|
}).catch(() => {
|
||||||
|
prompt('Copia este enlace para abrir la pistola en tu teléfono:', pistolaUrl);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
prompt('Copia este enlace para abrir la pistola en tu teléfono:', pistolaUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.copyPistolaUrl = copyPistolaUrl;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,730 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="es">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
|
||||||
|
<title>SiboPay - Pistola Lectora QR Remota</title>
|
||||||
|
<link rel="icon" type="image/png" href="/img/sibopay-emblem.png">
|
||||||
|
<meta name="theme-color" content="#0f172a">
|
||||||
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||||
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
||||||
|
<style>
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
-webkit-tap-highlight-color: transparent;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background: #0f172a;
|
||||||
|
color: #f8fafc;
|
||||||
|
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow: hidden;
|
||||||
|
touch-action: manipulation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Top Bar */
|
||||||
|
.pistola-header {
|
||||||
|
background: #1e293b;
|
||||||
|
border-bottom: 1.5px solid #334155;
|
||||||
|
padding: 12px 16px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
z-index: 20;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-box {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-box img {
|
||||||
|
width: 32px;
|
||||||
|
height: 32px;
|
||||||
|
object-fit: contain;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-box h1 {
|
||||||
|
font-size: 1rem;
|
||||||
|
font-weight: 900;
|
||||||
|
letter-spacing: -0.3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-box h1 span {
|
||||||
|
color: #38bdf8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-box p {
|
||||||
|
font-size: 0.68rem;
|
||||||
|
color: #94a3b8;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-badge {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 4px 10px;
|
||||||
|
border-radius: 20px;
|
||||||
|
font-size: 0.72rem;
|
||||||
|
font-weight: 800;
|
||||||
|
background: rgba(16, 185, 129, 0.15);
|
||||||
|
color: #34d399;
|
||||||
|
border: 1px solid rgba(16, 185, 129, 0.4);
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-badge.connecting {
|
||||||
|
background: rgba(245, 158, 11, 0.15);
|
||||||
|
color: #fbbf24;
|
||||||
|
border-color: rgba(245, 158, 11, 0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-badge.offline {
|
||||||
|
background: rgba(239, 68, 68, 0.15);
|
||||||
|
color: #f87171;
|
||||||
|
border-color: rgba(239, 68, 68, 0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-dot {
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: currentColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Banner de cobro sincronizado desde la PC */
|
||||||
|
.pos-sync-banner {
|
||||||
|
background: #0284c7;
|
||||||
|
color: #ffffff;
|
||||||
|
padding: 10px 14px;
|
||||||
|
display: none;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
font-weight: 800;
|
||||||
|
animation: bannerPulse 1.8s ease-in-out infinite;
|
||||||
|
z-index: 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes bannerPulse {
|
||||||
|
0%, 100% { background: #0284c7; }
|
||||||
|
50% { background: #0369a1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.pos-sync-banner.active {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Visor de Cámara Principal */
|
||||||
|
.scanner-viewport {
|
||||||
|
flex: 1;
|
||||||
|
position: relative;
|
||||||
|
background: #000;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
#scannerVideo {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Retícula de mira láser */
|
||||||
|
.aiming-reticle {
|
||||||
|
position: absolute;
|
||||||
|
width: 260px;
|
||||||
|
height: 260px;
|
||||||
|
pointer-events: none;
|
||||||
|
box-shadow: 0 0 0 4000px rgba(0, 0, 0, 0.55);
|
||||||
|
border-radius: 24px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Esquinas estilizadas */
|
||||||
|
.corner {
|
||||||
|
position: absolute;
|
||||||
|
width: 28px;
|
||||||
|
height: 28px;
|
||||||
|
border-color: #38bdf8;
|
||||||
|
border-style: solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.corner.tl { top: 0; left: 0; border-width: 4px 0 0 4px; border-top-left-radius: 20px; }
|
||||||
|
.corner.tr { top: 0; right: 0; border-width: 4px 4px 0 0; border-top-right-radius: 20px; }
|
||||||
|
.corner.bl { bottom: 0; left: 0; border-width: 0 0 4px 4px; border-bottom-left-radius: 20px; }
|
||||||
|
.corner.br { bottom: 0; right: 0; border-width: 0 4px 4px 0; border-bottom-right-radius: 20px; }
|
||||||
|
|
||||||
|
/* Haz de escáner láser rojo / cyan */
|
||||||
|
.laser-beam {
|
||||||
|
position: absolute;
|
||||||
|
left: 10px;
|
||||||
|
right: 10px;
|
||||||
|
height: 2.5px;
|
||||||
|
background: #38bdf8;
|
||||||
|
box-shadow: 0 0 14px 2px #38bdf8;
|
||||||
|
border-radius: 2px;
|
||||||
|
animation: laserSweep 2s cubic-bezier(0.4, 0, 0.2, 1) infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes laserSweep {
|
||||||
|
0% { top: 12px; opacity: 0.3; }
|
||||||
|
50% { top: 240px; opacity: 1; }
|
||||||
|
100% { top: 12px; opacity: 0.3; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Flash verde de disparo exitoso */
|
||||||
|
.flash-overlay {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
background: rgba(16, 185, 129, 0.45);
|
||||||
|
display: none;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 12px;
|
||||||
|
z-index: 30;
|
||||||
|
backdrop-filter: blur(2px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.flash-overlay.active {
|
||||||
|
display: flex;
|
||||||
|
animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes popIn {
|
||||||
|
from { opacity: 0; transform: scale(0.95); }
|
||||||
|
to { opacity: 1; transform: scale(1); }
|
||||||
|
}
|
||||||
|
|
||||||
|
.flash-badge {
|
||||||
|
background: #065f46;
|
||||||
|
color: #34d399;
|
||||||
|
border: 2px solid #10b981;
|
||||||
|
padding: 12px 24px;
|
||||||
|
border-radius: 16px;
|
||||||
|
font-size: 1.1rem;
|
||||||
|
font-weight: 900;
|
||||||
|
text-align: center;
|
||||||
|
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Controles de cámara flotantes */
|
||||||
|
.cam-controls {
|
||||||
|
position: absolute;
|
||||||
|
top: 14px;
|
||||||
|
right: 14px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
z-index: 25;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cam-btn {
|
||||||
|
width: 44px;
|
||||||
|
height: 44px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: rgba(15, 23, 42, 0.75);
|
||||||
|
border: 1.5px solid rgba(255, 255, 255, 0.2);
|
||||||
|
color: #ffffff;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
cursor: pointer;
|
||||||
|
backdrop-filter: blur(6px);
|
||||||
|
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
|
||||||
|
font-size: 1.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cam-btn.active {
|
||||||
|
background: #0284c7;
|
||||||
|
border-color: #38bdf8;
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Barra inferior: Último disparo y botones de prueba */
|
||||||
|
.pistola-footer {
|
||||||
|
background: #1e293b;
|
||||||
|
border-top: 1.5px solid #334155;
|
||||||
|
padding: 12px 14px calc(14px + env(safe-area-inset-bottom, 0px)) 14px;
|
||||||
|
z-index: 20;
|
||||||
|
}
|
||||||
|
|
||||||
|
.last-shot-box {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
background: #0f172a;
|
||||||
|
border: 1px solid #334155;
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 8px 12px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.last-shot-title {
|
||||||
|
font-size: 0.68rem;
|
||||||
|
color: #94a3b8;
|
||||||
|
font-weight: 700;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.last-shot-value {
|
||||||
|
font-size: 0.85rem;
|
||||||
|
font-weight: 900;
|
||||||
|
color: #38bdf8;
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.test-shortcuts-row {
|
||||||
|
display: flex;
|
||||||
|
gap: 6px;
|
||||||
|
overflow-x: auto;
|
||||||
|
scrollbar-width: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.test-btn {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 90px;
|
||||||
|
padding: 8px 10px;
|
||||||
|
background: #334155;
|
||||||
|
color: #f1f5f9;
|
||||||
|
border: 1px solid #475569;
|
||||||
|
border-radius: 10px;
|
||||||
|
font-size: 0.74rem;
|
||||||
|
font-weight: 800;
|
||||||
|
cursor: pointer;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-align: center;
|
||||||
|
transition: all 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.test-btn:active {
|
||||||
|
transform: scale(0.96);
|
||||||
|
background: #0284c7;
|
||||||
|
border-color: #38bdf8;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mensaje de permiso / error */
|
||||||
|
.cam-error-box {
|
||||||
|
position: absolute;
|
||||||
|
inset: 20px;
|
||||||
|
background: rgba(15, 23, 42, 0.95);
|
||||||
|
border: 1.5px solid #ef4444;
|
||||||
|
border-radius: 18px;
|
||||||
|
display: none;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 24px;
|
||||||
|
text-align: center;
|
||||||
|
z-index: 28;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cam-error-box.active {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<!-- CABECERA -->
|
||||||
|
<header class="pistola-header">
|
||||||
|
<div class="brand-box">
|
||||||
|
<img src="/img/sibopay-emblem.png" alt="SiboPay">
|
||||||
|
<div>
|
||||||
|
<h1>Sibo<span>Pay</span> Handheld</h1>
|
||||||
|
<p>Pistola QR Inalámbrica</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="connectionStatusBadge" class="status-badge connecting">
|
||||||
|
<span class="status-dot"></span>
|
||||||
|
<span id="lblConnectionStatus">Conectando...</span>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<!-- BANNER COBRO ACTIVO EN PC -->
|
||||||
|
<div id="posChargeBanner" class="pos-sync-banner">
|
||||||
|
<div style="display: flex; align-items: center; gap: 8px;">
|
||||||
|
<span style="font-size: 1.2rem;">⚡</span>
|
||||||
|
<div>
|
||||||
|
<div style="font-size: 0.72rem; text-transform: uppercase; opacity: 0.9;">Cobro en Caja Listo</div>
|
||||||
|
<div id="lblChargeAmount" style="font-size: 1.05rem; font-weight: 900;">Esperando carné...</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span style="background: rgba(255,255,255,0.25); padding: 3px 8px; border-radius: 6px; font-size: 0.7rem;">¡Apunta!</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- VISOR DE CÁMARA CON MIRA LÁSER -->
|
||||||
|
<main class="scanner-viewport">
|
||||||
|
<video id="scannerVideo" playsinline autoplay muted></video>
|
||||||
|
|
||||||
|
<!-- Mira Láser -->
|
||||||
|
<div class="aiming-reticle">
|
||||||
|
<div class="corner tl"></div>
|
||||||
|
<div class="corner tr"></div>
|
||||||
|
<div class="corner bl"></div>
|
||||||
|
<div class="corner br"></div>
|
||||||
|
<div class="laser-beam"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Controles flotantes: Linterna y Alternar Cámara -->
|
||||||
|
<div class="cam-controls">
|
||||||
|
<button id="btnToggleTorch" onclick="toggleTorch()" class="cam-btn" title="Encender / Apagar Linterna" style="display: none;">
|
||||||
|
🔦
|
||||||
|
</button>
|
||||||
|
<button onclick="flipCamera()" class="cam-btn" title="Cambiar Cámara">
|
||||||
|
🔄
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Overlay de Disparo Exitoso -->
|
||||||
|
<div id="shotSuccessOverlay" class="flash-overlay">
|
||||||
|
<div class="flash-badge">
|
||||||
|
<div style="font-size: 1.8rem; margin-bottom: 4px;">⚡ BEEP!</div>
|
||||||
|
<div style="font-size: 0.9rem; font-weight: 800; color: #ffffff;">Disparo Enviado a Caja</div>
|
||||||
|
<div id="lblSuccessToken" style="font-size: 0.78rem; opacity: 0.9; margin-top: 4px; font-family: monospace;">QR-MATEO-2026-A891</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Error / Permiso Denegado -->
|
||||||
|
<div id="camErrorBox" class="cam-error-box">
|
||||||
|
<div style="font-size: 2.5rem; margin-bottom: 8px;">📷</div>
|
||||||
|
<h3 style="font-size: 1.1rem; font-weight: 900; margin-bottom: 6px;">Se requiere acceso a la cámara</h3>
|
||||||
|
<p style="font-size: 0.8rem; color: #94a3b8; margin-bottom: 16px;">
|
||||||
|
Para usar tu teléfono como pistola lectora, habilita el permiso de cámara en este navegador.
|
||||||
|
</p>
|
||||||
|
<button onclick="startScannerCamera()" style="padding: 10px 20px; background: #0284c7; color: white; border: none; border-radius: 10px; font-weight: 800; font-size: 0.85rem; cursor: pointer;">
|
||||||
|
Reintentar Permiso
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<!-- PIE DE PÁGINA: ESTADO Y BOTONES DE DISPARO RÁPIDO PARA PRUEBAS -->
|
||||||
|
<footer class="pistola-footer">
|
||||||
|
<div class="last-shot-box">
|
||||||
|
<span class="last-shot-title">Último Disparo:</span>
|
||||||
|
<span id="lblLastShot" class="last-shot-value">Ninguno</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-bottom: 6px; font-size: 0.68rem; color: #94a3b8; font-weight: 700; text-transform: uppercase;">
|
||||||
|
Disparo Rápido para Pruebas:
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="test-shortcuts-row">
|
||||||
|
<button type="button" onclick="sendDirectShot('QR-MATEO-2026-A891')" class="test-btn">
|
||||||
|
🧒 Mateo (8a)
|
||||||
|
</button>
|
||||||
|
<button type="button" onclick="sendDirectShot('QR-SOFIA-2026-B442')" class="test-btn">
|
||||||
|
👧 Sofía (9a)
|
||||||
|
</button>
|
||||||
|
<button type="button" onclick="sendDirectShot('QR-NACHO-2026-D902')" class="test-btn">
|
||||||
|
🧑 Ignacio (14a)
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<!-- Librería jsQR para fallback si BarcodeDetector no está presente -->
|
||||||
|
<script src="/js/jsQR.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// Variables de control de cámara y escaneo
|
||||||
|
let videoStream = null;
|
||||||
|
let videoTrack = null;
|
||||||
|
let facingMode = 'environment';
|
||||||
|
let isTorchOn = false;
|
||||||
|
let isScanning = true;
|
||||||
|
let lastScannedToken = null;
|
||||||
|
let lastScannedTime = 0;
|
||||||
|
let sseSource = null;
|
||||||
|
let audioCtx = null;
|
||||||
|
|
||||||
|
// Inicializar Audio Web sintético (beeper de pistola POS)
|
||||||
|
function playLaserBeep() {
|
||||||
|
try {
|
||||||
|
if (!audioCtx) {
|
||||||
|
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
||||||
|
}
|
||||||
|
if (audioCtx.state === 'suspended') {
|
||||||
|
audioCtx.resume();
|
||||||
|
}
|
||||||
|
const osc = audioCtx.createOscillator();
|
||||||
|
const gain = audioCtx.createGain();
|
||||||
|
|
||||||
|
// Tono agudo característico de pistola lectora de supermercado (2400Hz)
|
||||||
|
osc.type = 'sine';
|
||||||
|
osc.frequency.setValueAtTime(2400, audioCtx.currentTime);
|
||||||
|
gain.gain.setValueAtTime(0.35, audioCtx.currentTime);
|
||||||
|
gain.gain.exponentialRampToValueAtTime(0.01, audioCtx.currentTime + 0.08);
|
||||||
|
|
||||||
|
osc.connect(gain);
|
||||||
|
gain.connect(audioCtx.destination);
|
||||||
|
osc.start();
|
||||||
|
osc.stop(audioCtx.currentTime + 0.08);
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Audio feedback error:', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vibración háptica
|
||||||
|
function vibratePhone() {
|
||||||
|
try {
|
||||||
|
if (navigator.vibrate) {
|
||||||
|
navigator.vibrate([70]);
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializar Canal SSE con el Servidor
|
||||||
|
function initSSEConnection() {
|
||||||
|
const badge = document.getElementById('connectionStatusBadge');
|
||||||
|
const lbl = document.getElementById('lblConnectionStatus');
|
||||||
|
|
||||||
|
if (sseSource) {
|
||||||
|
sseSource.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
sseSource = new EventSource('/api/events');
|
||||||
|
|
||||||
|
sseSource.onopen = () => {
|
||||||
|
badge.className = 'status-badge';
|
||||||
|
lbl.textContent = 'En Línea • Conectado';
|
||||||
|
};
|
||||||
|
|
||||||
|
sseSource.onerror = () => {
|
||||||
|
badge.className = 'status-badge offline';
|
||||||
|
lbl.textContent = 'Reconectando...';
|
||||||
|
};
|
||||||
|
|
||||||
|
// Escuchar cuando la caja en la PC entra en modo de cobro
|
||||||
|
sseSource.addEventListener('pistola_solicitud_cobro', (e) => {
|
||||||
|
try {
|
||||||
|
const data = JSON.parse(e.data);
|
||||||
|
const banner = document.getElementById('posChargeBanner');
|
||||||
|
const lblAmount = document.getElementById('lblChargeAmount');
|
||||||
|
if (banner && lblAmount) {
|
||||||
|
lblAmount.textContent = `₡${Number(data.total || 0).toLocaleString('es-CR')} (${data.itemsCount || 1} ítems)`;
|
||||||
|
banner.classList.add('active');
|
||||||
|
}
|
||||||
|
playLaserBeep();
|
||||||
|
vibratePhone();
|
||||||
|
} catch (err) {}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Escuchar cuando la caja en la PC cancela o cierra el modal
|
||||||
|
sseSource.addEventListener('pistola_cancelar_cobro', () => {
|
||||||
|
const banner = document.getElementById('posChargeBanner');
|
||||||
|
if (banner) banner.classList.remove('active');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializar Cámara
|
||||||
|
async function startScannerCamera() {
|
||||||
|
const video = document.getElementById('scannerVideo');
|
||||||
|
const errBox = document.getElementById('camErrorBox');
|
||||||
|
const btnTorch = document.getElementById('btnToggleTorch');
|
||||||
|
|
||||||
|
errBox.classList.remove('active');
|
||||||
|
|
||||||
|
if (videoStream) {
|
||||||
|
videoStream.getTracks().forEach(t => t.stop());
|
||||||
|
videoStream = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
videoStream = await navigator.mediaDevices.getUserMedia({
|
||||||
|
video: {
|
||||||
|
facingMode: { ideal: facingMode },
|
||||||
|
width: { ideal: 1280 },
|
||||||
|
height: { ideal: 720 }
|
||||||
|
},
|
||||||
|
audio: false
|
||||||
|
});
|
||||||
|
|
||||||
|
video.srcObject = videoStream;
|
||||||
|
await video.play();
|
||||||
|
|
||||||
|
videoTrack = videoStream.getVideoTracks()[0];
|
||||||
|
|
||||||
|
// Verificar soporte de linterna
|
||||||
|
if (videoTrack) {
|
||||||
|
const capabilities = videoTrack.getCapabilities ? videoTrack.getCapabilities() : {};
|
||||||
|
if (capabilities.torch) {
|
||||||
|
btnTorch.style.display = 'flex';
|
||||||
|
} else {
|
||||||
|
btnTorch.style.display = 'none';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
startDetectionLoop();
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error cámara:', err);
|
||||||
|
errBox.classList.add('active');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Alternar linterna
|
||||||
|
async function toggleTorch() {
|
||||||
|
if (!videoTrack) return;
|
||||||
|
try {
|
||||||
|
isTorchOn = !isTorchOn;
|
||||||
|
await videoTrack.applyConstraints({
|
||||||
|
advanced: [{ torch: isTorchOn }]
|
||||||
|
});
|
||||||
|
const btn = document.getElementById('btnToggleTorch');
|
||||||
|
if (btn) btn.classList.toggle('active', isTorchOn);
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Torch no soportado:', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cambiar cámara frontal / trasera
|
||||||
|
function flipCamera() {
|
||||||
|
facingMode = (facingMode === 'environment') ? 'user' : 'environment';
|
||||||
|
isTorchOn = false;
|
||||||
|
const btn = document.getElementById('btnToggleTorch');
|
||||||
|
if (btn) btn.classList.remove('active');
|
||||||
|
startScannerCamera();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detección Ultra-Rápida de Código QR
|
||||||
|
let scanCanvas = null;
|
||||||
|
let scanCtx = null;
|
||||||
|
let barcodeDetector = null;
|
||||||
|
|
||||||
|
if ('BarcodeDetector' in window) {
|
||||||
|
try {
|
||||||
|
barcodeDetector = new BarcodeDetector({ formats: ['qr_code'] });
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
function startDetectionLoop() {
|
||||||
|
const video = document.getElementById('scannerVideo');
|
||||||
|
|
||||||
|
async function checkFrame() {
|
||||||
|
if (!isScanning) return;
|
||||||
|
|
||||||
|
if (video && video.readyState >= video.HAVE_CURRENT_DATA) {
|
||||||
|
try {
|
||||||
|
// 1. Intentar con BarcodeDetector nativo (acelerado por hardware)
|
||||||
|
if (barcodeDetector) {
|
||||||
|
const barcodes = await barcodeDetector.detect(video);
|
||||||
|
if (barcodes.length > 0 && barcodes[0].rawValue) {
|
||||||
|
handleScannedCode(barcodes[0].rawValue);
|
||||||
|
}
|
||||||
|
} else if (window.jsQR) {
|
||||||
|
// 2. Fallback a jsQR
|
||||||
|
if (!scanCanvas) {
|
||||||
|
scanCanvas = document.createElement('canvas');
|
||||||
|
scanCtx = scanCanvas.getContext('2d', { willReadFrequently: true });
|
||||||
|
}
|
||||||
|
scanCanvas.width = video.videoWidth;
|
||||||
|
scanCanvas.height = video.videoHeight;
|
||||||
|
scanCtx.drawImage(video, 0, 0, scanCanvas.width, scanCanvas.height);
|
||||||
|
const imgData = scanCtx.getImageData(0, 0, scanCanvas.width, scanCanvas.height);
|
||||||
|
const code = window.jsQR(imgData.data, imgData.width, imgData.height, {
|
||||||
|
inversionAttempts: 'dontInvert'
|
||||||
|
});
|
||||||
|
if (code && code.data) {
|
||||||
|
handleScannedCode(code.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
requestAnimationFrame(checkFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
requestAnimationFrame(checkFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Procesar Código QR Detectado
|
||||||
|
async function handleScannedCode(rawToken) {
|
||||||
|
if (!rawToken) return;
|
||||||
|
const token = rawToken.trim();
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
|
// Cooldown de 2 segundos para evitar disparos duplicados involuntarios
|
||||||
|
if (token === lastScannedToken && (now - lastScannedTime) < 2000) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastScannedToken = token;
|
||||||
|
lastScannedTime = now;
|
||||||
|
|
||||||
|
// Disparar feedback sonoro y háptico
|
||||||
|
playLaserBeep();
|
||||||
|
vibratePhone();
|
||||||
|
|
||||||
|
// Destello visual en pantalla
|
||||||
|
showShotSuccess(token);
|
||||||
|
|
||||||
|
// Enviar disparo a la caja POS
|
||||||
|
sendTokenToPos(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
function showShotSuccess(token) {
|
||||||
|
const overlay = document.getElementById('shotSuccessOverlay');
|
||||||
|
const lbl = document.getElementById('lblSuccessToken');
|
||||||
|
const lblLast = document.getElementById('lblLastShot');
|
||||||
|
|
||||||
|
if (lbl) lbl.textContent = token;
|
||||||
|
if (lblLast) lblLast.textContent = token;
|
||||||
|
|
||||||
|
if (overlay) {
|
||||||
|
overlay.classList.add('active');
|
||||||
|
setTimeout(() => {
|
||||||
|
overlay.classList.remove('active');
|
||||||
|
}, 800);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Envío por API a la Terminal POS
|
||||||
|
async function sendTokenToPos(token) {
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/pos/remote-scan', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
token: token,
|
||||||
|
deviceName: navigator.userAgent.includes('iPhone') ? 'iPhone' : 'Android'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
const data = await res.json();
|
||||||
|
console.log('📡 Disparo enviado exitosamente a la terminal:', data);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error enviando disparo a la terminal:', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Botones directos de prueba
|
||||||
|
function sendDirectShot(token) {
|
||||||
|
handleScannedCode(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Iniciar todo al cargar
|
||||||
|
window.addEventListener('DOMContentLoaded', () => {
|
||||||
|
initSSEConnection();
|
||||||
|
startScannerCamera();
|
||||||
|
|
||||||
|
// Desbloquear AudioContext al primer toque
|
||||||
|
document.body.addEventListener('click', () => {
|
||||||
|
if (!audioCtx) playLaserBeep();
|
||||||
|
}, { once: true });
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
+31
-1
@@ -108,6 +108,10 @@
|
|||||||
<button id="btnPosNotificationToggle" onclick="enablePushNotificationsPrompt()" class="btn-saas btn-saas-outline" style="height: 30px; font-size: 0.76rem; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; color: #0284c7; border-color: #bae6fd;" title="Activar notificaciones de recargas en tiempo real">
|
<button id="btnPosNotificationToggle" onclick="enablePushNotificationsPrompt()" class="btn-saas btn-saas-outline" style="height: 30px; font-size: 0.76rem; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; color: #0284c7; border-color: #bae6fd;" title="Activar notificaciones de recargas en tiempo real">
|
||||||
<span>🔔</span> <span id="lblPosNotificationStatus">Notificaciones</span>
|
<span>🔔</span> <span id="lblPosNotificationStatus">Notificaciones</span>
|
||||||
</button>
|
</button>
|
||||||
|
<button type="button" onclick="openPhonePairingModal()" class="btn-saas btn-saas-outline" style="height: 30px; font-size: 0.76rem; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; color: #0284c7; border-color: #bae6fd; font-weight: 700;" title="Vincular tu teléfono celular como pistola lectora QR inalámbrica">
|
||||||
|
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><rect width="14" height="20" x="5" y="2" rx="2" ry="2"/><line x1="12" y1="18" x2="12.01" y2="18"/></svg>
|
||||||
|
<span>📱 Vincular Celular</span>
|
||||||
|
</button>
|
||||||
<a href="/index.html?tab=admin" class="btn-saas btn-saas-outline" style="height: 30px; font-size: 0.76rem; display: inline-flex; align-items: center; gap: 5px; font-weight: 700; color: #475569; border-color: #cbd5e1;" title="Ir al Panel de Administración">
|
<a href="/index.html?tab=admin" class="btn-saas btn-saas-outline" style="height: 30px; font-size: 0.76rem; display: inline-flex; align-items: center; gap: 5px; font-weight: 700; color: #475569; border-color: #cbd5e1;" title="Ir al Panel de Administración">
|
||||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></svg>
|
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></svg>
|
||||||
<span>Admin</span>
|
<span>Admin</span>
|
||||||
@@ -475,11 +479,37 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- MODAL: VINCULAR TELÉFONO COMO PISTOLA QR INALÁMBRICA -->
|
||||||
|
<div class="modal-qr-backdrop" id="modalPhonePairing" style="display: none;" onclick="closePhonePairingModal(event)">
|
||||||
|
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 440px; text-align: center; border-radius: 20px; padding: 22px;">
|
||||||
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; border-bottom: 1px solid var(--border, #e2e8f0); padding-bottom: 8px;">
|
||||||
|
<div style="display: flex; align-items: center; gap: 8px;">
|
||||||
|
<span style="font-size: 1.3rem;">📱</span>
|
||||||
|
<strong style="font-size: 1.05rem; color: var(--text-main, #0f172a);">Pistola QR en tu Celular</strong>
|
||||||
|
</div>
|
||||||
|
<button type="button" onclick="closePhonePairingModal()" style="background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-muted, #64748b);">✕</button>
|
||||||
|
</div>
|
||||||
|
<p style="font-size: 0.82rem; color: #64748b; margin-bottom: 14px; line-height: 1.4;">
|
||||||
|
Apunta la cámara de tu teléfono a este código para activarlo como <strong>pistola lectora inalámbrica en tiempo real</strong>. Cualquier carné que escanees con tu celular se cobrará aquí al instante.
|
||||||
|
</p>
|
||||||
|
<div style="background: #ffffff; border: 2px solid #0284c7; border-radius: 16px; padding: 14px; display: inline-block; margin-bottom: 14px; box-shadow: 0 4px 14px rgba(2, 132, 199, 0.15);">
|
||||||
|
<img id="imgPairingQr" src="/api/qr-image/http%3A%2F%2Flocalhost%2Fpistola.html" alt="QR Pistola" style="width: 200px; height: 200px; display: block; border-radius: 8px;">
|
||||||
|
</div>
|
||||||
|
<div style="display: flex; gap: 8px; justify-content: center; align-items: center; margin-bottom: 10px; flex-wrap: wrap;">
|
||||||
|
<a id="linkDirectPistola" href="/pistola.html" target="_blank" class="btn-saas btn-saas-outline" style="font-size: 0.78rem; text-decoration: none;">
|
||||||
|
Abrir Pistola en pestaña ↗
|
||||||
|
</a>
|
||||||
|
<button type="button" onclick="copyPistolaUrl()" class="btn-saas btn-saas-primary" style="font-size: 0.78rem;">
|
||||||
|
Copiar Enlace
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<span id="lblCopyPistolaFeedback" style="font-size: 0.74rem; color: #10b981; font-weight: 800; display: none;">¡Enlace copiado al portapapeles!</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="/js/sounds.js?v=8.6"></script>
|
<script src="/js/sounds.js?v=8.6"></script>
|
||||||
<script src="/js/jsQR.js"></script>
|
<script src="/js/jsQR.js"></script>
|
||||||
<script src="/js/food-icons.js?v=1.1"></script>
|
<script src="/js/food-icons.js?v=1.1"></script>
|
||||||
<script src="/js/pos.js?v=10.3"></script>
|
<script src="/js/pos.js?v=10.4"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+3
-2
@@ -1,9 +1,10 @@
|
|||||||
// RecreoPay PWA Service Worker v9.4 - Soporte Desktop Web Desacoplado
|
// RecreoPay PWA Service Worker v9.5 - Soporte Pistola Móvil Remota
|
||||||
const CACHE_NAME = 'recreopay-v9.4';
|
const CACHE_NAME = 'recreopay-v9.5';
|
||||||
const STATIC_ASSETS = [
|
const STATIC_ASSETS = [
|
||||||
'/',
|
'/',
|
||||||
'/index.html',
|
'/index.html',
|
||||||
'/pos.html',
|
'/pos.html',
|
||||||
|
'/pistola.html',
|
||||||
'/carnet.html',
|
'/carnet.html',
|
||||||
'/manifest.json',
|
'/manifest.json',
|
||||||
'/css/styles.css',
|
'/css/styles.css',
|
||||||
|
|||||||
@@ -157,6 +157,57 @@ setInterval(() => {
|
|||||||
}
|
}
|
||||||
}, 10000);
|
}, 10000);
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// PISTOLA REMOTA QR / HANDHELD SMARTPHONE
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
|
// Disparo remoto desde la pistola móvil (teléfono) hacia la caja POS
|
||||||
|
app.post('/api/pos/remote-scan', (req, res) => {
|
||||||
|
try {
|
||||||
|
const { token, deviceName } = req.body;
|
||||||
|
if (!token) return res.status(400).json({ error: 'Token requerido' });
|
||||||
|
|
||||||
|
console.log(`📡 [PISTOLA REMOTA] Disparo recibido desde ${deviceName || 'teléfono'}: ${token}`);
|
||||||
|
|
||||||
|
// Broadcast a todas las terminales POS conectadas por SSE
|
||||||
|
broadcastEvent('pistola_scan', {
|
||||||
|
token: String(token).trim(),
|
||||||
|
deviceName: deviceName || 'Pistola Teléfono',
|
||||||
|
timestamp: Date.now()
|
||||||
|
});
|
||||||
|
|
||||||
|
res.json({ ok: true, token: String(token).trim() });
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({ error: err.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Solicitud desde el POS en PC al teléfono para avisar que la caja está lista para cobrar
|
||||||
|
app.post('/api/pos/notify-scan-ready', (req, res) => {
|
||||||
|
try {
|
||||||
|
const { mode, total, itemsCount } = req.body;
|
||||||
|
broadcastEvent('pistola_solicitud_cobro', {
|
||||||
|
mode: mode || 'cobro',
|
||||||
|
total: total || 0,
|
||||||
|
itemsCount: itemsCount || 0,
|
||||||
|
timestamp: Date.now()
|
||||||
|
});
|
||||||
|
res.json({ ok: true });
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({ error: err.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Cancelación de solicitud cuando se cierra el modal de cobro en la PC
|
||||||
|
app.post('/api/pos/notify-scan-cancel', (req, res) => {
|
||||||
|
try {
|
||||||
|
broadcastEvent('pistola_cancelar_cobro', { timestamp: Date.now() });
|
||||||
|
res.json({ ok: true });
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({ error: err.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// 0. AUTENTICACIÓN Y ROLES (ADMIN, PADRE, ESTUDIANTE)
|
// 0. AUTENTICACIÓN Y ROLES (ADMIN, PADRE, ESTUDIANTE)
|
||||||
// ==========================================
|
// ==========================================
|
||||||
|
|||||||
Reference in New Issue
Block a user