preview-7683c203.js 5.0 KB

12
  1. import{d as E,c as u,r as F,Y as A,j as H,bg as q,c9 as J,o as K,cL as Y,be as Z,Z as T,a1 as N,cI as Q,cJ as X,n as O,T as ee,cl as te,a7 as ae,ay as oe,aV as re,at as ie,f as ne,h as se,av as ce,$ as de}from"./index-8a67e3df.js";import{d as x,g as z,V as G,W as le,b as P,c as B,a as R,A as $,e as ue,F as fe,D as ve,f as M,C as me}from"./canvas-2aaf4e1d.js";import"./dayjs-919e6097.js";import{G as pe}from"./gb28181-a8ace5d9.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,g=null,p=null;function k(){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:k()?z:G),l=V(v?R:$);const W=F(new le(""));let b=!1;A(()=>{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&&(D.value=!1,y.writeVideo(a),a.close())}),e.on(P.Error,a=>{console.error(a),b=!1,s instanceof x&&(s=I(k()?z:G),s.initialize().then(()=>{p&&s.configure({...p})}))}),e}function V(t){const e=new t;return e.on(B.Error,a=>{console.error(a),e instanceof R&&(l=V($),l.initialize().then(()=>{g&&l.configure({...g})}))}),e.on(B.AudioFrame,a=>{f?f.write(a):y&&(D.value=!1,y.writeAudio(a))}),e}function j(){l?.close(),g=null}function L(){s?.close(),p=null}function C(){i.value&&o.webrtcStream?.mediaStream&&(_.value=o.webrtcStream.mediaStream)}H(()=>{o.webrtcStream?.off("change",C)}),A(()=>{W.mediaStream&&(_.value=W.mediaStream),o.webrtcStream&&(C(),o.webrtcStream.on("change",C))}),A(async()=>{if(o.streamPath)try{r&&(j(),L(),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}`),U(new fe(r,ve.PUSH)),await r.connect()}catch(t){J.error({message:"播放失败",description:t instanceof Event?"连接失败":String(t)}),n("play","connect error")}});function U(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(M.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(M.AUDIO_ENCODER_CONFIG_CHANGED,e=>{g=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(!b&&e.type!=="key"){console.warn("Waiting for keyframe...");return}e.type==="key"&&(b||(b=!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 D=u(!0);return K(()=>{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}Y(i.value,"canplay",()=>{D.value=!1})}),Z(()=>{r?.close(),d&&d.close(),f&&f.close()}),(t,e)=>(T(),N("div",we,[Q(O(ee(te),{class:"loading",size:"large"},null,512),[[X,D.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(),N("div",{class:"h-full w-full flex justify-center items-center m-auto relative",style:ce(`width: ${r.value}%; height: ${r.value}%`)},[O(_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))}}),ge=E({name:"Channel"}),Ve=E({...ge,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};
  2. //# sourceMappingURL=preview-7683c203.js.map