var h=Object.defineProperty;var l=(a,t,e)=>t in a?h(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e;var r=(a,t,e)=>l(a,typeof t!="symbol"?t+"":t,e);import{m as p,C as g,f as d,R as f,j as S,k as _}from"./index-CBxrqwze.js";var T=Object.defineProperty,v=Object.getOwnPropertyDescriptor,c=(a,t,e,i)=>{for(var s=i>1?void 0:i?v(t,e):t,m=a.length-1,o;m>=0;m--)(o=a[m])&&(s=(i?o(t,e,s):o(s))||s);return i&&s&&T(t,e,s),s};let n=class extends p(g){constructor(){super(...arguments);r(this,"cameraImage");r(this,"cameraImageSource","");r(this,"cameraImageSourceUrl",null);r(this,"requestStartTime",performance.now());r(this,"startTime",performance.now());r(this,"time",0);r(this,"requestTime",0);r(this,"timeSmoothing",.6);r(this,"requestTimeSmoothing",.1)}get autoRaiseFrameEvent(){return!1}handleImageLoad(){this.updateStatus("connected"),this.$emit("frame",this.streamingElement);const e=!document.hasFocus()&&this.camera.target_fps_idle||this.camera.target_fps||10,i=performance.now(),s=i-this.startTime;this.time=this.time*this.timeSmoothing+s*(1-this.timeSmoothing),this.startTime=i;const m=1e3/e,o=performance.now()-this.requestStartTime;this.requestTime=this.requestTime*this.requestTimeSmoothing+o*(1-this.requestTimeSmoothing);const u=Math.max(0,m-this.requestTime);this.$nextTick(()=>{setTimeout(this.handleRefresh,u)})}handleRefresh(){if(document.hidden)this.stopPlayback();else{if(this.time!==0){const e=Math.round(1e3/this.time).toString().padStart(2,"0");this.updateFramesPerSecond(e)}this.$nextTick(()=>this.updateCameraImageSource())}}updateCameraImageSource(){const e=this.cameraImageSourceUrl;e&&(e.searchParams.set("cacheBust",Date.now().toString()),this.requestStartTime=performance.now(),this.cameraImageSource=e.toString())}startPlayback(){try{this.updateStatus("connecting"),this.cameraImageSourceUrl=this.buildAbsoluteUrl(this.camera.snapshot_url||""),this.updateCameraImageSource();const e=this.buildAbsoluteUrl(this.camera.stream_url||"");e.searchParams.set("cacheBust",Date.now().toString()),this.updateRawCameraUrl(e.toString())}catch(e){d.error(`[MjpegstreamerAdaptiveCamera] failed to start playback "${this.camera.name}"`,e)}}stopPlayback(){this.updateStatus("disconnected"),this.cameraImageSourceUrl=null,this.cameraImageSource="",this.cameraImage.src=""}};c([f("streamingElement")],n.prototype,"cameraImage",2);n=c([S({})],n);var I=function(){var t=this,e=t._self._c;return t._self._setupProxy,e("img",{directives:[{name:"show",rawName:"v-show",value:t.status==="connected",expression:"status === 'connected'"}],ref:"streamingElement",style:t.cameraStyle,attrs:{src:t.cameraImageSource,crossorigin:t.crossorigin},on:{load:t.handleImageLoad,error:function(i){return t.updateStatus("error")}}})},w=[],C=_(n,I,w,!1,null,null);const x=C.exports;export{x as default};
