-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
63 lines (54 loc) · 1.84 KB
/
script.js
File metadata and controls
63 lines (54 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
let camActive = false;
// Vérifie le statut au chargement
async function checkStatus() {
try {
const res = await fetch('/status');
const data = await res.json();
updateUI(data.active);
} catch (e) {
console.error('Erreur statut:', e);
}
}
async function toggleCam() {
const btn = document.getElementById('camBtn');
btn.disabled = true;
try {
const endpoint = camActive ? '/cam/off' : '/cam/on';
const res = await fetch(endpoint);
const data = await res.json();
updateUI(data.active);
} catch (e) {
console.error('Erreur toggle:', e);
} finally {
btn.disabled = false;
}
}
function updateUI(active) {
camActive = active;
const img = document.getElementById('streamImg');
const offlineScreen = document.getElementById('offlineScreen');
const statusDot = document.getElementById('statusDot');
const statusLabel = document.getElementById('statusLabel');
const camBtn = document.getElementById('camBtn');
const camBtnLabel = document.getElementById('camBtnLabel');
if (active) {
// Relance le stream avec timestamp pour éviter le cache
img.src = '/stream?' + Date.now();
img.style.display = 'block';
offlineScreen.style.display = 'none';
statusDot.classList.add('live');
statusLabel.textContent = 'LIVE FEED_01';
camBtnLabel.textContent = 'DEACTIVATE CAMERA';
camBtn.classList.add('active');
} else {
img.src = '';
img.style.display = 'none';
offlineScreen.style.display = 'flex';
statusDot.classList.remove('live');
statusLabel.textContent = 'OFFLINE';
camBtnLabel.textContent = 'ACTIVATE CAMERA';
camBtn.classList.remove('active');
}
}
// Vérification du statut au chargement de la page
checkStatus();