mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 12:14:46 -04:00
Use a longer hls timeout delay
This commit is contained in:
parent
e79e568a4c
commit
1dd3e37a37
@ -34,7 +34,7 @@ import { useAtomValue, useSetAtom, useAtom } from "jotai";
|
|||||||
import { useYoshiki } from "yoshiki";
|
import { useYoshiki } from "yoshiki";
|
||||||
import SubtitleOctopus from "libass-wasm";
|
import SubtitleOctopus from "libass-wasm";
|
||||||
import { playAtom, PlayMode, playModeAtom, subtitleAtom } from "./state";
|
import { playAtom, PlayMode, playModeAtom, subtitleAtom } from "./state";
|
||||||
import Hls, { Level } from "hls.js";
|
import Hls, { Level, LoadPolicy } from "hls.js";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Menu } from "@kyoo/primitives";
|
import { Menu } from "@kyoo/primitives";
|
||||||
import toVttBlob from "srt-webvtt";
|
import toVttBlob from "srt-webvtt";
|
||||||
@ -54,6 +54,23 @@ let client_id = typeof window === "undefined" ? "ssr" : uuidv4();
|
|||||||
const initHls = async (): Promise<Hls> => {
|
const initHls = async (): Promise<Hls> => {
|
||||||
if (hls !== null) return hls;
|
if (hls !== null) return hls;
|
||||||
const token = await getToken();
|
const token = await getToken();
|
||||||
|
|
||||||
|
const loadPolicy: LoadPolicy = {
|
||||||
|
default: {
|
||||||
|
maxTimeToFirstByteMs: Infinity,
|
||||||
|
maxLoadTimeMs: 60_000,
|
||||||
|
timeoutRetry: {
|
||||||
|
maxNumRetry: 2,
|
||||||
|
retryDelayMs: 0,
|
||||||
|
maxRetryDelayMs: 0,
|
||||||
|
},
|
||||||
|
errorRetry: {
|
||||||
|
maxNumRetry: 1,
|
||||||
|
retryDelayMs: 0,
|
||||||
|
maxRetryDelayMs: 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
hls = new Hls({
|
hls = new Hls({
|
||||||
xhrSetup: (xhr) => {
|
xhrSetup: (xhr) => {
|
||||||
if (token) xhr.setRequestHeader("Authorization", `Bearer: ${token}`);
|
if (token) xhr.setRequestHeader("Authorization", `Bearer: ${token}`);
|
||||||
@ -62,6 +79,12 @@ const initHls = async (): Promise<Hls> => {
|
|||||||
autoStartLoad: false,
|
autoStartLoad: false,
|
||||||
// debug: true,
|
// debug: true,
|
||||||
startPosition: 0,
|
startPosition: 0,
|
||||||
|
fragLoadPolicy: loadPolicy,
|
||||||
|
keyLoadPolicy: loadPolicy,
|
||||||
|
certLoadPolicy: loadPolicy,
|
||||||
|
playlistLoadPolicy: loadPolicy,
|
||||||
|
manifestLoadPolicy: loadPolicy,
|
||||||
|
steeringManifestLoadPolicy: loadPolicy,
|
||||||
});
|
});
|
||||||
// hls.currentLevel = hls.startLevel;
|
// hls.currentLevel = hls.startLevel;
|
||||||
return hls;
|
return hls;
|
||||||
@ -102,7 +125,7 @@ const Video = forwardRef<{ seek: (value: number) => void }, VideoProps>(function
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ref.current || paused === ref.current.paused) return;
|
if (!ref.current || paused === ref.current.paused) return;
|
||||||
if (paused) ref.current?.pause();
|
if (paused) ref.current?.pause();
|
||||||
else ref.current?.play().catch(() => {});
|
else ref.current?.play().catch(() => { });
|
||||||
}, [paused]);
|
}, [paused]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ref.current || !volume) return;
|
if (!ref.current || !volume) return;
|
||||||
@ -134,7 +157,7 @@ const Video = forwardRef<{ seek: (value: number) => void }, VideoProps>(function
|
|||||||
hls.on(Hls.Events.MANIFEST_LOADED, async () => {
|
hls.on(Hls.Events.MANIFEST_LOADED, async () => {
|
||||||
try {
|
try {
|
||||||
await ref.current?.play();
|
await ref.current?.play();
|
||||||
} catch {}
|
} catch { }
|
||||||
});
|
});
|
||||||
hls.on(Hls.Events.ERROR, (_, d) => {
|
hls.on(Hls.Events.ERROR, (_, d) => {
|
||||||
if (!d.fatal || !hls?.media) return;
|
if (!d.fatal || !hls?.media) return;
|
||||||
@ -267,8 +290,8 @@ const toWebVtt = async (srtUrl: string) => {
|
|||||||
const query = await fetch(srtUrl, {
|
const query = await fetch(srtUrl, {
|
||||||
headers: token
|
headers: token
|
||||||
? {
|
? {
|
||||||
Authorization: token,
|
Authorization: token,
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
});
|
});
|
||||||
const srt = await query.blob();
|
const srt = await query.blob();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user