iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
2 lines • 11.5 kB
JavaScript
"use strict";(self.webpackChunkhome_assistant_frontend=self.webpackChunkhome_assistant_frontend||[]).push([["95273"],{96e3:function(e,t,r){var i=r(61701),s=r(72621),a=(r(19083),r(71695),r(40251),r(19134),r(61006),r(47021),r(72700),r(8038),r(71513),r(75656),r(50100),r(18084),r(57243)),o=r(50778),l=r(36522),n=r(76320),d=(r(99426),r(47844)),h=r(72344);let u,c,y,v,_=e=>e;(0,i.Z)([(0,o.Mo)("ha-hls-player")],(function(e,t){class i extends t{constructor(...t){super(...t),e(this)}}return{F:i,d:[{kind:"field",decorators:[(0,o.Cb)({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[(0,o.Cb)()],key:"entityid",value:void 0},{kind:"field",decorators:[(0,o.Cb)()],key:"url",value:void 0},{kind:"field",decorators:[(0,o.Cb)({attribute:"poster-url"})],key:"posterUrl",value:void 0},{kind:"field",decorators:[(0,o.Cb)({type:Boolean,attribute:"controls"})],key:"controls",value(){return!1}},{kind:"field",decorators:[(0,o.Cb)({type:Boolean,attribute:"muted"})],key:"muted",value(){return!1}},{kind:"field",decorators:[(0,o.Cb)({type:Boolean,attribute:"autoplay"})],key:"autoPlay",value(){return!1}},{kind:"field",decorators:[(0,o.Cb)({type:Boolean,attribute:"playsinline"})],key:"playsInline",value(){return!1}},{kind:"field",decorators:[(0,o.Cb)({type:Boolean,attribute:"allow-exoplayer"})],key:"allowExoPlayer",value(){return!1}},{kind:"field",decorators:[(0,o.IO)("video")],key:"_videoEl",value:void 0},{kind:"field",decorators:[(0,o.SB)()],key:"_error",value:void 0},{kind:"field",decorators:[(0,o.SB)()],key:"_errorIsFatal",value(){return!1}},{kind:"field",decorators:[(0,o.SB)()],key:"_url",value:void 0},{kind:"field",key:"_hlsPolyfillInstance",value:void 0},{kind:"field",key:"_exoPlayer",value(){return!1}},{kind:"field",static:!0,key:"streamCount",value(){return 0}},{kind:"method",key:"connectedCallback",value:function(){(0,s.Z)(i,"connectedCallback",this,3)([]),i.streamCount+=1,this.hasUpdated&&(this._resetError(),this._startHls())}},{kind:"method",key:"disconnectedCallback",value:function(){(0,s.Z)(i,"disconnectedCallback",this,3)([]),i.streamCount-=1,this._cleanUp()}},{kind:"method",key:"render",value:function(){return(0,a.dy)(u||(u=_` ${0} ${0} `),this._error?(0,a.dy)(c||(c=_`<ha-alert alert-type="error" class="${0}"> ${0} </ha-alert>`),this._errorIsFatal?"fatal":"retry",this._error):"",this._errorIsFatal?"":(0,a.dy)(y||(y=_`<video .poster="${0}" ?autoplay="${0}" .muted="${0}" ?playsinline="${0}" ?controls="${0}" ="${0}"></video>`),this.posterUrl,this.autoPlay,this.muted,this.playsInline,this.controls,this._loadedData))}},{kind:"method",key:"updated",value:function(e){(0,s.Z)(i,"updated",this,3)([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())}},{kind:"method",key:"_getStreamUrlFromEntityId",value:async function(){if(this._cleanUp(),this._resetError(),(0,h.p)(this.hass,"stream")){if(this.entityid)try{const{url:e}=await(0,d.Lr)(this.hass,this.entityid);this._url=this.hass.hassUrl(e),this._cleanUp(),this._resetError(),this._startHls()}catch(e){console.error(e),(0,l.B)(this,"streams",{hasAudio:!1,hasVideo:!1})}}else this._setFatalError("Streaming component is not loaded.")}},{kind:"method",key:"_startHls",value:async function(){var e;const t=fetch(this._url),i=(await Promise.all([r.e("2142"),r.e("66095")]).then(r.bind(r,17231))).default;if(!this.isConnected)return;let s=i.isSupported();if(s||(s=""!==this._videoEl.canPlayType("application/vnd.apple.mpegurl")),!s)return void this._setFatalError(this.hass.localize("ui.components.media-browser.video_not_supported"));const a=this.allowExoPlayer&&(null===(e=this.hass.auth.external)||void 0===e?void 0:e.config.hasExoPlayer),o=await(await t).text();if(!this.isConnected)return;const l=/#EXT-X-STREAM-INF:.*?(?:CODECS=".*?([^.]*)?\..*?,([^.]*)?\..*?".*?)?(?:\n|\r\n)(.+)/g,n=l.exec(o),d=l.exec(o);let h;h=null!==n&&null===d?new URL(n[3],this._url).href:this._url;const u=n?`${n[1]},${n[2]}`:void 0;this._reportStreams(u),a&&(null!=u&&u.includes("hevc")||null!=u&&u.includes("hev1"))?this._renderHLSExoPlayer(h):i.isSupported()?this._renderHLSPolyfill(this._videoEl,i,h):this._renderHLSNative(this._videoEl,h)}},{kind:"method",key:"_renderHLSExoPlayer",value:async function(e){this._exoPlayer=!0,window.addEventListener("resize",this._resizeExoPlayer),this.updateComplete.then((()=>(0,n.y)())).then(this._resizeExoPlayer),this._videoEl.style.visibility="hidden",await this.hass.auth.external.fireMessage({type:"exoplayer/play_hls",payload:{url:e,muted:this.muted}})}},{kind:"field",key:"_resizeExoPlayer",value(){return()=>{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}})}}},{kind:"method",key:"_isLLHLSSupported",value:function(){if(i.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}},{kind:"method",key:"_renderHLSPolyfill",value:async function(e,t,r){const i=new t({backBufferLength:60,fragLoadingTimeOut:3e4,manifestLoadingTimeOut:3e4,levelLoadingTimeOut:3e4,maxLiveSyncPlaybackRate:2,lowLatencyMode:this._isLLHLSSupported()});this._hlsPolyfillInstance=i,i.attachMedia(e),i.on(t.Events.MEDIA_ATTACHED,(()=>{this._resetError(),i.loadSource(r)})),i.on(t.Events.FRAG_LOADED,((e,t)=>{this._resetError()})),i.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")}i.startLoad()}else r.type===t.ErrorTypes.MEDIA_ERROR?(this._setRetryableError("Error with media stream contents"),i.recoverMediaError()):this._setFatalError("Error playing stream")}))}},{kind:"method",key:"_renderHLSNative",value:async function(e,t){e.src=t,e.addEventListener("loadedmetadata",(()=>{e.play()}))}},{kind:"method",key:"_cleanUp",value:function(){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())}},{kind:"method",key:"_resetError",value:function(){this._error=void 0,this._errorIsFatal=!1}},{kind:"method",key:"_setFatalError",value:function(e){this._error=e,this._errorIsFatal=!0,(0,l.B)(this,"streams",{hasAudio:!1,hasVideo:!1})}},{kind:"method",key:"_setRetryableError",value:function(e){this._error=e,this._errorIsFatal=!1,(0,l.B)(this,"streams",{hasAudio:!1,hasVideo:!1})}},{kind:"method",key:"_reportStreams",value:function(e){var t;const r=null==e?void 0:e.split(",");(0,l.B)(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)})}},{kind:"method",key:"_loadedData",value:function(){(0,l.B)(this,"load")}},{kind:"field",static:!0,key:"styles",value(){return(0,a.iv)(v||(v=_`: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}`))}}]}}),a.oi)},79381:function(e,t,r){r.a(e,(async function(e,i){try{r.r(t),r.d(t,{FlowPreviewGeneric:()=>p});var s=r(61701),a=r(72621),o=(r(71695),r(19423),r(40251),r(47021),r(57243)),l=r(50778),n=r(55290),d=r(28820),h=r(22381),u=r(36522),c=(r(99426),e([d]));d=(c.then?(await c)():c)[0];let y,v,_=e=>e,p=(0,s.Z)([(0,l.Mo)("flow-preview-generic")],(function(e,t){class r extends t{constructor(...t){super(...t),e(this)}}return{F:r,d:[{kind:"field",decorators:[(0,l.Cb)({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[(0,l.Cb)({attribute:!1})],key:"flowType",value:void 0},{kind:"field",key:"handler",value:void 0},{kind:"field",decorators:[(0,l.Cb)()],key:"domain",value:void 0},{kind:"field",decorators:[(0,l.Cb)({attribute:!1})],key:"stepId",value:void 0},{kind:"field",decorators:[(0,l.Cb)({attribute:!1})],key:"flowId",value:void 0},{kind:"field",decorators:[(0,l.Cb)({attribute:!1})],key:"stepData",value:void 0},{kind:"field",decorators:[(0,l.SB)()],key:"_preview",value:void 0},{kind:"field",decorators:[(0,l.SB)()],key:"_error",value:void 0},{kind:"field",key:"_unsub",value:void 0},{kind:"method",key:"disconnectedCallback",value:function(){(0,a.Z)(r,"disconnectedCallback",this,3)([]),this._unsub&&(this._unsub.then((e=>e())),this._unsub=void 0)}},{kind:"method",key:"willUpdate",value:function(e){e.has("stepData")&&this._debouncedSubscribePreview()}},{kind:"method",key:"render",value:function(){return this._error?(0,o.dy)(y||(y=_`<ha-alert alert-type="error">${0}</ha-alert>`),this._error):(0,o.dy)(v||(v=_`<entity-preview-row .hass="${0}" .stateObj="${0}"></entity-preview-row>`),this.hass,this._preview)}},{kind:"field",key:"_setPreview",value(){return e=>{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)}}},{kind:"field",key:"_debouncedSubscribePreview",value(){return(0,h.D)((()=>{this._subscribePreview()}),250)}},{kind:"method",key:"_subscribePreview",value:async function(){if(this._unsub&&((await this._unsub)(),this._unsub=void 0),"config_flow"===this.flowType||"options_flow"===this.flowType)try{this._unsub=(0,n.H)(this.hass,this.domain,this.flowId,this.flowType,this.stepData,this._setPreview),(0,u.B)(this,"set-flow-errors",{errors:{}})}catch(e){"string"==typeof e.message?this._error=e.message:(this._error=void 0,(0,u.B)(this,"set-flow-errors",e.message)),this._unsub=void 0,this._preview=void 0}}}]}}),o.oi);i()}catch(y){i(y)}}))},97556:function(e,t,r){r.a(e,(async function(e,i){try{r.r(t);var s=r(61701),a=(r(71695),r(47021),r(57243)),o=r(50778),l=r(79381),n=(r(96e3),r(17170)),d=e([n,l]);[n,l]=d.then?(await d)():d;let h,u,c,y,v=e=>e;(0,s.Z)([(0,o.Mo)("flow-preview-generic_camera")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"method",key:"render",value:function(){if(!this._preview)return a.Ld;if(this._error)return(0,a.dy)(h||(h=v`<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,a.dy)(u||(u=v` ${0} ${0}`),e?(0,a.dy)(c||(c=v`<p>Still image:</p> <p> <img src="${0}" alt="Still preview"> </p>`),e):"",t?(0,a.dy)(y||(y=v`<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}" ="${0}"></ha-hls-player>`),this.hass,t,this._videoLoaded):"")}},{kind:"method",key:"_videoLoaded",value:function(){var e;null===(e=this.shadowRoot.getElementById("hls-load-spinner"))||void 0===e||e.remove()}}]}}),l.FlowPreviewGeneric);i()}catch(h){i(h)}}))}}]);
//# sourceMappingURL=95273.b40e93a0b452fdda.js.map