Don't dispatch media events for pre-rendered live.

This commit is contained in:
Dermot Duffy
2021-10-30 22:12:04 -07:00
parent 5e7ba84bc5
commit b4ec3d34a7
2 changed files with 32 additions and 1 deletions
+2
View File
@@ -710,6 +710,7 @@ export class FrigateCard extends LitElement {
if (!isValidMediaShowInfo(mediaShowInfo)) { if (!isValidMediaShowInfo(mediaShowInfo)) {
return; return;
} }
console.info(`Media show: ${JSON.stringify(mediaShowInfo)}`)
let requestRefresh = false; let requestRefresh = false;
if ( if (
this._isAspectRatioEnforced() && this._isAspectRatioEnforced() &&
@@ -954,6 +955,7 @@ export class FrigateCard extends LitElement {
.hass=${this._hass} .hass=${this._hass}
.config=${this.config} .config=${this.config}
.frigateCameraName=${this._frigateCameraName} .frigateCameraName=${this._frigateCameraName}
.preload=${this.config.live_preload && !this._view.is('live')}
class="${classMap(liveClasses)}" class="${classMap(liveClasses)}"
@frigate-card:media-show=${this._mediaShowHandler} @frigate-card:media-show=${this._mediaShowHandler}
@frigate-card:pause=${this._pauseHandler} @frigate-card:pause=${this._pauseHandler}
+30 -1
View File
@@ -1,5 +1,5 @@
import { CSSResultGroup, LitElement, TemplateResult, html, unsafeCSS } from 'lit'; import { CSSResultGroup, LitElement, TemplateResult, html, unsafeCSS } from 'lit';
import type { ExtendedHomeAssistant, FrigateCardConfig } from '../types.js'; import type { ExtendedHomeAssistant, FrigateCardConfig, MediaShowInfo } from '../types.js';
import { HomeAssistant } from 'custom-card-helpers'; import { HomeAssistant } from 'custom-card-helpers';
import { customElement, property } from 'lit/decorators.js'; import { customElement, property } from 'lit/decorators.js';
import { until } from 'lit/directives/until.js'; import { until } from 'lit/directives/until.js';
@@ -7,6 +7,7 @@ import { until } from 'lit/directives/until.js';
import { localize } from '../localize/localize.js'; import { localize } from '../localize/localize.js';
import { import {
dispatchErrorMessageEvent, dispatchErrorMessageEvent,
dispatchExistingMediaShowInfoAsEvent,
dispatchMediaShowEvent, dispatchMediaShowEvent,
dispatchMessageEvent, dispatchMessageEvent,
dispatchPauseEvent, dispatchPauseEvent,
@@ -36,23 +37,51 @@ export class FrigateCardLive extends LitElement {
@property({ attribute: false }) @property({ attribute: false })
protected frigateCameraName!: string; protected frigateCameraName!: string;
@property({ attribute: false })
set preload(preload: boolean) {
this._preload = preload;
if (!preload && this._savedMediaShowInfo) {
dispatchExistingMediaShowInfoAsEvent(this, this._savedMediaShowInfo);
}
}
// Whether or not the live view is currently being preloaded.
protected _preload?: boolean;
// MediaShowInfo object from the underlying live object. In the case of
// pre-loading it may be propagated upwards later.
protected _savedMediaShowInfo?: MediaShowInfo;
protected _mediaShowHandler(e: CustomEvent<MediaShowInfo>): void {
this._savedMediaShowInfo = e.detail;
if (this._preload) {
// If live is being pre-loaded, don't let the event propogate upwards yet
// as the media is not really being shown.
e.stopPropagation();
}
}
protected render(): TemplateResult | void { protected render(): TemplateResult | void {
return html` ${this.config.live_provider == 'frigate' return html` ${this.config.live_provider == 'frigate'
? html` <frigate-card-live-frigate ? html` <frigate-card-live-frigate
.hass=${this.hass} .hass=${this.hass}
.cameraEntity=${this.config.camera_entity} .cameraEntity=${this.config.camera_entity}
@frigate-card:media-show=${this._mediaShowHandler}
> >
</frigate-card-live-frigate>` </frigate-card-live-frigate>`
: this.config.live_provider == 'webrtc' : this.config.live_provider == 'webrtc'
? html`<frigate-card-live-webrtc ? html`<frigate-card-live-webrtc
.hass=${this.hass} .hass=${this.hass}
.webRTCConfig=${this.config.webrtc || {}} .webRTCConfig=${this.config.webrtc || {}}
@frigate-card:media-show=${this._mediaShowHandler}
> >
</frigate-card-live-webrtc>` </frigate-card-live-webrtc>`
: html` <frigate-card-live-jsmpeg : html` <frigate-card-live-jsmpeg
.hass=${this.hass} .hass=${this.hass}
.cameraName=${this.frigateCameraName} .cameraName=${this.frigateCameraName}
.clientId=${this.config.frigate_client_id} .clientId=${this.config.frigate_client_id}
@frigate-card:media-show=${this._mediaShowHandler}
> >
</frigate-card-live-jsmpeg>`}`; </frigate-card-live-jsmpeg>`}`;
} }