mirror of
git://soft.sys114.com/mainsail
synced 2026-02-04 13:10:36 +09:00
2 lines
6.2 KiB
JavaScript
2 lines
6.2 KiB
JavaScript
import{_ as S}from"./WebcamNozzleCrosshair-OgFJAMdG.js";import{m as w,B as _,H as y,P as u,R as b,W as f,C as v,n as C}from"./index-Bku7SJna.js";import{m as P,n as x,r as R}from"./vuetify-Ce4WN_Dg.js";import"./overlayscrollbars-CiKU261J.js";import"./echarts-DzoUeqWp.js";var F=Object.defineProperty,L=Object.getOwnPropertyDescriptor,i=(c,t,e,a)=>{for(var s=a>1?void 0:a?L(t,e):t,n=c.length-1,o;n>=0;n--)(o=c[n])&&(s=(a?o(t,e,s):o(s))||s);return a&&s&&F(t,e,s),s};const M="content-length",m=new Uint8Array(2);m[0]=255;m[1]=216;let r=class extends w(_,y){constructor(){super(),this.frames=0,this.currentFPS=0,this.status="connecting",this.statusMessage="",this.streamState=!1,this.aspectRatio=null,this.timerFPS=null,this.timerRestart=null,this.reader=null}get url(){var t;return this.convertUrl((t=this.camSettings)==null?void 0:t.stream_url,this.printerUrl)}get webcamStyle(){var e,a,s;const t={transform:this.generateTransform((e=this.camSettings.flip_horizontal)!=null?e:!1,(a=this.camSettings.flip_vertical)!=null?a:!1,(s=this.camSettings.rotation)!=null?s:0),aspectRatio:1.7777777777777777,maxHeight:window.innerHeight-155+"px",maxWidth:"auto"};return this.aspectRatio&&(t.aspectRatio=this.aspectRatio,t.maxWidth=(window.innerHeight-155)*this.aspectRatio+"px"),t}get fpsOutput(){return this.currentFPS.toString().padStart(2,"0")}get showFpsCounter(){var t,e;return this.showFps?!((e=(t=this.camSettings.extra_data)==null?void 0:t.hideFps)!=null&&e):!1}get expanded(){var t;return this.page!=="dashboard"?!0:(t=this.$store.getters["gui/getPanelExpand"]("webcam-panel",this.viewport))!=null?t:!1}get showNozzleCrosshair(){var e,a;return((a=(e=this.camSettings.extra_data)==null?void 0:e.nozzleCrosshair)!=null?a:!1)&&this.status==="connected"}expandChanged(t){if(!t){this.stopStream();return}this.startStream()}log(t,e){if(e){window.console.log("[MJPEG streamer] ".concat(t),e);return}window.console.log("[MJPEG streamer] ".concat(t))}getLength(t){let e=-1;return t.split("\n").forEach(a=>{const s=a.split(":");s[0].toLowerCase()===M&&(e=s[1])}),e}async startStream(t=!1){var e;if(!this.streamState){this.streamState=!0,t||(this.status="connecting",this.statusMessage=this.$t("Panels.WebcamPanel.ConnectingTo",{url:this.url}).toString()),this.clearTimeouts();try{const a=new URL(this.url);a.searchParams.append("timestamp",new Date().getTime().toString());let s=await fetch(a.toString(),{mode:"cors"});if(!s.ok){this.log("".concat(s.status,": ").concat(s.statusText)),await this.stopStream();return}if(!s.body){this.log("ReadableStream not yet supported in this browser."),await this.stopStream();return}this.timerFPS=window.setInterval(()=>{this.currentFPS=this.frames,this.frames=0},1e3),this.timerRestart=window.setTimeout(()=>{this.restartStream(!0)},1e4),this.reader=(e=s.body)==null?void 0:e.getReader(),await this.readStream(),this.reader=null,s=null}catch(a){this.log(a.message),this.status="error",this.statusMessage=this.$t("Panels.WebcamPanel.ErrorWhileConnecting",{url:this.url}).toString(),this.timerRestart=window.setTimeout(()=>{this.restartStream()},5e3)}}}async readStream(){var t,e;if(this.reader)try{let a="",s=-1,n=new Uint8Array(0),o=0,p=!1,g=null,l;do if({done:g,value:l}=await this.reader.read(),!(g||!l))for(let h=0;h<l.length;h++){if(l[h]===m[0]&&l[h+1]===m[1]&&(s=this.getLength(a),n=new Uint8Array(new ArrayBuffer(s))),s<=0){a+=String.fromCharCode(l[h]);continue}if(o<s){n[o++]=l[h];continue}if(this.image&&!p){const d=URL.createObjectURL(new Blob([n],{type:"image/jpeg"}));this.image.src=d,p=!0,this.status!=="connected"&&(this.status="connected",this.statusMessage=""),this.image.onload=()=>{URL.revokeObjectURL(d),p=!1}}this.frames++,s=0,o=0,a=""}while(!g)}catch(a){this.log("readStream error: ".concat((t=a.message)!=null?t:""),a)}finally{(e=this.reader)==null||e.releaseLock()}}mounted(){document.addEventListener("visibilitychange",this.documentVisibilityChanged)}beforeDestroy(){document.removeEventListener("visibilitychange",this.documentVisibilityChanged),this.stopStream()}clearTimeouts(){this.frames=0,this.timerFPS&&(window.clearInterval(this.timerFPS),this.timerFPS=null),this.timerRestart&&(window.clearTimeout(this.timerRestart),this.timerRestart=null)}async stopStream(t=!1){var e,a;this.streamState=!1,t||(this.status="disconnected",this.statusMessage=this.$t("Panels.WebcamPanel.Disconnected").toString()),this.clearTimeouts();try{await((e=this.reader)==null?void 0:e.cancel()),(a=this.reader)==null||a.releaseLock(),this.reader=null}catch(s){this.log("Error cancelling reader:",s)}}async restartStream(t=!1){await this.stopStream(t),await this.startStream(t)}camSettingsChanged(){this.aspectRatio=null,this.restartStream()}documentVisibilityChanged(){let e=document.visibilityState==="visible";if(this.page==="dashboard"&&!this.expanded&&(e=!1),!e){this.stopStream();return}this.startStream()}onload(){this.aspectRatio!==null||!this.image||(this.aspectRatio=this.image.naturalWidth/this.image.naturalHeight)}};i([u({required:!0})],r.prototype,"camSettings",2);i([u({default:null})],r.prototype,"printerUrl",2);i([u({default:!0})],r.prototype,"showFps",2);i([u({type:String,default:null})],r.prototype,"page",2);i([b("image")],r.prototype,"image",2);i([f("expanded",{immediate:!0})],r.prototype,"expandChanged",1);i([f("camSettings",{deep:!0})],r.prototype,"camSettingsChanged",1);r=i([v],r);var T=function(){var t=this,e=t._self._c;return t._self._setupProxy,e("div",{staticClass:"d-flex justify-center",staticStyle:{position:"relative"}},[e("img",{directives:[{name:"show",rawName:"v-show",value:t.status==="connected",expression:"status === 'connected'"}],ref:"image",staticClass:"webcamImage",style:t.webcamStyle,attrs:{draggable:"false",alt:t.camSettings.name,src:"#"},on:{load:t.onload}}),t.showFpsCounter&&t.status==="connected"?e("span",{staticClass:"webcamFpsOutput"},[t._v(" "+t._s(t.$t("Panels.WebcamPanel.FPS"))+": "+t._s(t.fpsOutput)+" ")]):t._e(),t.showNozzleCrosshair?e(S,{attrs:{webcam:t.camSettings}}):t._e(),t.status!=="connected"?e(P,[e(x,{staticClass:"_webcam_mjpegstreamer_output text-center d-flex flex-column justify-center align-center"},[t.status==="connecting"?e(R,{staticClass:"mb-3",attrs:{indeterminate:"",color:"primary"}}):t._e(),e("span",{staticClass:"mt-3"},[t._v(t._s(t.statusMessage))])],1)],1):t._e()],1)},z=[],U=C(r,T,z,!1,null,"5cf3464a");const N=U.exports;export{N as default};
|