This commit is contained in:
team3
2026-08-31 11:54:20 +02:00
parent f29a4106bb
commit e7216138c7
21 changed files with 1517 additions and 87 deletions

18
frontend/src/live.js Normal file
View File

@@ -0,0 +1,18 @@
// Ein Kanal für die ganze Seite. Mehrere Komponenten lauschen mit, ohne
// dass jede eine eigene Verbindung aufmacht.
let quelle = null
const hoerer = new Set()
export function abonnieren(fn) {
hoerer.add(fn)
if (!quelle) {
quelle = new EventSource('/api/events')
quelle.onmessage = (ereignis) => {
const nachricht = JSON.parse(ereignis.data)
hoerer.forEach((h) => h(nachricht))
}
// Der Browser verbindet nach einem Abbruch von selbst neu
}
return () => hoerer.delete(fn)
}