mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-11-08 18:39:33 +00:00
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2 lines
10 KiB
JavaScript
2 lines
10 KiB
JavaScript
"use strict";(self.webpackChunkhome_assistant_frontend=self.webpackChunkhome_assistant_frontend||[]).push([["131"],{51257:function(e,t,r){r(79827),r(35748),r(5934),r(67579),r(18223),r(95013),r(45460),r(18332),r(13484),r(81071),r(92714),r(55885);var s=r(69868),i=r(84922),o=r(11991),a=r(7577),l=r(26946),n=r(44017),h=r(54337),d=r(63375);r(94124);let _,p,c,u,y=e=>e;class v extends i.WF{connectedCallback(){super.connectedCallback(),v.streamCount+=1,this.hasUpdated&&(this._resetError(),this._startHls()),document.addEventListener("visibilitychange",this._handleVisibilityChange)}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener("visibilitychange",this._handleVisibilityChange),v.streamCount-=1,this._cleanUp()}render(){return(0,i.qy)(_||(_=y` ${0} ${0} `),this._error?(0,i.qy)(p||(p=y`<ha-alert alert-type="error" class="${0}"> ${0} </ha-alert>`),this._errorIsFatal?"fatal":"retry",this._error):"",this._errorIsFatal?"":(0,i.qy)(c||(c=y`<video .poster="${0}" ?autoplay="${0}" .muted="${0}" ?playsinline="${0}" ?controls="${0}" @loadeddata="${0}" style="${0}"></video>`),this.posterUrl,this.autoPlay,this.muted,this.playsInline,this.controls,this._loadedData,(0,a.W)({height:null==this.aspectRatio?"100%":"auto",aspectRatio:this.aspectRatio,objectFit:this.fitMode})))}updated(e){super.updated(e);const t=e.has("entityid"),r=e.has("url");t?this._getStreamUrlFromEntityId():r&&this.url&&(this._cleanUp(),this._resetError(),this._url=this.url,this._startHls())}async _getStreamUrlFromEntityId(){if(this._cleanUp(),this._resetError(),(0,l.x)(this.hass,"stream")){if(this.entityid)try{const{url:e}=await(0,d.wv)(this.hass,this.entityid);this._url=this.hass.hassUrl(e),this._cleanUp(),this._resetError(),this._startHls()}catch(e){console.error(e),(0,n.r)(this,"streams",{hasAudio:!1,hasVideo:!1})}}else this._setFatalError("Streaming component is not loaded.")}async _startHls(){var e;const t=fetch(this._url),s=(await r.e("705").then(r.bind(r,62664))).default;if(!this.isConnected)return;let i=s.isSupported();if(i||(i=""!==this._videoEl.canPlayType("application/vnd.apple.mpegurl")),!i)return void this._setFatalError(this.hass.localize("ui.components.media-browser.video_not_supported"));const o=this.allowExoPlayer&&(null===(e=this.hass.auth.external)||void 0===e?void 0:e.config.hasExoPlayer),a=await(await t).text();if(!this.isConnected)return;const l=/#EXT-X-STREAM-INF:.*?(?:CODECS=".*?([^.]*)?\..*?,([^.]*)?\..*?".*?)?(?:\n|\r\n)(.+)/g,n=l.exec(a),h=l.exec(a);let d;d=null!==n&&null===h?new URL(n[3],this._url).href:this._url;const _=n?`${n[1]},${n[2]}`:void 0;this._reportStreams(_),o&&(null!=_&&_.includes("hevc")||null!=_&&_.includes("hev1"))?this._renderHLSExoPlayer(d):s.isSupported()?this._renderHLSPolyfill(this._videoEl,s,d):this._renderHLSNative(this._videoEl,d)}async _renderHLSExoPlayer(e){this._exoPlayer=!0,window.addEventListener("resize",this._resizeExoPlayer),this.updateComplete.then(()=>(0,h.E)()).then(this._resizeExoPlayer),this._videoEl.style.visibility="hidden",await this.hass.auth.external.fireMessage({type:"exoplayer/play_hls",payload:{url:e,muted:this.muted}})}_isLLHLSSupported(){if(v.streamCount<=2)return!0;if(!("performance"in window)||0===performance.getEntriesByType("resource").length)return!1;const e=performance.getEntriesByType("resource")[0];return"nextHopProtocol"in e&&"h2"===e.nextHopProtocol}async _renderHLSPolyfill(e,t,r){const s=new t({backBufferLength:60,fragLoadingTimeOut:3e4,manifestLoadingTimeOut:3e4,levelLoadingTimeOut:3e4,maxLiveSyncPlaybackRate:2,lowLatencyMode:this._isLLHLSSupported()});this._hlsPolyfillInstance=s,s.attachMedia(e),s.on(t.Events.MEDIA_ATTACHED,()=>{this._resetError(),s.loadSource(r)}),s.on(t.Events.FRAG_LOADED,(e,t)=>{this._resetError()}),s.on(t.Events.ERROR,(e,r)=>{if(r.fatal)if(r.type===t.ErrorTypes.NETWORK_ERROR){switch(r.details){case t.ErrorDetails.MANIFEST_LOAD_ERROR:{let e="Error starting stream, see logs for details";void 0!==r.response&&void 0!==r.response.code&&(r.response.code>=500?e+=" (Server failure)":r.response.code>=400?e+=" (Stream never started)":e+=" ("+r.response.code+")"),this._setRetryableError(e);break}case t.ErrorDetails.MANIFEST_LOAD_TIMEOUT:this._setRetryableError("Timeout while starting stream");break;default:this._setRetryableError("Stream network error")}s.startLoad()}else r.type===t.ErrorTypes.MEDIA_ERROR?(this._setRetryableError("Error with media stream contents"),s.recoverMediaError()):this._setFatalError("Error playing stream")})}async _renderHLSNative(e,t){e.src=t,e.addEventListener("loadedmetadata",()=>{e.play()})}_cleanUp(){this._hlsPolyfillInstance&&(this._hlsPolyfillInstance.destroy(),this._hlsPolyfillInstance=void 0),this._exoPlayer&&(window.removeEventListener("resize",this._resizeExoPlayer),this.hass.auth.external.fireMessage({type:"exoplayer/stop"}),this._exoPlayer=!1),this._videoEl&&(this._videoEl.removeAttribute("src"),this._videoEl.load())}_resetError(){this._error=void 0,this._errorIsFatal=!1}_setFatalError(e){this._error=e,this._errorIsFatal=!0,(0,n.r)(this,"streams",{hasAudio:!1,hasVideo:!1})}_setRetryableError(e){this._error=e,this._errorIsFatal=!1,(0,n.r)(this,"streams",{hasAudio:!1,hasVideo:!1})}_reportStreams(e){var t;const r=null==e?void 0:e.split(",");(0,n.r)(this,"streams",{hasAudio:null!==(t=null==r?void 0:r.includes("mp4a"))&&void 0!==t&&t,hasVideo:null!=r&&r.includes("mp4a")?(null==r?void 0:r.length)>1:Boolean(null==r?void 0:r.length)})}_loadedData(){(0,n.r)(this,"load")}constructor(...e){super(...e),this.controls=!1,this.muted=!1,this.autoPlay=!1,this.playsInline=!1,this.allowExoPlayer=!1,this._errorIsFatal=!1,this._exoPlayer=!1,this._handleVisibilityChange=()=>{document.hidden?this._cleanUp():(this._resetError(),this._startHls())},this._resizeExoPlayer=()=>{if(!this._videoEl)return;const e=this._videoEl.getBoundingClientRect();this.hass.auth.external.fireMessage({type:"exoplayer/resize",payload:{left:e.left,top:e.top,right:e.right,bottom:e.bottom}})}}}v.streamCount=0,v.styles=(0,i.AH)(u||(u=y`:host,video{display:block}video{width:100%;max-height:var(--video-max-height,calc(100vh - 97px))}.fatal{display:block;padding:100px 16px}.retry{display:block}`)),(0,s.__decorate)([(0,o.MZ)({attribute:!1})],v.prototype,"hass",void 0),(0,s.__decorate)([(0,o.MZ)()],v.prototype,"entityid",void 0),(0,s.__decorate)([(0,o.MZ)()],v.prototype,"url",void 0),(0,s.__decorate)([(0,o.MZ)({attribute:"poster-url"})],v.prototype,"posterUrl",void 0),(0,s.__decorate)([(0,o.MZ)({attribute:!1})],v.prototype,"aspectRatio",void 0),(0,s.__decorate)([(0,o.MZ)({attribute:!1})],v.prototype,"fitMode",void 0),(0,s.__decorate)([(0,o.MZ)({type:Boolean,attribute:"controls"})],v.prototype,"controls",void 0),(0,s.__decorate)([(0,o.MZ)({type:Boolean,attribute:"muted"})],v.prototype,"muted",void 0),(0,s.__decorate)([(0,o.MZ)({type:Boolean,attribute:"autoplay"})],v.prototype,"autoPlay",void 0),(0,s.__decorate)([(0,o.MZ)({type:Boolean,attribute:"playsinline"})],v.prototype,"playsInline",void 0),(0,s.__decorate)([(0,o.MZ)({type:Boolean,attribute:"allow-exoplayer"})],v.prototype,"allowExoPlayer",void 0),(0,s.__decorate)([(0,o.P)("video")],v.prototype,"_videoEl",void 0),(0,s.__decorate)([(0,o.wk)()],v.prototype,"_error",void 0),(0,s.__decorate)([(0,o.wk)()],v.prototype,"_errorIsFatal",void 0),(0,s.__decorate)([(0,o.wk)()],v.prototype,"_url",void 0),v=(0,s.__decorate)([(0,o.EM)("ha-hls-player")],v)},38542:function(e,t,r){r.a(e,async function(e,s){try{r.r(t),r.d(t,{FlowPreviewGeneric:function(){return y}});r(35748),r(12977),r(5934),r(95013);var i=r(69868),o=r(84922),a=r(11991),l=r(38534),n=r(99264),h=r(51849),d=r(44017),_=(r(94124),e([n]));n=(_.then?(await _)():_)[0];let p,c,u=e=>e;class y extends o.WF{disconnectedCallback(){super.disconnectedCallback(),this._unsub&&(this._unsub.then(e=>e()),this._unsub=void 0)}willUpdate(e){e.has("stepData")&&this._debouncedSubscribePreview()}render(){return this._error?(0,o.qy)(p||(p=u`<ha-alert alert-type="error">${0}</ha-alert>`),this._error):(0,o.qy)(c||(c=u`<entity-preview-row .hass="${0}" .stateObj="${0}"></entity-preview-row>`),this.hass,this._preview)}async _subscribePreview(){if(this._unsub&&((await this._unsub)(),this._unsub=void 0),"config_flow"===this.flowType||"options_flow"===this.flowType||"config_subentries_flow"===this.flowType){this._error=void 0;try{this._unsub=(0,l.Q)(this.hass,this.domain,this.flowId,this.flowType,this.stepData,this._setPreview),await this._unsub,(0,d.r)(this,"set-flow-errors",{errors:{}})}catch(e){"string"==typeof e.message?this._error=e.message:(this._error=void 0,(0,d.r)(this,"set-flow-errors",e.message)),this._unsub=void 0,this._preview=void 0}}}constructor(...e){super(...e),this._setPreview=e=>{if(e.error)return this._error=e.error,void(this._preview=void 0);const t=(new Date).toISOString();this._preview=Object.assign({entity_id:`${this.stepId}.___flow_preview___`,last_changed:t,last_updated:t,context:{id:"",parent_id:null,user_id:null}},e)},this._debouncedSubscribePreview=(0,h.s)(()=>{this._subscribePreview()},250)}}(0,i.__decorate)([(0,a.MZ)({attribute:!1})],y.prototype,"hass",void 0),(0,i.__decorate)([(0,a.MZ)({attribute:!1})],y.prototype,"flowType",void 0),(0,i.__decorate)([(0,a.MZ)()],y.prototype,"domain",void 0),(0,i.__decorate)([(0,a.MZ)({attribute:!1})],y.prototype,"stepId",void 0),(0,i.__decorate)([(0,a.MZ)({attribute:!1})],y.prototype,"flowId",void 0),(0,i.__decorate)([(0,a.MZ)({attribute:!1})],y.prototype,"stepData",void 0),(0,i.__decorate)([(0,a.wk)()],y.prototype,"_preview",void 0),(0,i.__decorate)([(0,a.wk)()],y.prototype,"_error",void 0),y=(0,i.__decorate)([(0,a.EM)("flow-preview-generic")],y),s()}catch(p){s(p)}})},91566:function(e,t,r){r.a(e,async function(e,s){try{r.r(t);var i=r(69868),o=r(84922),a=r(11991),l=r(38542),n=(r(51257),r(96635)),h=e([n,l]);[n,l]=h.then?(await h)():h;let d,_,p,c,u=e=>e;class y extends l.FlowPreviewGeneric{render(){if(!this._preview)return o.s6;if(this._error)return(0,o.qy)(d||(d=u`<ha-alert alert-type="error">${0}</ha-alert>`),this._error);const e=this._preview.attributes.still_url,t=this._preview.attributes.stream_url;return(0,o.qy)(_||(_=u` ${0} ${0}`),e?(0,o.qy)(p||(p=u`<p>Still image:</p> <p> <img src="${0}" alt="Still preview"> </p>`),e):"",t?(0,o.qy)(c||(c=u`<p>Stream:</p> <ha-spinner class="render-spinner" id="hls-load-spinner" size="large"></ha-spinner> <ha-hls-player autoplay playsinline .hass="${0}" .url="${0}" @load="${0}"></ha-hls-player>`),this.hass,t,this._videoLoaded):"")}_videoLoaded(){var e;null===(e=this.shadowRoot.getElementById("hls-load-spinner"))||void 0===e||e.remove()}}y=(0,i.__decorate)([(0,a.EM)("flow-preview-generic_camera")],y),s()}catch(d){s(d)}})}}]);
|
|
//# sourceMappingURL=131.566df1af9c07775a.js.map
|