2 lines
3.6 KiB
JavaScript
2 lines
3.6 KiB
JavaScript
import{a as e,eO as t,di as a,cP as r,dD as s,dh as i,l as o,ds as n,du as c,dv as d,dt as l,r as u,_ as h,n as g,b as m,t as p,d$ as y,x as b}from"./card-320adb66.js";import{s as _,h as f,c as w,d as v}from"./dispatch-live-error-c649b480.js";import{g as C}from"./get-technology-for-video-rtc-778a0c05.js";import{m as P}from"./audio-cf3a75aa.js";let x=class extends e{constructor(){super(...arguments),this.controls=!1,this._message=null,this._webrtcTask=new t(this,this._getWebRTCCardElement,(()=>[1]))}async play(){return this._getPlayer()?.play()}async pause(){this._getPlayer()?.pause()}async mute(){const e=this._getPlayer();e&&(e.muted=!0)}async unmute(){const e=this._getPlayer();e&&(e.muted=!1)}isMuted(){return this._getPlayer()?.muted??!0}async seek(e){const t=this._getPlayer();t&&(t.currentTime=e)}async setControls(e){const t=this._getPlayer();t&&_(t,e??this.controls)}isPaused(){return this._getPlayer()?.paused??!0}async getScreenshotURL(){const e=this._getPlayer();return e?a(e):null}connectedCallback(){super.connectedCallback(),this.requestUpdate()}disconnectedCallback(){this._message=null,super.disconnectedCallback()}willUpdate(e){["cameraConfig","cameraEndpoints"].some((t=>e.has(t)))&&(this._message=null)}_getVideoRTC(){return this.renderRoot?.querySelector("#webrtc")??null}_getPlayer(){return this._getVideoRTC()?.video??null}async _getWebRTCCardElement(){return await customElements.whenDefined("webrtc-camera"),customElements.get("webrtc-camera")}_createWebRTC(){const e=this._webrtcTask.value;if(e&&this.hass&&this.cameraConfig){const t=new e,a={intersection:0,muted:!0,...this.cameraConfig.webrtc_card};return a.url||a.entity||!this.cameraEndpoints?.webrtcCard||(a.url=this.cameraEndpoints.webrtcCard.endpoint),t.setConfig(a),t.hass=this.hass,t}return null}render(){if(this._message)return r(this._message);return s(this._webrtcTask,(()=>{let e;try{e=this._createWebRTC()}catch(e){return this._message={type:"error",message:e instanceof y?e.message:o("error.webrtc_card_reported_error")+": "+e.message,context:e.context},void v(this)}return e&&(e.id="webrtc"),b`${e}`}),{inProgressFunc:()=>i({message:o("error.webrtc_card_waiting"),cardWideConfig:this.cardWideConfig})})}updated(){this.updateComplete.then((()=>{const e=this._getVideoRTC(),t=this._getPlayer();t&&(_(t,this.controls),t.onloadeddata=()=>{this.controls&&f(t,w),n(this,t,{player:this,capabilities:{supportsPause:!0,hasAudio:P(t)},...e&&{technology:C(e)}})},t.onplay=()=>c(this),t.onpause=()=>d(this),t.onvolumechange=()=>l(this))}))}static get styles(){return u(":host {\n width: 100%;\n height: 100%;\n display: block;\n}\n\n/* Don't drop shadow or have radius for nested webrtc card */\n#webrtc ha-card {\n border-radius: 0px;\n margin: 0px;\n box-shadow: none;\n}\n\nha-card,\ndiv.fix-safari,\n#video {\n background: unset;\n background-color: unset;\n}\n\n#webrtc #video {\n object-fit: var(--frigate-card-media-layout-fit, contain);\n object-position: var(--frigate-card-media-layout-position-x, 50%) var(--frigate-card-media-layout-position-y, 50%);\n object-view-box: inset(var(--frigate-card-media-layout-view-box-top, 0%) var(--frigate-card-media-layout-view-box-right, 0%) var(--frigate-card-media-layout-view-box-bottom, 0%) var(--frigate-card-media-layout-view-box-left, 0%));\n}")}};h([g({attribute:!1})],x.prototype,"cameraConfig",void 0),h([g({attribute:!1})],x.prototype,"cameraEndpoints",void 0),h([g({attribute:!1})],x.prototype,"cardWideConfig",void 0),h([g({attribute:!0,type:Boolean})],x.prototype,"controls",void 0),h([m()],x.prototype,"_message",void 0),x=h([p("frigate-card-live-webrtc-card")],x);export{x as FrigateCardLiveWebRTCCard};
|