From 53a1d83d434743a6801f1330748e8a069b8a1b4e Mon Sep 17 00:00:00 2001 From: Sebastjan Date: Sat, 25 Apr 2026 15:15:07 +0200 Subject: [PATCH] EMERGENCY REVERT - TV detection caused infinite loop; back to working state --- views/index.ejs | 72 +++++-------------------------------------------- 1 file changed, 6 insertions(+), 66 deletions(-) diff --git a/views/index.ejs b/views/index.ejs index e20b8f3..6e95ab9 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -643,14 +643,6 @@ function showMsg(html) { msg.innerHTML = html; msg.classList.add('visible'); } function hideMsg() { msg.classList.remove('visible'); } - // Device detection — Samsung Tizen, LG webOS, and other smart TVs need - // smaller buffers and lower resolution caps to avoid stalling. - const UA = navigator.userAgent || ''; - const IS_SAMSUNG_TV = /Tizen|SMART-TV|SmartTV|SamsungBrowser/i.test(UA); - const IS_LG_TV = /webOS|Web0S|LG SmartTV/i.test(UA); - const IS_TV = IS_SAMSUNG_TV || IS_LG_TV || /Hisense|Bravia|Roku|AppleTV|GoogleTV|AndroidTV/i.test(UA); - const IS_LOW_POWER = IS_TV; - function attach() { try { hls && hls.destroy(); } catch (e) {} hls = null; @@ -663,31 +655,7 @@ } if (window.Hls && window.Hls.isSupported()) { - // TV-tuned settings (smaller buffers, 720p cap, more aggressive recovery) - const cfg = IS_LOW_POWER ? { - liveDurationInfinity: true, - liveSyncDurationCount: 3, - liveMaxLatencyDurationCount: 8, - backBufferLength: 10, // Tizen has tight memory - maxBufferLength: 20, - maxMaxBufferLength: 30, - maxBufferSize: 30 * 1000 * 1000, // 30 MB buffer cap (Tizen-friendly) - manifestLoadingTimeOut: 15000, - manifestLoadingMaxRetry: 8, - manifestLoadingRetryDelay: 1000, - levelLoadingTimeOut: 15000, - levelLoadingMaxRetry: 8, - fragLoadingTimeOut: 25000, - fragLoadingMaxRetry: 8, - fragLoadingRetryDelay: 1000, - // Lock to 720p on TVs — Tizen decoder struggles with 1080p HLS.js - startLevel: -1, - capLevelToPlayerSize: false, - abrEwmaDefaultEstimate: 2000000, - testBandwidth: true, - abrBandWidthFactor: 0.9, - abrBandWidthUpFactor: 0.6, - } : { + hls = new Hls({ liveDurationInfinity: true, liveSyncDurationCount: 4, backBufferLength: 30, @@ -702,33 +670,17 @@ testBandwidth: true, abrBandWidthFactor: 0.95, abrBandWidthUpFactor: 0.7, - }; - hls = new Hls(cfg); + }); hls.loadSource(HLS_URL); hls.attachMedia(video); hls.on(Hls.Events.MANIFEST_PARSED, () => { try { if (hls.levels && hls.levels.length) { - if (IS_LOW_POWER) { - // On Samsung TV / smart TV: lock to 720p (720p only, disable both 1080p and 480p). - // 1080p stalls on Tizen decoder, 480p is desynced from Rok's encoder. - hls.levels.forEach((lvl) => { - lvl.enabled = (lvl.height === 720); - }); - // Also force start at 720p - const idx720 = hls.levels.findIndex(l => l.height === 720); - if (idx720 >= 0) { - hls.currentLevel = idx720; - hls.loadLevel = idx720; + hls.levels.forEach((lvl) => { + if (lvl.height && lvl.height <= 480) { + lvl.enabled = false; } - } else { - // Desktop/mobile: only disable 480p (desynced); allow 1080p ↔ 720p ABR. - hls.levels.forEach((lvl) => { - if (lvl.height && lvl.height <= 480) { - lvl.enabled = false; - } - }); - } + }); } } catch (e) {} hideMsg(); @@ -736,21 +688,9 @@ }); hls.on(Hls.Events.ERROR, (_e, data) => { if (!data.fatal) return; - // Try in-place recovery first (faster than full reattach, less disruptive on TV) - if (data.type === Hls.ErrorTypes.NETWORK_ERROR) { - try { hls.startLoad(); return; } catch (e) {} - } - if (data.type === Hls.ErrorTypes.MEDIA_ERROR) { - try { hls.recoverMediaError(); return; } catch (e) {} - } - // Last resort: full reattach showMsg('
Verbindung wird wiederhergestellt…
'); setTimeout(() => { attach(); }, 3000); }); - // Buffer stall recovery — esp. needed on Samsung TV - hls.on(Hls.Events.BUFFER_STALLED_ERROR, () => { - try { hls.startLoad(); } catch (e) {} - }); } else { showMsg('
HLS wird von diesem Browser nicht unterstützt.
'); }