Stream proxy: MediaTailor redirect gre do klienta (fix 404 po signal switchu); VU varovalka ob tihem analizatorju

This commit is contained in:
OpenClaw Agent 2026-07-17 09:04:34 +00:00
parent a0c935af7a
commit b3ce836b42
2 changed files with 12 additions and 0 deletions

View File

@ -64,7 +64,14 @@ app.get('/stream/:n/master.m3u8', async (req, res) => {
try { try {
const response = await fetch(signedMasterUrl, { const response = await fetch(signedMasterUrl, {
headers: { 'User-Agent': 'folx-live-proxy/1.0' }, headers: { 'User-Agent': 'folx-live-proxy/1.0' },
redirect: 'manual',
}); });
// Signal switch (Bunny edge rule) lahko master preusmeri na MediaTailor —
// redirect posredujemo playerju, da MediaTailor sejo drzi direktno klient.
if (response.status >= 300 && response.status < 400) {
const loc = response.headers.get('location');
if (loc) return res.redirect(302, loc);
}
if (!response.ok) { if (!response.ok) {
console.error(`[stream/${n}] origin ${response.status}: ${signedMasterUrl}`); console.error(`[stream/${n}] origin ${response.status}: ${signedMasterUrl}`);
return res.status(502).send(`Origin returned ${response.status}`); return res.status(502).send(`Origin returned ${response.status}`);

View File

@ -156,6 +156,7 @@
var audioCtx = null, analyser = null, vuRaf = null, freqData = null; var audioCtx = null, analyser = null, vuRaf = null, freqData = null;
function initAnalyser(){ function initAnalyser(){
if (audioCtx || !window.AudioContext && !window.webkitAudioContext) return; if (audioCtx || !window.AudioContext && !window.webkitAudioContext) return;
if (!(window.Hls && Hls.isSupported())) return; // native HLS (Safari): CORS taint bi ubil zvok
try { try {
audioCtx = new (window.AudioContext || window.webkitAudioContext)(); audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var src = audioCtx.createMediaElementSource(video); var src = audioCtx.createMediaElementSource(video);
@ -167,9 +168,13 @@
freqData = new Uint8Array(analyser.frequencyBinCount); freqData = new Uint8Array(analyser.frequencyBinCount);
} catch(e) { audioCtx = null; analyser = null; } } catch(e) { audioCtx = null; analyser = null; }
} }
var vuZeroFrames = 0;
function vuLoop(){ function vuLoop(){
if (!analyser) return; if (!analyser) return;
analyser.getByteFrequencyData(freqData); analyser.getByteFrequencyData(freqData);
var total = 0; for (var z = 0; z < freqData.length; z++) total += freqData[z];
if (total === 0) { if (++vuZeroFrames > 150 && !video.paused && !video.muted) { vuEl.classList.remove('live'); for (var q = 0; q < vuBars.length; q++) vuBars[q].style.transform=''; vuRaf = requestAnimationFrame(vuLoop); return; } }
else { vuZeroFrames = 0; if (!video.muted) vuEl.classList.add('live'); }
var n = vuBars.length; // 7 stolpcev, razporejenih cez spekter (bas -> visine) var n = vuBars.length; // 7 stolpcev, razporejenih cez spekter (bas -> visine)
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {
var a = Math.floor(i * freqData.length / (n + 4)); var a = Math.floor(i * freqData.length / (n + 4));