var d=Object.defineProperty;var v=(c,a,e)=>a in c?d(c,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[a]=e;var o=(c,a,e)=>v(c,typeof a!="symbol"?a+"":a,e);import{m as u,C as p,f as n,R as f,j as C,k as h}from"./index-CBxrqwze.js";var g=Object.defineProperty,D=Object.getOwnPropertyDescriptor,l=(c,a,e,t)=>{for(var r=t>1?void 0:t?D(a,e):a,s=c.length-1,i;s>=0;s--)(i=c[s])&&(r=(t?i(a,e,r):i(r))||r);return t&&r&&g(a,e,r),r};let m=class extends u(p){constructor(){super(...arguments);o(this,"cameraVideo")}async startPlayback(){this.updateStatus("connecting");try{const e=await this.getUserMedia();this.cameraVideo.srcObject=e,this.updateCameraName(await this.getDeviceLabel()??"")}catch(e){n.error(`[DeviceCamera] failed to start playback "${this.getSelectedDeviceCamera()}"`,e),this.updateStatus("error")}}stopPlayback(){this.updateStatus("disconnected");try{const e=this.cameraVideo.srcObject;if(e)for(const t of e.getTracks())t.stop(),e.removeTrack(t)}catch(e){n.error("[DeviceCamera] failed to stop and remove all tracks",e)}this.cameraVideo.srcObject=null}async getUserMedia(){const e=this.getSelectedDeviceCamera();try{const t=["environment","user"].includes(e)?"facingMode":"deviceId";return await navigator.mediaDevices.getUserMedia({video:{[t]:e}})}catch(t){return n.error(`[DeviceCamera] failed to select device "${e}"`,t),this.setSelectedDeviceCamera(null),await navigator.mediaDevices.getUserMedia({video:{facingMode:"environment"}})}}async enumerateDevices(){try{return(await navigator.mediaDevices.enumerateDevices()).filter(t=>t.kind==="videoinput")}catch(e){return n.error("[DeviceCamera] failed to enumerate devices",e),[]}}async getDeviceLabel(){var t;if(this.cameraNameMenuItems.length===0){const r=await this.enumerateDevices(),s=[{icon:"$camera",text:this.$tc("app.general.label.environment_facing"),value:"environment"},{icon:"$camera",text:this.$tc("app.general.label.user_facing"),value:"user"},...r.map(i=>({icon:"$camera",text:i.label,value:i.deviceId}))];this.updateCameraNameMenuItems(s)}const e=this.getSelectedDeviceCamera();return(t=this.cameraNameMenuItems.find(r=>r.value===e))==null?void 0:t.text}getSelectedDeviceCamera(){return localStorage.getItem("deviceCamera.selectedCamera")??"environment"}setSelectedDeviceCamera(e){e?localStorage.setItem("deviceCamera.selectedCamera",e):localStorage.removeItem("deviceCamera.selectedCamera")}menuItemClick(e){this.getSelectedDeviceCamera()!==e.value&&(this.setSelectedDeviceCamera(e.value),this.stopPlayback(),this.updateCameraName(e.text),this.startPlayback())}};l([f("streamingElement")],m.prototype,"cameraVideo",2);m=l([C({})],m);var _=function(){var a=this,e=a._self._c;return a._self._setupProxy,e("video",{ref:"streamingElement",style:a.cameraStyle,attrs:{autoplay:"",muted:""},domProps:{muted:!0},on:{play:function(t){return a.updateStatus("connected")},error:function(t){return a.updateStatus("error")}}})},y=[],S=h(m,_,y,!1,null,null);const I=S.exports;export{I as default};
