forked from dsutanto/zenai-kpc-python
merging to main
This commit is contained in:
1 parent
d9c04d36c0
commit
6071d56dc3
5 files changed
+196
-146
No files matched your search
@@ -814,9 +814,6 @@ function updateToggleIcon() {
|
||||
let mainChart = null;
|
||||
let videoActive = false;
|
||||
let videoErrorTimer = null;
|
||||
let videoWatchdogTimer = null;
|
||||
let lastVideoFrameAt = 0;
|
||||
const VIDEO_STALL_MS = 8000;
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
loadSummary();
|
||||
@@ -1140,32 +1137,6 @@ document.addEventListener('keydown', (e) => {
|
||||
|
||||
// --- Live Video Feed ---
|
||||
|
||||
function reconnectVideo() {
|
||||
if (!videoActive) return;
|
||||
const img = document.getElementById('live-video-img');
|
||||
if (!img) return;
|
||||
lastVideoFrameAt = Date.now();
|
||||
img.src = '/api/live-video?' + Date.now();
|
||||
}
|
||||
|
||||
function startVideoWatchdog() {
|
||||
stopVideoWatchdog();
|
||||
lastVideoFrameAt = Date.now();
|
||||
videoWatchdogTimer = setInterval(() => {
|
||||
if (!videoActive) return;
|
||||
if (Date.now() - lastVideoFrameAt > VIDEO_STALL_MS) {
|
||||
reconnectVideo();
|
||||
}
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
function stopVideoWatchdog() {
|
||||
if (videoWatchdogTimer) {
|
||||
clearInterval(videoWatchdogTimer);
|
||||
videoWatchdogTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
function toggleVideo() {
|
||||
const btn = document.getElementById('videoToggle');
|
||||
const img = document.getElementById('live-video-img');
|
||||
@@ -1176,16 +1147,14 @@ function toggleVideo() {
|
||||
|
||||
if (videoActive) {
|
||||
resetFilter();
|
||||
img.src = '/api/live-video?' + Date.now();
|
||||
img.style.display = 'block';
|
||||
if (placeholder) placeholder.style.display = 'none';
|
||||
btn.textContent = 'STREAM ON';
|
||||
btn.classList.add('active');
|
||||
status.innerHTML = '<span style="width:6px;height:6px;border-radius:50%;background:var(--accent4);animation:blink 1.5s ease-in-out infinite;"></span> connecting...';
|
||||
status.className = 'video-status waiting';
|
||||
reconnectVideo();
|
||||
startVideoWatchdog();
|
||||
} else {
|
||||
stopVideoWatchdog();
|
||||
img.src = '';
|
||||
img.style.display = 'none';
|
||||
if (placeholder) placeholder.style.display = '';
|
||||
@@ -1198,7 +1167,6 @@ function toggleVideo() {
|
||||
}
|
||||
|
||||
function onVideoLoad() {
|
||||
lastVideoFrameAt = Date.now();
|
||||
const status = document.getElementById('video-status');
|
||||
status.innerHTML = '<span style="width:6px;height:6px;border-radius:50%;background:var(--accent4);box-shadow:0 0 6px var(--accent4);animation:blink 1.5s ease-in-out infinite;"></span> live';
|
||||
status.className = 'video-status connected';
|
||||
@@ -1210,7 +1178,10 @@ function onVideoError() {
|
||||
if (overlay) overlay.classList.add('visible');
|
||||
if (videoErrorTimer) clearTimeout(videoErrorTimer);
|
||||
videoErrorTimer = setTimeout(() => {
|
||||
reconnectVideo();
|
||||
if (videoActive) {
|
||||
const img = document.getElementById('live-video-img');
|
||||
img.src = '/api/live-video?' + Date.now();
|
||||
}
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
@@ -1246,4 +1217,4 @@ function hideVideoError() {
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
Reference in new issue
Block a user