Stream proxy: MediaTailor redirect gre do klienta (fix 404 po signal switchu); VU varovalka ob tihem analizatorju
This commit is contained in:
parent
a0c935af7a
commit
b3ce836b42
@ -64,7 +64,14 @@ app.get('/stream/:n/master.m3u8', async (req, res) => {
|
||||
try {
|
||||
const response = await fetch(signedMasterUrl, {
|
||||
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) {
|
||||
console.error(`[stream/${n}] origin ${response.status}: ${signedMasterUrl}`);
|
||||
return res.status(502).send(`Origin returned ${response.status}`);
|
||||
|
||||
@ -156,6 +156,7 @@
|
||||
var audioCtx = null, analyser = null, vuRaf = null, freqData = null;
|
||||
function initAnalyser(){
|
||||
if (audioCtx || !window.AudioContext && !window.webkitAudioContext) return;
|
||||
if (!(window.Hls && Hls.isSupported())) return; // native HLS (Safari): CORS taint bi ubil zvok
|
||||
try {
|
||||
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
||||
var src = audioCtx.createMediaElementSource(video);
|
||||
@ -167,9 +168,13 @@
|
||||
freqData = new Uint8Array(analyser.frequencyBinCount);
|
||||
} catch(e) { audioCtx = null; analyser = null; }
|
||||
}
|
||||
var vuZeroFrames = 0;
|
||||
function vuLoop(){
|
||||
if (!analyser) return;
|
||||
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)
|
||||
for (var i = 0; i < n; i++) {
|
||||
var a = Math.floor(i * freqData.length / (n + 4));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user