import{d as E,c as u,r as L,Y as C,j as H,bh as q,c4 as K,o as Y,cT as Z,bf as J,Z as T,a1 as M,cU as Q,cV as X,n as N,T as ee,bt as te,a7 as ae,ay as oe,aW as re,at as ie,f as ne,h as se,av as ce,$ as de}from"./index-a8341fa1.js";import{V as x,b as j,c as G,j as le,d as P,A as z,e as R,f as $,W as ue,F as fe,h as ve,D as B,i as me}from"./canvas-b3f2b616.js";import"./dayjs-919e6097.js";import{G as pe}from"./gb28181-0e98f3aa.js";const we={class:"video-container"},ye=["srcObject"],he=E({__name:"jb4-ws-flv",props:{videoShadow:{},streamPath:{},webrtcStream:{},speed:{},pause:{type:Boolean},startTime:{}},emits:["postion","play"],setup(h,{emit:c}){const o=h,n=c;let r,w=0,m=0;const i=u();let f,d;const _=u(),v=typeof VideoDecoder=="function",S=u();let y=null,b=null,p=null;function W(){return typeof WebAssembly>"u"?!1:WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11]))}let s=I(v?x:W()?j:G),l=V(v?R:$);const k=L(new le(""));let D=!1;C(()=>{i.value&&(i.value.addEventListener("playing",()=>{n("play",!0)}),i.value.addEventListener("pause",()=>{n("play","pause")}),i.value.addEventListener("ended",()=>{n("play","ended")}),i.value.addEventListener("error",()=>{n("play","error")}))});function I(t){const e=new t;return e.on(P.VideoCodecInfo,a=>{`${a.width}${a.height}`}),e.on(P.VideoFrame,a=>{d?d.write(a):y&&S.value&&(g.value=!1,y.writeVideo(a),a.close())}),e.on(P.Error,a=>{console.error(a),D=!1,s instanceof x&&(s=I(W()?j:G),s.initialize().then(()=>{p&&s.configure({...p})}))}),e}function V(t){const e=new t;return e.on(z.Error,a=>{console.error(a),e instanceof R&&(l=V($),l.initialize().then(()=>{b&&l.configure({...b})}))}),e.on(z.AudioFrame,a=>{f?f.write(a):y&&(g.value=!1,y.writeAudio(a))}),e}function O(){l?.close(),b=null}function U(){s?.close(),p=null}function A(){i.value&&o.webrtcStream?.mediaStream&&(_.value=o.webrtcStream.mediaStream)}H(()=>{o.webrtcStream?.off("change",A)}),C(()=>{k.mediaStream&&(_.value=k.mediaStream),o.webrtcStream&&(A(),o.webrtcStream.on("change",A))}),C(async()=>{if(o.streamPath)try{r&&(O(),U(),await r.close()),l=V(v?R:$),s=I(v?x:G),await s.initialize(),await l.initialize(),r=new ue(`${q("flv","","ws")}/${o.streamPath}`),F(new fe(r,ve.PUSH)),await r.connect()}catch(t){K.error({message:"播放失败",description:t instanceof Event?"连接失败":String(t)}),n("play","connect error")}});function F(t){if(v&&typeof MediaStreamTrackGenerator=="function"){const e=new MediaStreamTrackGenerator({kind:"audio"});f=e.writable.getWriter(),e.onmute=()=>{n("play","audio mute")};const a=new MediaStreamTrackGenerator({kind:"video"});d=a.writable.getWriter(),a.onmute=()=>{n("play","videomute")},_.value=new MediaStream([e,a])}t.on(B.VIDEO_ENCODER_CONFIG_CHANGED,e=>{p={...e},delete p.description,s.state==="initialized"&&s.configure(p),!v&&S.value&&(y=new me(S.value))}),t.on(B.AUDIO_ENCODER_CONFIG_CHANGED,e=>{b=e;try{l.configure({...e})}catch(a){console.error(a)}}),t.gotVideo=e=>{try{if(s.state!=="configured"){console.warn("Video decoder not configured yet, waiting...");return}if(!D&&e.type!=="key"){console.warn("Waiting for keyframe...");return}e.type==="key"&&(D||(D=!0)),s.decode(e),w=e.timestamp,o.startTime!==void 0&&o.startTime!==null&&n("postion",w-m+o.startTime)}catch(a){console.error(a,e)}},t.gotAudio=e=>{if(l.state!=="configured"){console.warn("Audio decoder not configured yet, waiting...");return}l.decode(e)}}const g=u(!0);return Y(()=>{if(!v&&i.value){const t=document.createElement("canvas");t.style.width="100%",t.style.objectFit="cover",t.style.borderRadius="6px",o.videoShadow&&(t.style.boxShadow="4px 4px 8px 4px #dedede"),i.value.parentElement?.replaceChild(t,i.value),S.value=t}Z(i.value,"canplay",()=>{g.value=!1})}),J(()=>{r?.close(),d&&d.close(),f&&f.close()}),(t,e)=>(T(),M("div",we,[Q(N(ee(te),{class:"loading",size:"large"},null,512),[[X,g.value]]),ae("video",{ref_key:"videoEle",ref:i,class:oe(["video",{videoShadow:t.videoShadow}]),srcObject:_.value,autoplay:""},null,10,ye),re(t.$slots,"default",{},void 0,!0)]))}});const _e=ie(he,[["__scopeId","data-v-fea00ff5"]]),Se=E({__name:"play",props:{isGbRecord:{type:Boolean},path:{},id:{},deviceId:{}},setup(h){const c=h,o=u(1),n=u(!0),r=u(100),w=u("ws-flv"),m=u(""),i=ne(()=>`${pe(c.isGbRecord)}${m.value}`);return se([()=>c.id,()=>c.path],([f,d])=>{d?m.value=d:f&&(m.value=`${c.id}/${c.deviceId}`)},{immediate:!0}),(f,d)=>(T(),M("div",{class:"h-full w-full flex justify-center items-center m-auto relative",style:ce(`width: ${r.value}%; height: ${r.value}%`)},[N(_e,{videoShadow:!0,streamPath:i.value,format:w.value,speed:o.value,pause:!n.value,class:"flex-1 m-r-10px"},null,8,["streamPath","format","speed","pause"])],4))}}),be=E({name:"Channel"}),Ve=E({...be,setup(h){const c=new URLSearchParams(window.location.search),o=c.get("ID")||"",n=c.get("DeviceID")||"",r={id:o,deviceId:n,isGbRecord:!1};return(w,m)=>(T(),de(Se,{id:r.id,deviceId:r.deviceId,isGbRecord:r.isGbRecord},null,8,["id","deviceId","isGbRecord"]))}});export{Ve as default}; //# sourceMappingURL=preview-c1935abb.js.map