Home-AssistantConfig/config/www/community/frigate-hass-card/live-jsmpeg-9c767737.js

13 lines
126 KiB
JavaScript
Raw Normal View History

2024-04-24 04:21:06 +00:00
import{cH as A,dG as t,cW as i,dH as e,s,cX as o,dl as g,dm as I,dj as a,cL as B,l as r,y as C,db as n,bj as E,bk as Q,bl as h,bn as d}from"./card-555679fd.js";import{g as c}from"./endpoint-aa68fc9e.js";function l(){return l=Object.assign?Object.assign.bind():function(A){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&(A[e]=i[e])}return A},l.apply(this,arguments)}function u(A,t){A.prototype=Object.create(t.prototype),A.prototype.constructor=A,w(A,t)}function w(A,t){return w=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(A,t){return A.__proto__=t,A},w(A,t)}var p=A=>"string"==typeof A&&A.constructor===String,D=A=>"Promise"===Object.prototype.toString.call(A).slice(8,-1);var m="WJ3NAvwFY9",f="tR2-0dd-e1",y="ZgIIHVSSYI",R="kAA8SjbHe2",k="OueN4AU4CJ";!function(A,t){void 0===t&&(t={});var i=t.insertAt;if(A&&"undefined"!=typeof document){var e=document.head||document.getElementsByTagName("head")[0],s=document.createElement("style");s.type="text/css","top"===i&&e.firstChild?e.insertBefore(s,e.firstChild):e.appendChild(s),s.styleSheet?s.styleSheet.cssText=A:s.appendChild(document.createTextNode(A))}}(".WJ3NAvwFY9,.ZgIIHVSSYI,.kAA8SjbHe2,.tR2-0dd-e1{height:100%;left:0;position:absolute;top:0;width:100%;z-index:1}.ZgIIHVSSYI{-ms-flex-pack:center;-ms-flex-align:center;-webkit-align-items:center;align-items:center;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-justify-content:center;justify-content:center}.WJ3NAvwFY9,.tR2-0dd-e1{display:block}.tR2-0dd-e1.OueN4AU4CJ{display:none}.ZgIIHVSSYI,.kAA8SjbHe2{-webkit-tap-highlight-color:rgba(255,0,0,0);cursor:pointer;opacity:.7}.OueN4AU4CJ.ZgIIHVSSYI,.OueN4AU4CJ.kAA8SjbHe2{display:none}.ZgIIHVSSYI{z-index:10}.ZgIIHVSSYI>svg{fill:#fff;height:12vw;max-height:60px;max-width:60px;width:12vw}.kAA8SjbHe2{-ms-flex-pack:end;-ms-flex-align:end;-webkit-align-items:flex-end;align-items:flex-end;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-justify-content:flex-end;justify-content:flex-end;z-index:10}.kAA8SjbHe2>svg{fill:#fff;height:9vw;margin:0 15px 15px 0;max-height:40px;max-width:40px;width:9vw}");var b=function(){function A(A,t,i,e){var s=void 0===i?{}:i,o=s.canvas,g=void 0===o?"":o,I=s.poster,a=void 0===I?"":I,B=s.autoplay,r=void 0!==B&&B,C=s.autoSetWrapperSize,n=void 0!==C&&C,E=s.loop,Q=void 0!==E&&E,h=s.control,d=void 0===h||h,c=s.decodeFirstFrame,u=void 0===c||c,w=s.picMode,D=void 0!==w&&w,m=s.progressive,f=void 0===m||m,y=s.chunkSize,R=void 0===y?1048576:y,k=s.hooks,b=void 0===k?{}:k;void 0===e&&(e={}),this.options=l({videoUrl:t,canvas:g,poster:a,picMode:D,autoplay:r,autoSetWrapperSize:n,loop:Q,control:d,decodeFirstFrame:u,progressive:f,chunkSize:R,hooks:l({play:function(){},pause:function(){},stop:function(){},load:function(){}},b)},e),this.options.needPlayButton=this.options.control&&!this.options.picMode,this.player=null,this.els={wrapper:p(A)?document.querySelector(A):A,canvas:null,playButton:document.createElement("div"),unmuteButton:null,poster:null},"static"===window.getComputedStyle(this.els.wrapper).getPropertyValue("position")&&(this.els.wrapper.style.position="relative"),this.els.wrapper.clientRect=this.els.wrapper.getBoundingClientRect(),this.initCanvas(),this.initPlayButton(),this.initPlayer()}var t=A.prototype;return t.initCanvas=function(){this.options.canvas?this.els.canvas=p(this.options.canvas)?document.querySelector(this.options.canvas):this.options.canvas:(this.els.canvas=document.createElement("canvas"),this.els.canvas.classList.add(m),this.els.wrapper.appendChild(this.els.canvas))},t.initPlayer=function(){var A=this;this.options=l(this.options,{canvas:this.els.canvas});var t=l({},this.options,{autoplay:!1});if(this.player=new X(this.options.videoUrl,t,{play:function(){A.options.needPlayButton&&A.els.playButton.classList.add(k),A.els.poster&&A.els.poster.classList.add(k),A.options.hooks.play()},pause:function(){A.options.needPlayButton&&A.els.playButton.classList.remove(k),A.options.hooks.pause()},stop:function(){A.els.poster&&A.els.poster.classList.remove(k),A.opti
/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
class Z{constructor(A){this.Y=A}disconnect(){this.Y=void 0}reconnect(A){this.Y=A}deref(){return this.Y}}class j{constructor(){this.Z=void 0,this.q=void 0}get(){return this.Z}pause(){var A;null!==(A=this.Z)&&void 0!==A||(this.Z=new Promise((A=>this.q=A)))}resume(){var A;null===(A=this.q)||void 0===A||A.call(this),this.Z=this.q=void 0}}
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/const V=A=>!e(A)&&"function"==typeof A.then;const z=A(class extends t{constructor(){super(...arguments),this._$Cwt=1073741823,this._$Cyt=[],this._$CK=new Z(this),this._$CX=new j}render(...A){var t;return null!==(t=A.find((A=>!V(A))))&&void 0!==t?t:i}update(A,t){const e=this._$Cyt;let s=e.length;this._$Cyt=t;const o=this._$CK,g=this._$CX;this.isConnected||this.disconnected();for(let A=0;A<t.length&&!(A>this._$Cwt);A++){const i=t[A];if(!V(i))return this._$Cwt=A,i;A<s&&i===e[A]||(this._$Cwt=1073741823,s=0,Promise.resolve(i).then((async A=>{for(;g.get();)await g.get();const t=o.deref();if(void 0!==t){const e=t._$Cyt.indexOf(i);e>-1&&e<t._$Cwt&&(t._$Cwt=e,t.setValue(A))}})))}return i}disconnected(){this._$CK.disconnect(),this._$CX.pause()}reconnected(){this._$CK.reconnect(this),this._$CX.resume()}});let $=class extends s{constructor(){super(...arguments),this._refreshPlayerTimer=new o}async play(){return this._jsmpegVideoPlayer?.play()}async pause(){this._jsmpegVideoPlayer?.stop()}async mute(){const A=this._jsmpegVideoPlayer?.player;A&&(A.volume=0)}async unmute(){const A=this._jsmpegVideoPlayer?.player;A&&(A.volume=1)}isMuted(){return!this._jsmpegVideoPlayer||0===this._jsmpegVideoPlayer.player.volume}async seek(A){}async setControls(A){}isPaused(){return this._jsmpegVideoPlayer?.player?.paused??!0}async getScreenshotURL(){return this._jsmpegCanvasElement?.toDataURL("image/jpeg")??null}async _createJSMPEGPlayer(A){this._jsmpegVideoPlayer=await new Promise((t=>{let i=!1;const e=new W.VideoElement(this,A,{canvas:this._jsmpegCanvasElement},{pauseWhenHidden:!1,autoplay:!1,protocols:[],audio:!1,videoBufferSize:4194304,preserveDrawingBuffer:!0,...this.cameraConfig?.jsmpeg?.options,reconnectInterval:0,onVideoDecode:()=>{!i&&this._jsmpegCanvasElement&&(i=!0,t(e))},onPlay:()=>g(this),onPause:()=>I(this)})})),this._jsmpegCanvasElement&&a(this,this._jsmpegCanvasElement,{player:this,capabilities:{supportsPause:!0}})}_resetPlayer(){if(this._refreshPlayerTimer.stop(),this._jsmpegVideoPlayer){try{this._jsmpegVideoPlayer.destroy()}catch(A){}this._jsmpegVideoPlayer=void 0}this._jsmpegCanvasElement&&(this._jsmpegCanvasElement.remove(),this._jsmpegCanvasElement=void 0)}connectedCallback(){super.connectedCallback(),this.isConnected&&this.requestUpdate()}disconnectedCallback(){this.isConnected||this._resetPlayer(),super.disconnectedCallback()}async _refreshPlayer(){if(!this.hass)return;this._resetPlayer(),this._jsmpegCanvasElement=document.createElement("canvas"),this._jsmpegCanvasElement.className="media";const A=this.cameraEndpoints?.jsmpeg;if(!A)return B(this,r("error.live_camera_no_endpoint"),{context:this.cameraConfig});const t=await c(this,this.hass,A,86400);t&&(await this._createJSMPEGPlayer(t),this._refreshPlayerTimer.start(82800,(()=>this.requestUpdate())))}render(){return C`${z((async()=>(await this._refreshPlayer(),this._jsmpegVideoPlayer&&this._jsmpegCanvasElement?C`${this._jsmpegCanvasElement}`:B(this,r("error.jsmpeg_no_player"))))(),n({cardWideConfig:this.cardWideConfig}))}`}static get styles(){return E(":host {\n width: 100%;\n height: 100%;\n display: flex;\n}\n\ncanvas {\n display: block;\n width: 100%;\n height: 100%;\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}")}};Q([h({attribute:!1})],$.prototype,"cameraConfig",void 0),Q([h({attribute:!1})],$.prototype,"cameraEndpoints",void 0),Q([h({attribute:!1})],$.prototype,"cardWideConfig",void 0),$=Q([d("frigate-card-live-jsmpeg")],$);export{$ as FrigateCardLiveJSMPEG};