import{c as e,n as t,o as n,t as r}from"./_plugin-vue2_normalizer-BwvlkTga.js";import{t as i}from"./browser-1D2tZwAR.js";import{n as a}from"./Watch-BsFMHUzZ.js";import{t as o}from"./camera-C1rIv-Ce.js";var s=class extends e(o){cameraVideo;async startPlayback(){this.updateStatus(`connecting`);try{let e=await this.getUserMedia();this.cameraVideo.srcObject=e,this.updateCameraName(await this.getDeviceLabel()??``)}catch(e){i.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){i.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 i.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 i.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())}};t([a(`streamingElement`)],s.prototype,`cameraVideo`,void 0),s=t([n({})],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};