var g=Object.defineProperty;var p=(r,e,t)=>e in r?g(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var i=(r,e,t)=>p(r,typeof e!="symbol"?e+"":e,t);import{m as d,f as b,R as f,C as j,j as v}from"./index-DGn1DPCK.js";import{C as _}from"./camera-DJLV_IoI.js";function w(r){return new Worker(""+new URL("mjpegStream.worker-LO74F1Jz.js",import.meta.url).href,{name:r==null?void 0:r.name})}var k=Object.defineProperty,O=Object.getOwnPropertyDescriptor,l=(r,e,t,s)=>{for(var a=s>1?void 0:s?O(e,t):e,o=r.length-1,m;o>=0;o--)(m=r[o])&&(a=(s?m(e,t,a):m(a))||a);return s&&a&&k(e,t,a),a};let n=class extends d(_){constructor(){super(...arguments);i(this,"cameraImage");i(this,"startTime",0);i(this,"time",0);i(this,"timeSmoothing",.6);i(this,"worker",null);i(this,"imageObjectUrl",null)}handleImageLoad(){this.updateStatus("connected"),this.revokeImageObjectURL()}handleImageError(){this.updateStatus("error"),this.revokeImageObjectURL()}revokeImageObjectURL(){const t=this.imageObjectUrl;t!=null&&(URL.revokeObjectURL(t),this.imageObjectUrl=null)}startPlayback(){try{this.updateStatus("connecting");const t=this.buildAbsoluteUrl(this.camera.stream_url||"");t.searchParams.set("cacheBust",Date.now().toString());const s=this.worker=new w;s.addEventListener("message",o=>{const m=o.data;switch(m.action){case"frame":{const c=performance.now(),h=c-this.startTime;this.time=this.time*this.timeSmoothing+h*(1-this.timeSmoothing),this.startTime=c,this.time!==0&&this.updateFramesPerSecond(Math.round(1e3/this.time)),this.revokeImageObjectURL();const u=new Blob([m.data.buffer],{type:"image/jpeg"});this.cameraImage.src=this.imageObjectUrl=URL.createObjectURL(u);break}case"done":this.stopPlayback();break;case"error":this.updateStatus("error"),this.stopPlayback();break}});const a={action:"start",url:t.toString()};this.time=0,this.startTime=performance.now(),s.postMessage(a)}catch(t){b.error(`[MjpegstreamerCamera] failed to start playback "${this.camera.name}"`,t),this.updateStatus("error")}}stopPlayback(){var t;(t=this.worker)==null||t.terminate(),this.worker=null,this.revokeImageObjectURL(),this.updateStatus("disconnected"),this.cameraImage.src=""}};l([f("streamingElement")],n.prototype,"cameraImage",2);n=l([j({})],n);var U=function(){var e=this,t=e._self._c;return e._self._setupProxy,t("img",{directives:[{name:"show",rawName:"v-show",value:e.status==="connected",expression:"status === 'connected'"}],ref:"streamingElement",style:e.cameraStyle,attrs:{crossorigin:e.crossorigin},on:{load:e.handleImageLoad,error:e.handleImageError}})},L=[],S=v(n,U,L,!1,null,null);const C=S.exports;export{C as default};
