Build 541864stable
Module 718499
2,050 characters · in 319eba3c62bdf9fc.jsDependencies
Source Raw
function(e,t,n){n.d(t,{Ay:()=>c,Bu:()=>o,OJ:()=>s,XY:()=>u});var r=n(64700),l=n(771253),a=n(876230),i=n(614269);let u=8e5,s=20,o=30;function c(e,t){let{src:n,initialTimeSec:c=0,onError:d,onHlsInstance:m,crossOrigin:f="anonymous"}=t,p=r.useRef(null),h=r.useRef(c);h.current=c;let x=r.useRef(d),E=r.useRef(m),v=r.useRef(f);v.current=f,r.useEffect(()=>{x.current=d},[d]),r.useEffect(()=>{E.current=m},[m]);let g=i.u.isHlsUrl(n)&&l.Ay.isSupported();return r.useEffect(()=>{if(!g||null==n||null==e.current)return;let t=e.current,r=new l.Ay({backBufferLength:s,maxBufferLength:o,startPosition:h.current,startFragPrefetch:!0,startLevel:-1,xhrSetup:e=>{e.withCredentials="use-credentials"===v.current},fetchSetup:(e,t)=>(t.credentials=function(e){switch(e){case"use-credentials":return"include";case"anonymous":case null:return"same-origin"}}(v.current),new Request(e.url,t))});p.current=r,E.current?.(r);let i=0,c=()=>{r.mainForwardBufferInfo?.len===0&&r.trigger(l.Ay.Events.BUFFER_FLUSHING,{startOffset:t.currentTime,endOffset:1/0,type:"video"})};return r.on(l.Ay.Events.FRAG_LOADING,()=>{r.config.minAutoBitrate!==u&&(r.config.minAutoBitrate=u)}),r.on(l.Ay.Events.ERROR,(e,t)=>{if(x.current?.(function(e){switch(e){case l.Ay.ErrorTypes.NETWORK_ERROR:return a.SB.HLS_NETWORK_ERROR;case l.Ay.ErrorTypes.MEDIA_ERROR:return a.SB.HLS_MEDIA_ERROR;case l.Ay.ErrorTypes.MUX_ERROR:return a.SB.HLS_MUX_ERROR;case l.Ay.ErrorTypes.KEY_SYSTEM_ERROR:return a.SB.HLS_KEY_SYSTEM_ERROR;default:return a.SB.HLS_OTHER_ERROR}}(t.type),{errorDetails:t.details,fatal:t.fatal}),t.fatal){if(i>=3){r.destroy(),p.current=null,E.current?.(null);return}switch(i++,t.type){case l.Ay.ErrorTypes.NETWORK_ERROR:r.startLoad();break;case l.Ay.ErrorTypes.MEDIA_ERROR:r.recoverMediaError();break;default:r.destroy(),p.current=null,E.current?.(null)}}}),t.addEventListener("seeking",c),r.loadSource(n),r.attachMedia(t),()=>{t.removeEventListener("seeking",c),p.current===r&&(r.destroy(),p.current=null,E.current?.(null)),t.removeAttribute("src"),t.load()}},[g,n,e]),{isHlsActive:g,hlsRef:p}}}