diff --git a/frontend/css/style.css b/frontend/css/style.css index f927c0e..02b10bb 100644 --- a/frontend/css/style.css +++ b/frontend/css/style.css @@ -303,6 +303,39 @@ html, body { object-fit: contain; } +.preview-erreur-camera { + position: absolute; + top: 0; left: 0; right: 0; bottom: 0; + background: rgba(0, 0, 0, 0.85); + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + gap: 1rem; + color: #fff; + z-index: 10; +} + +.preview-erreur-camera.cache { + display: none; +} + +.preview-erreur-icon { + font-size: 5rem; + animation: pulse-texte 1.5s ease-in-out infinite; +} + +.preview-erreur-camera p { + font-size: 1.8rem; + font-weight: bold; + margin: 0; +} + +.preview-erreur-camera span { + font-size: 1.2rem; + opacity: 0.7; +} + .compte-a-rebours { position: absolute; top: 0; left: 0; diff --git a/frontend/index.html b/frontend/index.html index 5a32e63..6f92536 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -63,6 +63,11 @@
Preview +
+
📷
+

Appareil photo deconnecte

+ Reconnexion en cours... +
3 diff --git a/frontend/js/camera.js b/frontend/js/camera.js index 4f7b451..3102161 100644 --- a/frontend/js/camera.js +++ b/frontend/js/camera.js @@ -2,18 +2,37 @@ let previewActif = false; let previewInterval = null; +let previewTimeoutId = null; +const PREVIEW_TIMEOUT_MS = 3000; const EMOJI_CAR = { 3: '🤪', 2: '😱', 1: '🔥' }; // --- Preview live --- +function afficherErreurPreview(visible) { + const el = document.getElementById('preview-erreur-camera'); + if (!el) return; + if (visible) el.classList.remove('cache'); + else el.classList.add('cache'); +} + +function resetPreviewTimeout() { + if (previewTimeoutId) clearTimeout(previewTimeoutId); + previewTimeoutId = setTimeout(() => { + if (previewActif) afficherErreurPreview(true); + }, PREVIEW_TIMEOUT_MS); +} + function lancerPreview() { if (previewActif) return; previewActif = true; + afficherErreurPreview(false); previewInterval = setInterval(() => { if (previewActif) wsEnvoyer({ type: 'preview' }); }, 100); + + resetPreviewTimeout(); } function arreterPreview() { @@ -22,12 +41,28 @@ function arreterPreview() { clearInterval(previewInterval); previewInterval = null; } + if (previewTimeoutId) { + clearTimeout(previewTimeoutId); + previewTimeoutId = null; + } + afficherErreurPreview(false); } wsOnMessage('preview', (msg) => { if (!previewActif) return; const img = document.getElementById('img-preview'); if (img) img.src = msg.image; + afficherErreurPreview(false); + resetPreviewTimeout(); +}); + +// Erreur camera pendant la preview +wsOnMessage('camera_erreur', () => { + if (previewActif) afficherErreurPreview(true); +}); + +wsOnMessage('camera_ok', () => { + afficherErreurPreview(false); }); // --- Capture ---