import{a as e,l as t,n,t as r,u as i}from"./_plugin-vue2_normalizer-Vm4EDAeQ.js";import{t as a}from"./browser-1D2tZwAR.js";import{t as o}from"./camera-DKiOc18c.js";var s=class extends i(o){cameraImage;cameraImageSource=``;cameraImageSourceUrl=null;requestStartTime=0;startTime=0;time=0;requestTime=0;timeSmoothing=.6;requestTimeSmoothing=.1;get autoRaiseFrameEvent(){return!1}handleImageLoad(){this.updateStatus(`connected`),this.$emit(`frame`,this.streamingElement);let e=!document.hasFocus()&&this.camera.target_fps_idle||this.camera.target_fps||10,t=performance.now(),n=t-this.startTime;this.time=this.time*this.timeSmoothing+n*(1-this.timeSmoothing),this.startTime=t;let r=1e3/e,i=performance.now()-this.requestStartTime;this.requestTime=this.requestTime*this.requestTimeSmoothing+i*(1-this.requestTimeSmoothing);let a=Math.max(0,r-this.requestTime);this.$nextTick(()=>{setTimeout(this.handleRefresh,a)})}handleRefresh(){document.hidden?this.stopPlayback():(this.time!==0&&this.updateFramesPerSecond(Math.round(1e3/this.time)),this.$nextTick(()=>this.updateCameraImageSource()))}updateCameraImageSource(){let 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.time=0,this.startTime=performance.now(),this.updateCameraImageSource();let e=this.buildAbsoluteUrl(this.camera.stream_url||``);e.searchParams.set(`cacheBust`,Date.now().toString()),this.updateRawCameraUrl(e.toString())}catch(e){a.error(`[MjpegstreamerAdaptiveCamera] failed to start playback "${this.camera.name}"`,e)}}stopPlayback(){this.updateStatus(`disconnected`),this.cameraImageSourceUrl=null,this.cameraImageSource=``,this.cameraImage.src=``}};n([e(`streamingElement`)],s.prototype,`cameraImage`,void 0),s=n([t({})],s);var c=r(s,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:{src:e.cameraImageSource,crossorigin:e.crossorigin},on:{load:e.handleImageLoad,error:function(t){return e.updateStatus(`error`)}}})},[],!1,null,null,null,null).exports;export{c as default};