0.1.17
build / test (push) Waiting to run

This commit is contained in:
Mateusz Gruszczyński committed 2026-11-17 16:50:28 +01:00
1 parent 528017b0e6
commit 9e65aa0103
27 files changed
+1053 -101

No files matched your search

+17 -3
View File
@@ -7,7 +7,9 @@
'HEVC': ['video/mp4; codecs="hvc1.1.6.L120.90"', 'video/mp4; codecs="hvc1.1.6.L123.B0"', 'video/mp4; codecs="hev1.1.6.L120.90"', 'video/mp4; codecs="hvc1.2.4.L120.90"'],
'MPEG-2': null,
'AAC': 'audio/mp4; codecs="mp4a.40.2"',
'MP2': 'audio/mpeg',
// MPEG-1 Layer II (DVB-T radio/TV sound): MSE decoders handle MP3 only, so browsers
// get it converted to AAC (cheap: the video is not touched)
'MP2': null,
'AC-3': 'audio/mp4; codecs="ac-3"',
'E-AC-3': 'audio/mp4; codecs="ec-3"',
'AAC-LATM': null
@@ -87,7 +89,11 @@
container.appendChild(badge);
var hls = null;
var destroyed = false;
var fallbackOrder = opts.transcode === false ? ['pass'] : ['pass', 'aac', 'h264'];
// full video transcoding (h264) only when the browser cannot decode the video itself
var fallbackOrder = opts.transcode === false ? ['pass'] : (supported(codec(opts.video)) ? ['pass', 'aac'] : ['pass', 'aac', 'h264']);
// viewer id: lets the server stop this viewer's previous session at once when the
// channel or profile changes (frees the tuner and ffmpeg immediately)
var viewer = Math.random().toString(36).slice(2, 10) + Date.now().toString(36);
var profile = opts.profile && opts.profile !== 'auto' ? opts.profile : pickProfile(opts.video, opts.audio, opts.transcode);
var auto = !opts.profile || opts.profile === 'auto';
var retries = 0;
@@ -122,6 +128,7 @@
if (profile !== 'pass') q.push('profile=' + profile);
if (opts.share) q.push('share=' + encodeURIComponent(opts.share));
if (opts.token) q.push('token=' + encodeURIComponent(opts.token));
if (opts.live !== false) q.push('v=' + viewer);
return '/hls/' + opts.channelId + '/index.m3u8' + (q.length ? '?' + q.join('&') : '');
}
@@ -133,6 +140,13 @@
return true;
}
function leave() {
if (opts.src || opts.live === false) return;
var u = '/hls/leave?v=' + viewer;
try { if (!(navigator.sendBeacon && navigator.sendBeacon(u))) fetch(u, { method: 'POST', keepalive: true }); } catch (e) {}
}
window.addEventListener('pagehide', leave);
function teardown() {
if (hls) { try { hls.destroy(); } catch (e) {} hls = null; }
video.removeAttribute('src');
@@ -208,7 +222,7 @@
video: video,
get profile() { return profile; },
setProfile: function (p) { auto = p === 'auto'; profile = auto ? pickProfile(opts.video, opts.audio) : p; start(); },
destroy: function () { destroyed = true; teardown(); container.innerHTML = ''; }
destroy: function () { destroyed = true; teardown(); leave(); window.removeEventListener('pagehide', leave); container.innerHTML = ''; }
};
}