mirror of
git://soft.sys114.com/mainsail
synced 2026-02-04 13:10:36 +09:00
2 lines
4.9 KiB
JavaScript
2 lines
4.9 KiB
JavaScript
import{m as d,B as p,H as m,P as u,R as g,W as l,C as f,n as _}from"./index-Bku7SJna.js";import{m as w,n as v,r as b}from"./vuetify-Ce4WN_Dg.js";import"./overlayscrollbars-CiKU261J.js";import"./echarts-DzoUeqWp.js";var S=Object.defineProperty,y=Object.getOwnPropertyDescriptor,o=(c,t,e,i)=>{for(var s=i>1?void 0:i?y(t,e):t,n=c.length-1,r;n>=0;n--)(r=c[n])&&(s=(i?r(t,e,s):r(s))||s);return i&&s&&S(t,e,s),s};let a=class extends d(p,m){constructor(){super(...arguments),this.pc=null,this.ws=null,this.restartPause=2e3,this.restartTimeout=null,this.status="connecting"}mounted(){this.start()}beforeDestroy(){this.terminate(),this.restartTimeout&&clearTimeout(this.restartTimeout)}get webcamStyle(){var t,e,i;return{transform:this.generateTransform((t=this.camSettings.flip_horizontal)!=null?t:!1,(e=this.camSettings.flip_vertical)!=null?e:!1,(i=this.camSettings.rotation)!=null?i:0)}}get url(){let t="",e=new URL(location.href);try{t=new URL(this.camSettings.stream_url).search.toString(),e=new URL("api/ws"+t,this.camSettings.stream_url)}catch{this.log("invalid url",this.camSettings.stream_url)}const i=["video"];return this.enableAudio&&i.push("audio"),e.searchParams.set("media",i.join("+")),e.protocol=this.$store.state.socket.protocol+":",e.searchParams.has("src")||this.log("no src set in url"),this.convertUrl(e.toString(),this.printerUrl)}get enableAudio(){var t,e;return(e=(t=this.camSettings.extra_data)==null?void 0:t.enableAudio)!=null?e:!1}changedUrl(){this.terminate(),this.start()}changedEnableAudio(){this.terminate(),this.start()}get expanded(){var t;return(t=this.$store.getters["gui/getPanelExpand"]("webcam-panel",this.viewport))!=null?t:!1}expandChanged(t){if(!t){this.terminate();return}this.start()}log(t,e){if(e){window.console.log("[WebRTC go2rtc] ".concat(t),e);return}window.console.log("[WebRTC go2rtc] ".concat(t))}start(){if(!this.video){this.scheduleRestart();return}this.log("connecting to "+this.url),this.status="connecting",this.pc=new RTCPeerConnection({iceServers:[{urls:"stun:stun.l.google.com:19302"}]});let t=[];["video","audio"].forEach(i=>{var n;const s=(n=this.pc)==null?void 0:n.addTransceiver(i,{direction:"recvonly"}).receiver.track;s&&t.push(s)}),this.video.srcObject=new MediaStream(t),this.ws=new WebSocket(this.url),this.ws.addEventListener("open",()=>this.onWebSocketOpen()),this.ws.addEventListener("message",i=>this.onWebSocketMessage(i)),this.ws.addEventListener("close",i=>this.onWebSocketClose(i))}onWebSocketOpen(){var t,e,i;this.log("open"),this.restartTimeout!==null&&(clearTimeout(this.restartTimeout),this.restartTimeout=null),(t=this.pc)==null||t.addEventListener("icecandidate",s=>{var r;if(!s.candidate)return;const n={type:"webrtc/candidate",value:s.candidate.candidate};(r=this.ws)==null||r.send(JSON.stringify(n))}),(e=this.pc)==null||e.addEventListener("connectionstatechange",()=>{var s,n;this.status=((n=(s=this.pc)==null?void 0:s.connectionState)!=null?n:"").toString(),this.log("connection state changed",this.status),["failed","disconnected"].includes(this.status)&&this.scheduleRestart()}),(i=this.pc)==null||i.createOffer().then(s=>{var n;return(n=this.pc)==null?void 0:n.setLocalDescription(s)}).then(()=>{var n,r,h;const s={type:"webrtc/offer",value:(r=(n=this.pc)==null?void 0:n.localDescription)==null?void 0:r.sdp};(h=this.ws)==null||h.send(JSON.stringify(s))})}onWebSocketMessage(t){var i,s;const e=JSON.parse(t.data);e.type==="webrtc/candidate"?(i=this.pc)==null||i.addIceCandidate({candidate:e.value,sdpMid:"0"}):e.type==="webrtc/answer"&&((s=this.pc)==null||s.setRemoteDescription({type:"answer",sdp:e.value}))}onWebSocketClose(t){this.log("close"),this.status="disconnected",t.wasClean||this.scheduleRestart()}terminate(){this.log("terminating"),this.pc!==null&&(this.pc.close(),this.pc=null),this.ws!==null&&(this.ws.close(),this.ws=null)}scheduleRestart(){this.restartTimeout===null&&(this.terminate(),this.restartTimeout=window.setTimeout(()=>{this.restartTimeout=null,this.start()},this.restartPause))}};o([u({required:!0})],a.prototype,"camSettings",2);o([u({default:null})],a.prototype,"printerUrl",2);o([g()],a.prototype,"video",2);o([l("url")],a.prototype,"changedUrl",1);o([l("enableAudio")],a.prototype,"changedEnableAudio",1);o([l("expanded",{immediate:!0})],a.prototype,"expandChanged",1);a=o([f],a);var C=function(){var t=this,e=t._self._c;return t._self._setupProxy,e("div",[e("video",{directives:[{name:"show",rawName:"v-show",value:t.status==="connected",expression:"status === 'connected'"}],ref:"video",staticClass:"webcamImage",style:t.webcamStyle,attrs:{autoplay:"",playsinline:"",muted:""},domProps:{muted:!0}}),t.status!=="connected"?e(w,[e(v,{staticClass:"_webcam_webrtc_output text-center d-flex flex-column justify-center align-center"},[t.status==="connecting"?e(b,{staticClass:"mb-3",attrs:{indeterminate:"",color:"primary"}}):t._e(),e("span",{staticClass:"mt-3"},[t._v(t._s(t.status))])],1)],1):t._e()],1)},T=[],x=_(a,C,T,!1,null,"673627af");const L=x.exports;export{L as default};
|