fix playback: vendor hls.js locally, surface stream/API errors visibly
- jsdelivr CDN was a silent single point of failure (Hls undefined -> unhandled rejection -> black screen with no feedback) - play() now catches API errors; hls fatal + video media errors render 'Stream error: ...' under the player - server now binds 0.0.0.0 (LAN access); was 127.0.0.1 only
This commit is contained in:
1 parent
e4dde86d85
commit
6c752ae5bc
3 files changed
+29
-9
No files matched your search
+26
-8
@@ -24,6 +24,12 @@ function fail(err) {
|
||||
main.append(el("p", "error", "Error: " + err.message));
|
||||
}
|
||||
|
||||
function showStreamError(msg) {
|
||||
const p = el("p", "error", "Stream error: " + msg);
|
||||
const player = document.getElementById("player");
|
||||
if (player) player.append(p); else fail(new Error(msg));
|
||||
}
|
||||
|
||||
// ---------- history ----------
|
||||
const HKEY = "aniweb.history";
|
||||
const hist = () => JSON.parse(localStorage.getItem(HKEY) || "[]");
|
||||
@@ -139,14 +145,26 @@ function videoEl() {
|
||||
function stopHls() { if (hls) { hls.destroy(); hls = null; } }
|
||||
|
||||
async function play(ep_id, ep_no) {
|
||||
const s = await api(`/api/episode/${ep_id}/stream?lang=${lang}`);
|
||||
stopHls();
|
||||
const v = videoEl();
|
||||
document.getElementById("player").replaceChildren(v);
|
||||
if (!Hls.isSupported()) throw new Error("HLS not supported in this browser");
|
||||
hls = new Hls();
|
||||
hls.loadSource("/stream/" + s.token);
|
||||
hls.attachMedia(v);
|
||||
try {
|
||||
const s = await api(`/api/episode/${ep_id}/stream?lang=${lang}`);
|
||||
stopHls();
|
||||
const v = videoEl();
|
||||
document.getElementById("player").replaceChildren(v);
|
||||
if (!window.Hls || !Hls.isSupported()) throw new Error("HLS not supported in this browser");
|
||||
hls = new Hls();
|
||||
hls.on(Hls.Events.ERROR, (_, data) => {
|
||||
if (data.fatal) {
|
||||
showStreamError(`${data.type}: ${data.details}` +
|
||||
(data.response ? ` (HTTP ${data.response.code})` : ""));
|
||||
stopHls();
|
||||
}
|
||||
});
|
||||
hls.loadSource("/stream/" + s.token);
|
||||
hls.attachMedia(v);
|
||||
v.onerror = () => showStreamError("media error: " + (v.error?.message || v.error?.code));
|
||||
} catch (e) {
|
||||
showStreamError(e.message);
|
||||
}
|
||||
pushHistory({title: detail.name, slug_id: detail.slug_id, season_id: seasonId,
|
||||
ep_id, lang, ep: ep_no});
|
||||
document.title = `${detail.name} E${ep_no} — ani-web`;
|
||||
|
||||
Reference in new issue
Block a user