preview-003de7f8.js 5.0 KB

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