import{l as e,o as t}from"./vue.runtime.esm-uXCn7sOw.js";import{c as n,n as r,o as i,t as a}from"./_plugin-vue2_normalizer-BwvlkTga.js";import{t as o}from"./browser-1D2tZwAR.js";import{n as s}from"./Watch-BsFMHUzZ.js";import{t as c}from"./camera-C1rIv-Ce.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 n(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){o.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=``}};r([s(`streamingElement`)],u.prototype,`cameraImage`,void 0),u=r([i({})],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};