fixxed connect button
This commit is contained in:
parent
702eba2370
commit
4f96b919be
@ -17,13 +17,13 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
if (!connectBtn) {
|
if (!connectBtn) {
|
||||||
console.warn('Nicht auf der Steuerseite – Connect-Button nicht gefunden');
|
console.warn('Nicht auf der Steuerseite – Connect-Button nicht gefunden');
|
||||||
return;
|
// Dennoch Status und Soundboard-Logik initialisieren (falls vorhanden)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Config aus Template ────────────────────────────────────────────────────
|
// ── Config & globale Sounds aus Template ──────────────────────────────────
|
||||||
const config = {{ config | tojson | safe }};
|
const config = {{ config | tojson | safe }};
|
||||||
const globalSounds = {{ global_sounds | tojson | safe }};
|
const globalSounds = {{ global_sounds | tojson | safe }};
|
||||||
window.mkConfig = config; // global für Konsistenz
|
window.mkConfig = config; // global verfügbar
|
||||||
|
|
||||||
console.log("Config im JS:", config);
|
console.log("Config im JS:", config);
|
||||||
console.log("Globale Sounds:", globalSounds);
|
console.log("Globale Sounds:", globalSounds);
|
||||||
@ -85,48 +85,50 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// ── Connect-Button ────────────────────────────────────────────────────────
|
// ── Connect-Button ────────────────────────────────────────────────────────
|
||||||
connectBtn.addEventListener('click', async () => {
|
if (connectBtn) {
|
||||||
connectBtn.disabled = true;
|
connectBtn.addEventListener('click', async () => {
|
||||||
connectBtn.innerHTML = '<span class="spinner-border spinner-border-sm me-2" role="status" aria-hidden="true"></span> Verbinde...';
|
connectBtn.disabled = true;
|
||||||
|
connectBtn.innerHTML = '<span class="spinner-border spinner-border-sm me-2" role="status" aria-hidden="true"></span> Verbinde...';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log("→ Sende /api/connect ...");
|
console.log("→ Sende /api/connect ...");
|
||||||
const response = await fetch('/api/connect', {
|
const response = await fetch('/api/connect', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' }
|
headers: { 'Content-Type': 'application/json' }
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("→ Antwort erhalten:", response.status);
|
console.log("→ Antwort erhalten:", response.status);
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
console.log("→ Resultat:", result);
|
console.log("→ Resultat:", result);
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
console.log("→ Connect erfolgreich – blende Sections um");
|
console.log("→ Connect erfolgreich – blende Sections um");
|
||||||
connectSection.style.display = 'none';
|
connectSection.style.display = 'none';
|
||||||
controlSection.style.display = 'block';
|
controlSection.style.display = 'block';
|
||||||
reconnectSection.style.display = 'none';
|
reconnectSection.style.display = 'none';
|
||||||
|
|
||||||
updateStatus(true);
|
updateStatus(true);
|
||||||
startConnectionCheck();
|
startConnectionCheck();
|
||||||
|
|
||||||
console.log("→ Rufe renderChannels() auf");
|
console.log("→ Rufe renderChannels() auf");
|
||||||
renderChannels();
|
renderChannels();
|
||||||
|
|
||||||
console.log("→ renderChannels() abgeschlossen");
|
console.log("→ renderChannels() abgeschlossen");
|
||||||
} else {
|
} else {
|
||||||
console.warn("→ Connect fehlgeschlagen:", result.message);
|
console.warn("→ Connect fehlgeschlagen:", result.message);
|
||||||
alert('Verbindung fehlgeschlagen:\n' + (result.message || 'Unbekannter Fehler'));
|
alert('Verbindung fehlgeschlagen:\n' + (result.message || 'Unbekannter Fehler'));
|
||||||
|
updateStatus(false);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("→ Connect-Fehler:", err);
|
||||||
|
alert('Netzwerk- oder Verbindungsfehler: ' + err.message);
|
||||||
updateStatus(false);
|
updateStatus(false);
|
||||||
|
} finally {
|
||||||
|
connectBtn.disabled = false;
|
||||||
|
connectBtn.innerHTML = '<i class="bi bi-bluetooth me-2"></i> Mit Hub verbinden';
|
||||||
}
|
}
|
||||||
} catch (err) {
|
});
|
||||||
console.error("→ Connect-Fehler:", err);
|
}
|
||||||
alert('Netzwerk- oder Verbindungsfehler: ' + err.message);
|
|
||||||
updateStatus(false);
|
|
||||||
} finally {
|
|
||||||
connectBtn.disabled = false;
|
|
||||||
connectBtn.innerHTML = '<i class="bi bi-bluetooth me-2"></i> Mit Hub verbinden';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// ── Alle stoppen ──────────────────────────────────────────────────────────
|
// ── Alle stoppen ──────────────────────────────────────────────────────────
|
||||||
if (stopAllBtn) {
|
if (stopAllBtn) {
|
||||||
@ -301,7 +303,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── Event-Listener Toggle-Buttons (Licht/Sound/Fogger) ──────────────────
|
// ── Event-Listener Toggle-Buttons ──────────────────────────────────────
|
||||||
document.querySelectorAll('.toggle-btn').forEach(btn => {
|
document.querySelectorAll('.toggle-btn').forEach(btn => {
|
||||||
btn.addEventListener('click', async () => {
|
btn.addEventListener('click', async () => {
|
||||||
const current = btn.dataset.state;
|
const current = btn.dataset.state;
|
||||||
@ -335,7 +337,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('sendControl Fehler:', err);
|
console.error('sendControl Fehler:', err);
|
||||||
// Bei Fehler: Verbindungsprüfung triggern
|
|
||||||
updateStatus(false, 'Fehler beim Senden');
|
updateStatus(false, 'Fehler beim Senden');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -355,7 +356,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
btn.addEventListener('click', async () => {
|
btn.addEventListener('click', async () => {
|
||||||
const soundId = btn.dataset.soundId;
|
const soundId = btn.dataset.soundId;
|
||||||
|
|
||||||
// Alten Play-Button zurücksetzen
|
|
||||||
if (currentSoundButton && currentSoundButton !== btn) {
|
if (currentSoundButton && currentSoundButton !== btn) {
|
||||||
currentSoundButton.classList.remove('btn-success');
|
currentSoundButton.classList.remove('btn-success');
|
||||||
currentSoundButton.classList.add('btn-outline-primary', 'btn-outline-secondary');
|
currentSoundButton.classList.add('btn-outline-primary', 'btn-outline-secondary');
|
||||||
@ -395,7 +395,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── Stop-Button für aktuellen Sound
|
// ── Stop-Button für aktuellen Sound ────────────────────────────────────────
|
||||||
document.querySelectorAll('.stop-sound-btn').forEach(btn => {
|
document.querySelectorAll('.stop-sound-btn').forEach(btn => {
|
||||||
btn.addEventListener('click', async () => {
|
btn.addEventListener('click', async () => {
|
||||||
try {
|
try {
|
||||||
@ -420,7 +420,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── Volume-Regler
|
// ── Volume-Regler ──────────────────────────────────────────────────────────
|
||||||
if (volumeSlider && volumeDisplay) {
|
if (volumeSlider && volumeDisplay) {
|
||||||
volumeSlider.addEventListener('input', () => {
|
volumeSlider.addEventListener('input', () => {
|
||||||
const vol = volumeSlider.value / 100;
|
const vol = volumeSlider.value / 100;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user