This commit is contained in:
@@ -46,12 +46,19 @@
|
||||
const apiLive = !!it.live;
|
||||
const pillClass = apiLive ? 'live' : 'off';
|
||||
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 = `
|
||||
<div class="row space-between">
|
||||
<div>
|
||||
<div class="title-strong">${it.name}</div>
|
||||
<div class="muted">Zuschauer: ${it.viewers ?? 0}</div>
|
||||
<div class="muted">Zuschauer: ${viewers}</div>
|
||||
</div>
|
||||
<div class="pill ${pillClass}" data-role="live-pill">${pillText}</div>
|
||||
</div>`;
|
||||
|
||||
@@ -65,6 +65,24 @@
|
||||
v.addEventListener('playing', () => { playerLive = true; setLive(true); });
|
||||
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(){
|
||||
// API nur als Zusatz – überschreibt NIE ein „echtes“ playerLive=true
|
||||
try {
|
||||
@@ -78,12 +96,15 @@
|
||||
const combinedLive = playerLive || apiLive;
|
||||
setLive(combinedLive);
|
||||
|
||||
let viewers = it.viewers ?? 0;
|
||||
if (combinedLive && viewers === 0) {
|
||||
// Wir sehen selbst Video → mindestens 1 Betrachter
|
||||
viewers = '≥1';
|
||||
let viewers = pickViewers(it);
|
||||
|
||||
// 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;
|
||||
}
|
||||
viewersEl.textContent = 'Zuschauer: ' + viewers;
|
||||
} catch (_) {
|
||||
// Bei API-Fehler nichts überschreiben
|
||||
}
|
||||
@@ -110,9 +131,15 @@
|
||||
const combinedLive = playerLive || apiLive;
|
||||
setLive(combinedLive);
|
||||
|
||||
let viewers = it.viewers ?? 0;
|
||||
if (combinedLive && viewers === 0) viewers = '≥1';
|
||||
viewersEl.textContent = 'Zuschauer: ' + viewers;
|
||||
let viewers = pickViewers(it);
|
||||
|
||||
// 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 */ }
|
||||
});
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user