Fix rfid.js-Failure with X1-Series,

if you wanna send a Spool to AMS:
 - Uncaught TypeError: Cannot read properties of undefined (reading 'replace')
    at handleSpoolIn (rfid.js:493:67)
    at HTMLButtonElement.onclick ((Index):1:1)
handleSpoolIn	@	rfid.js:493
onclick	@	(Index):1
This commit is contained in:
tugsi 2025-03-25 17:40:55 +01:00
parent 43719aac41
commit fe4d2d7479

View File

@ -11,7 +11,7 @@ let reconnectTimer = null;
// WebSocket Funktionen // WebSocket Funktionen
function startHeartbeat() { function startHeartbeat() {
if (heartbeatTimer) clearInterval(heartbeatTimer); if (heartbeatTimer) clearInterval(heartbeatTimer);
heartbeatTimer = setInterval(() => { heartbeatTimer = setInterval(() => {
// Prüfe ob zu lange keine Antwort kam // Prüfe ob zu lange keine Antwort kam
if (Date.now() - lastHeartbeatResponse > HEARTBEAT_TIMEOUT) { if (Date.now() - lastHeartbeatResponse > HEARTBEAT_TIMEOUT) {
@ -29,7 +29,7 @@ function startHeartbeat() {
updateConnectionStatus(); updateConnectionStatus();
return; return;
} }
try { try {
// Sende Heartbeat // Sende Heartbeat
socket.send(JSON.stringify({ type: 'heartbeat' })); socket.send(JSON.stringify({ type: 'heartbeat' }));
@ -83,7 +83,7 @@ function initWebSocket() {
isConnected = false; isConnected = false;
updateConnectionStatus(); updateConnectionStatus();
if (heartbeatTimer) clearInterval(heartbeatTimer); if (heartbeatTimer) clearInterval(heartbeatTimer);
// Bei Fehler Verbindung schließen und neu aufbauen // Bei Fehler Verbindung schließen und neu aufbauen
if (socket) { if (socket) {
socket.close(); socket.close();
@ -109,7 +109,7 @@ function initWebSocket() {
const bambuDot = document.getElementById('bambuDot'); const bambuDot = document.getElementById('bambuDot');
const spoolmanDot = document.getElementById('spoolmanDot'); const spoolmanDot = document.getElementById('spoolmanDot');
const ramStatus = document.getElementById('ramStatus'); const ramStatus = document.getElementById('ramStatus');
if (bambuDot) { if (bambuDot) {
bambuDot.className = 'status-dot ' + (data.bambu_connected ? 'online' : 'offline'); bambuDot.className = 'status-dot ' + (data.bambu_connected ? 'online' : 'offline');
// Add click handler only when offline // Add click handler only when offline
@ -208,7 +208,7 @@ document.addEventListener('spoolmanError', function(event) {
showNotification(`Spoolman Error: ${event.detail.message}`, false); showNotification(`Spoolman Error: ${event.detail.message}`, false);
}); });
document.addEventListener('filamentSelected', function(event) { document.addEventListener('filamentSelected', function (event) {
updateNfcInfo(); updateNfcInfo();
// Zeige Spool-Buttons wenn ein Filament ausgewählt wurde // Zeige Spool-Buttons wenn ein Filament ausgewählt wurde
const selectedText = document.getElementById("selected-filament").textContent; const selectedText = document.getElementById("selected-filament").textContent;
@ -490,7 +490,7 @@ function handleSpoolIn(amsId, trayId) {
nozzle_temp_max: parseInt(maxTemp), nozzle_temp_max: parseInt(maxTemp),
type: selectedSpool.filament.material, type: selectedSpool.filament.material,
brand: selectedSpool.filament.vendor.name, brand: selectedSpool.filament.vendor.name,
tray_info_idx: selectedSpool.filament.extra.bambu_idx.replace(/['"]+/g, '').trim(), tray_info_idx: selectedSpool.filament.extra.bambu_idx?.replace(/['"]+/g, '').trim() || '',
cali_idx: "-1" // Default-Wert setzen cali_idx: "-1" // Default-Wert setzen
} }
}; };
@ -686,4 +686,4 @@ function showNotification(message, isSuccess) {
notification.remove(); notification.remove();
}, 300); }, 300);
}, 3000); }, 3000);
} }