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