This commit is contained in:
@@ -46,12 +46,19 @@
|
|||||||
const apiLive = !!it.live;
|
const apiLive = !!it.live;
|
||||||
const pillClass = apiLive ? 'live' : 'off';
|
const pillClass = apiLive ? 'live' : 'off';
|
||||||
const pillText = apiLive ? 'LIVE' : 'Offline';
|
const pillText = apiLive ? 'LIVE' : 'Offline';
|
||||||
|
const viewers = (()=>{
|
||||||
|
const cands = [it.viewers, it.viewerCount, it.viewCount, it.watchers, it.clients, it.hls_viewers, it.stats && it.stats.viewers];
|
||||||
|
for (const v of cands){
|
||||||
|
const n = typeof v === 'string' ? parseInt(v,10) : v;
|
||||||
|
if (Number.isFinite(n) && n >= 0) return n;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
})();
|
||||||
a.innerHTML = `
|
a.innerHTML = `
|
||||||
<div class="row space-between">
|
<div class="row space-between">
|
||||||
<div>
|
<div>
|
||||||
<div class="title-strong">${it.name}</div>
|
<div class="title-strong">${it.name}</div>
|
||||||
<div class="muted">Zuschauer: ${it.viewers ?? 0}</div>
|
<div class="muted">Zuschauer: ${viewers}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="pill ${pillClass}" data-role="live-pill">${pillText}</div>
|
<div class="pill ${pillClass}" data-role="live-pill">${pillText}</div>
|
||||||
</div>`;
|
</div>`;
|
||||||
|
|||||||
@@ -65,6 +65,24 @@
|
|||||||
v.addEventListener('playing', () => { playerLive = true; setLive(true); });
|
v.addEventListener('playing', () => { playerLive = true; setLive(true); });
|
||||||
v.addEventListener('error', () => { playerLive = false; setLive(false); });
|
v.addEventListener('error', () => { playerLive = false; setLive(false); });
|
||||||
|
|
||||||
|
function pickViewers(it){
|
||||||
|
// Häufige Feldnamen aus diversen Backends
|
||||||
|
const candidates = [
|
||||||
|
it.viewers,
|
||||||
|
it.viewerCount,
|
||||||
|
it.viewCount,
|
||||||
|
it.watchers,
|
||||||
|
it.clients,
|
||||||
|
it.hls_viewers,
|
||||||
|
it.stats && it.stats.viewers,
|
||||||
|
];
|
||||||
|
for (const v of candidates) {
|
||||||
|
const n = typeof v === 'string' ? parseInt(v, 10) : v;
|
||||||
|
if (Number.isFinite(n) && n >= 0) return n;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
async function refreshMeta(){
|
async function refreshMeta(){
|
||||||
// API nur als Zusatz – überschreibt NIE ein „echtes“ playerLive=true
|
// API nur als Zusatz – überschreibt NIE ein „echtes“ playerLive=true
|
||||||
try {
|
try {
|
||||||
@@ -78,12 +96,15 @@
|
|||||||
const combinedLive = playerLive || apiLive;
|
const combinedLive = playerLive || apiLive;
|
||||||
setLive(combinedLive);
|
setLive(combinedLive);
|
||||||
|
|
||||||
let viewers = it.viewers ?? 0;
|
let viewers = pickViewers(it);
|
||||||
if (combinedLive && viewers === 0) {
|
|
||||||
// Wir sehen selbst Video → mindestens 1 Betrachter
|
// Nur wenn API wirklich 0/fehlend meldet, aber der Player sicher läuft,
|
||||||
viewers = '≥1';
|
// zeigen wir "≥1" als sinnvollen Fallback:
|
||||||
|
if (playerLive && viewers === 0) {
|
||||||
|
viewersEl.textContent = 'Zuschauer: ≥1';
|
||||||
|
} else {
|
||||||
|
viewersEl.textContent = 'Zuschauer: ' + viewers;
|
||||||
}
|
}
|
||||||
viewersEl.textContent = 'Zuschauer: ' + viewers;
|
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
// Bei API-Fehler nichts überschreiben
|
// Bei API-Fehler nichts überschreiben
|
||||||
}
|
}
|
||||||
@@ -110,9 +131,15 @@
|
|||||||
const combinedLive = playerLive || apiLive;
|
const combinedLive = playerLive || apiLive;
|
||||||
setLive(combinedLive);
|
setLive(combinedLive);
|
||||||
|
|
||||||
let viewers = it.viewers ?? 0;
|
let viewers = pickViewers(it);
|
||||||
if (combinedLive && viewers === 0) viewers = '≥1';
|
|
||||||
viewersEl.textContent = 'Zuschauer: ' + viewers;
|
// Nur wenn API wirklich 0/fehlend meldet, aber der Player sicher läuft,
|
||||||
|
// zeigen wir "≥1" als sinnvollen Fallback:
|
||||||
|
if (playerLive && viewers === 0) {
|
||||||
|
viewersEl.textContent = 'Zuschauer: ≥1';
|
||||||
|
} else {
|
||||||
|
viewersEl.textContent = 'Zuschauer: ' + viewers;
|
||||||
|
}
|
||||||
} catch(e){ /* ignore */ }
|
} catch(e){ /* ignore */ }
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user