mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 21:03:01 +00:00
live preview troubleshooting
This commit is contained in:
@@ -1779,11 +1779,19 @@
|
||||
|
||||
// Socket.IO connection
|
||||
function initializeSocket() {
|
||||
socket = io({ transports: ['websocket', 'polling'] });
|
||||
socket = io({
|
||||
path: '/socket.io',
|
||||
transports: ['websocket', 'polling'],
|
||||
reconnection: true,
|
||||
reconnectionAttempts: Infinity,
|
||||
reconnectionDelay: 1000,
|
||||
reconnectionDelayMax: 10000
|
||||
});
|
||||
|
||||
socket.on('connect', function() {
|
||||
updateConnectionStatus(true);
|
||||
showNotification('Connected to LED Matrix', 'success');
|
||||
stopPreviewPolling();
|
||||
});
|
||||
|
||||
socket.on('disconnect', function() {
|
||||
@@ -1800,6 +1808,12 @@
|
||||
}, delay);
|
||||
};
|
||||
retry();
|
||||
startPreviewPolling();
|
||||
});
|
||||
|
||||
socket.on('connect_error', function(_err){
|
||||
updateConnectionStatus(false);
|
||||
startPreviewPolling();
|
||||
});
|
||||
|
||||
socket.on('display_update', function(data) {
|
||||
@@ -1807,6 +1821,24 @@
|
||||
});
|
||||
}
|
||||
|
||||
// Fallback polling when websocket is disconnected
|
||||
let __previewPollTimer = null;
|
||||
function startPreviewPolling(){
|
||||
if (__previewPollTimer) return;
|
||||
__previewPollTimer = setInterval(fetchCurrentDisplayOnce, 1000);
|
||||
}
|
||||
function stopPreviewPolling(){
|
||||
if (__previewPollTimer) clearInterval(__previewPollTimer);
|
||||
__previewPollTimer = null;
|
||||
}
|
||||
async function fetchCurrentDisplayOnce(){
|
||||
try {
|
||||
const res = await fetch('/api/display/current');
|
||||
const data = await res.json();
|
||||
if (data && data.image) updateDisplayPreview(data);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
// Draw pixel grid lines on top of scaled image
|
||||
function drawGrid(canvas, logicalWidth, logicalHeight, scale) {
|
||||
const show = document.getElementById('toggleGrid')?.checked;
|
||||
|
||||
Reference in New Issue
Block a user