import{l as e,o as t}from"./vue.runtime.esm-BGP6PPFT.js";import{a as n,l as r,n as i,t as a,u as o}from"./_plugin-vue2_normalizer-Vm4EDAeQ.js";import{t as s}from"./browser-1D2tZwAR.js";import{t as c}from"./camera-DKiOc18c.js";t();function l(e){return new Worker(``+new URL(`mjpegStream.worker-CkFbgHTR.js`,import.meta.url).href,{name:e?.name})}var u=class extends o(c){cameraImage;startTime=0;time=0;timeSmoothing=.6;worker=null;imageObjectUrl=null;handleImageLoad(){this.updateStatus(`connected`),this.revokeImageObjectURL()}handleImageError(){this.updateStatus(`error`),this.revokeImageObjectURL()}revokeImageObjectURL(){let e=this.imageObjectUrl;e!=null&&(URL.revokeObjectURL(e),this.imageObjectUrl=null)}startPlayback(){try{this.updateStatus(`connecting`);let t=this.buildAbsoluteUrl(this.camera.stream_url||``);t.searchParams.set(`cacheBust`,Date.now().toString());let n=this.worker=e(new l);n.onmessage=e=>{let t=e.data;switch(t.action){case`frame`:{let e=performance.now(),n=e-this.startTime;this.time=this.time*this.timeSmoothing+n*(1-this.timeSmoothing),this.startTime=e,this.time!==0&&this.updateFramesPerSecond(Math.round(1e3/this.time)),this.revokeImageObjectURL();let r=new Blob([t.data.buffer],{type:`image/jpeg`});this.cameraImage.src=this.imageObjectUrl=URL.createObjectURL(r);break}case`done`:this.stopPlayback();break;case`error`:this.updateStatus(`error`),this.stopPlayback();break}};let r={action:`start`,url:t.toString()};this.time=0,this.startTime=performance.now(),n.postMessage(r)}catch(e){s.error(`[MjpegstreamerCamera] failed to start playback "${this.camera.name}"`,e),this.updateStatus(`error`)}}stopPlayback(){this.worker?.terminate(),this.worker=null,this.revokeImageObjectURL(),this.updateStatus(`disconnected`),this.cameraImage.src=``}};i([n(`streamingElement`)],u.prototype,`cameraImage`,void 0),u=i([r({})],u);var d=a(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}})},[],!1,null,null,null,null).exports;export{d as default};