Files
dogfather-universe/workspace/assets/js/koppeln.js
T
DogFatherGitandClaude Opus 5.5 7071b0cd66 Reaction M9: Koppel-Seite und Fernbedienung fuers Handy
Grosse Reaktionsknoepfe (ueber den Saal-Chat), Dogen, Chat, Anschluss
window.Fernbedienung.anschliessen fuer Nochmal!/Tipps. Ruft nie /dabei.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 13:58:40 +01:00

63 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* =====================================================================
DIE KOPPEL-SEITE (04.11.2026, Reaction M9) – siehe koppeln.html
Der Code wird SOFORT aus der Adresszeile genommen (replaceState): So
steht er weder im Verlauf noch in einem Lesezeichen, und wer über die
Schulter auf das Handy sieht, sieht ihn nicht. Danach lebt er nur noch
in dieser Variablen, bis er eingelöst ist.
===================================================================== */
(() => {
'use strict';
const $ = (id) => document.getElementById(id);
const satzFeld = $('kp-satz');
const wahl = $('kp-wahl');
const main = $('koppeln');
const code = decodeURIComponent(location.hash.slice(1) || '');
try { history.replaceState(null, '', location.pathname); } catch { /* sehr alter Browser – dann bleibt er stehen */ }
const sag = (t, stand) => { satzFeld.textContent = t; if (stand) main.dataset.stand = stand; };
const satz = (j, sonst) => (window.sagWas ? window.sagWas(j?.fehler, sonst) : sonst);
async function einloesen(wechseln) {
wahl.hidden = true;
sag('Einen Moment – dein Handy wird verbunden …', 'laedt');
let a; let j = null;
try {
a = await fetch('/workspace/api/koppeln', {
method: 'POST',
credentials: 'same-origin',
cache: 'no-store',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(wechseln ? { code, wechseln: true } : { code }),
});
j = await a.json().catch(() => null);
} catch {
sag('Keine Verbindung zum Server. Prüf das Netz und scanne den Code noch einmal.', 'fehler');
return;
}
if (a.ok && j?.weiter) {
sag('Verbunden. Die Fernbedienung öffnet sich …', 'gut');
location.replace(j.weiter);
return;
}
if (a.status === 409 && j?.fehler === 'anders_angemeldet') {
sag(`Dieses Handy ist schon als ${j.name || 'jemand anderes'} angemeldet. Mit dem Zugang aus dem Saal koppeln und wechseln?`, 'frage');
wahl.hidden = false;
$('kp-wechseln').focus();
return;
}
if (a.status === 401) {
sag('Dieser Code gilt nicht (mehr). Ein Code gilt 2 Minuten und nur einmal – lass dir im Saal unter „Nur Kino“ einen neuen zeigen.', 'fehler');
return;
}
sag(satz(j, 'Das Koppeln ging gerade nicht. Versuch es gleich noch einmal.'), 'fehler');
}
$('kp-wechseln').addEventListener('click', () => einloesen(true));
if (!code) {
sag('Hier fehlt der Code. Scanne den QR-Code im Saal noch einmal – er steht unter „Nur Kino“ → „Handy als Fernbedienung“.', 'fehler');
return;
}
einloesen(false);
})();