import{a as e,l as t,n,t as r,u as i}from"./_plugin-vue2_normalizer-Vm4EDAeQ.js";import{t as a}from"./browser-1D2tZwAR.js";import{t as o}from"./camera-DKiOc18c.js";var s=class extends i(o){cameraVideo;async startPlayback(){this.updateStatus(`connecting`);try{let e=await this.getUserMedia();this.cameraVideo.srcObject=e,this.updateCameraName(await this.getDeviceLabel()??``)}catch(e){a.error(`[DeviceCamera] failed to start playback "${this.getSelectedDeviceCamera()}"`,e),this.updateStatus(`error`)}}stopPlayback(){this.updateStatus(`disconnected`);try{let e=this.cameraVideo.srcObject;if(e instanceof MediaStream)for(let t of e.getTracks())t.stop(),e.removeTrack(t)}catch(e){a.error(`[DeviceCamera] failed to stop and remove all tracks`,e)}this.cameraVideo.srcObject=null}async getUserMedia(){let e=this.getSelectedDeviceCamera();try{let t=[`environment`,`user`].includes(e)?`facingMode`:`deviceId`;return await navigator.mediaDevices.getUserMedia({video:{[t]:e}})}catch(t){return a.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(e=>e.kind===`videoinput`)}catch(e){return a.error(`[DeviceCamera] failed to enumerate devices`,e),[]}}async getDeviceLabel(){if(this.cameraNameMenuItems.length===0){let e=await this.enumerateDevices(),t=[{icon:`$camera`,text:this.$tc(`app.general.label.environment_facing`),value:`environment`},{icon:`$camera`,text:this.$tc(`app.general.label.user_facing`),value:`user`},...e.map(e=>({icon:`$camera`,text:e.label,value:e.deviceId}))];this.updateCameraNameMenuItems(t)}let e=this.getSelectedDeviceCamera();return this.cameraNameMenuItems.find(t=>t.value===e)?.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())}};n([e(`streamingElement`)],s.prototype,`cameraVideo`,void 0),s=n([t({})],s);var c=r(s,function(){var e=this,t=e._self._c;return e._self._setupProxy,t(`video`,{ref:`streamingElement`,style:e.cameraStyle,attrs:{autoplay:``,disablePictureInPicture:``,playsinline:``,muted:``},domProps:{muted:!0},on:{play:function(t){return e.updateStatus(`connected`)},error:function(t){return e.updateStatus(`error`)}}})},[],!1,null,null,null,null).exports;export{c as default};