Correctly record unloaded media.

This commit is contained in:
Dermot Duffy
2022-09-03 15:30:38 -07:00
parent 429ea80db1
commit 24e59dfe4d
5 changed files with 36 additions and 6 deletions
+1
View File
@@ -17,6 +17,7 @@ export class CachedValueController<T> implements ReactiveController {
* Remove the controller for the host. * Remove the controller for the host.
*/ */
public removeController(): void { public removeController(): void {
this.stopTimer();
this._host.removeController(this); this._host.removeController(this);
} }
+16
View File
@@ -1602,6 +1602,10 @@ export class FrigateCard extends LitElement {
if (!this._message || newPriority >= currentPriority) { if (!this._message || newPriority >= currentPriority) {
this._message = message; this._message = message;
// When a message is displayed it is effectively unloading the media.
this._mediaUnloadedHandler();
if (!skipUpdate) { if (!skipUpdate) {
this.requestUpdate(); this.requestUpdate();
this._resetMainScroll(); this._resetMainScroll();
@@ -1646,6 +1650,14 @@ export class FrigateCard extends LitElement {
this.requestUpdate(); this.requestUpdate();
} }
/**
* Unload a media item.
*/
protected _mediaUnloadedHandler(): void {
this._currentMediaLoadedInfo = null;
this._generateConditionState();
}
/** /**
* Handler called when fullscreen is toggled. * Handler called when fullscreen is toggled.
*/ */
@@ -1672,6 +1684,9 @@ export class FrigateCard extends LitElement {
* Component disconnected callback. * Component disconnected callback.
*/ */
disconnectedCallback(): void { disconnectedCallback(): void {
// When the dashboard 'tab' is changed, the media is effectively unloaded.
this._mediaUnloadedHandler();
if (screenfull.isEnabled) { if (screenfull.isEnabled) {
screenfull.off('change', this._fullscreenHandler.bind(this)); screenfull.off('change', this._fullscreenHandler.bind(this));
} }
@@ -1797,6 +1812,7 @@ export class FrigateCard extends LitElement {
@frigate-card:view:change=${this._changeViewHandler.bind(this)} @frigate-card:view:change=${this._changeViewHandler.bind(this)}
@frigate-card:view:change-context=${this._addViewContextHandler.bind(this)} @frigate-card:view:change-context=${this._addViewContextHandler.bind(this)}
@frigate-card:media:loaded=${this._mediaLoadedHandler.bind(this)} @frigate-card:media:loaded=${this._mediaLoadedHandler.bind(this)}
@frigate-card:media:unloaded=${this._mediaUnloadedHandler.bind(this)}
@frigate-card:render=${() => this.requestUpdate()} @frigate-card:render=${() => this.requestUpdate()}
> >
${renderMenuAbove ? this._renderMenu() : ''} ${renderMenuAbove ? this._renderMenu() : ''}
+6 -2
View File
@@ -21,8 +21,9 @@ import { updateElementStyleFromMediaLayoutConfig } from '../utils/media-layout.j
import { dispatchMediaLoadedEvent } from '../utils/media-info.js'; import { dispatchMediaLoadedEvent } from '../utils/media-info.js';
import { View } from '../view.js'; import { View } from '../view.js';
import { dispatchErrorMessageEvent } from './message.js'; import { dispatchErrorMessageEvent } from './message.js';
import { contentsChanged } from '../utils/basic.js';
// See: https://github.com/home-assistant/core/blob/dev/homeassistant/components/camera/__init__.py#L101 // See TOKEN_CHANGE_INTERVAL in https://github.com/home-assistant/core/blob/dev/homeassistant/components/camera/__init__.py .
const HASS_REJECTION_CUTOFF_MS = 5 * 60 * 1000; const HASS_REJECTION_CUTOFF_MS = 5 * 60 * 1000;
@customElement('frigate-card-image') @customElement('frigate-card-image')
@@ -36,7 +37,10 @@ export class FrigateCardImage extends LitElement {
@property({ attribute: false }) @property({ attribute: false })
public cameraConfig?: CameraConfig; public cameraConfig?: CameraConfig;
@property({ attribute: false }) // Using contentsChanged to ensure overridden configs (e.g. when the
// 'show_image_during_load' option is true for live views, an overridden
// config may be used here).
@property({ attribute: false, hasChanged: contentsChanged })
public imageConfig?: ImageViewConfig; public imageConfig?: ImageViewConfig;
protected _refImage: Ref<HTMLImageElement> = createRef(); protected _refImage: Ref<HTMLImageElement> = createRef();
+12 -4
View File
@@ -106,7 +106,7 @@ export class FrigateCardLive extends LitElement {
// MediaLoadedInfo object and message from the underlying live object. In the // MediaLoadedInfo object and message from the underlying live object. In the
// case of pre-loading these may be propagated upwards later. // case of pre-loading these may be propagated upwards later.
protected _savedMediaLoadedInfo: MediaLoadedInfo | null = null; protected _backgroundMediaLoadedInfo: MediaLoadedInfo | null = null;
protected _messageReceivedPostRender = false; protected _messageReceivedPostRender = false;
protected _renderKey = 0; protected _renderKey = 0;
@@ -127,11 +127,12 @@ export class FrigateCardLive extends LitElement {
if ( if (
!this._inBackground && !this._inBackground &&
!this._messageReceivedPostRender && !this._messageReceivedPostRender &&
this._savedMediaLoadedInfo this._backgroundMediaLoadedInfo
) { ) {
// If this isn't being rendered in the background, the last render did not // If this isn't being rendered in the background, the last render did not
// generate a message and there's a saved MediaInfo, dispatch it upwards. // generate a message and there's a saved MediaInfo, dispatch it upwards.
dispatchExistingMediaLoadedInfoAsEvent(this, this._savedMediaLoadedInfo); dispatchExistingMediaLoadedInfoAsEvent(this, this._backgroundMediaLoadedInfo);
this._backgroundMediaLoadedInfo = null;
} }
// Trigger a re-render which may be necessary if the prior render resulted // Trigger a re-render which may be necessary if the prior render resulted
@@ -223,8 +224,8 @@ export class FrigateCardLive extends LitElement {
} }
}} }}
@frigate-card:media:loaded=${(ev: CustomEvent<MediaLoadedInfo>) => { @frigate-card:media:loaded=${(ev: CustomEvent<MediaLoadedInfo>) => {
this._savedMediaLoadedInfo = ev.detail;
if (this._inBackground) { if (this._inBackground) {
this._backgroundMediaLoadedInfo = ev.detail;
ev.stopPropagation(); ev.stopPropagation();
} }
}} }}
@@ -735,6 +736,13 @@ export class FrigateCardLiveProvider extends LitElement {
); );
} }
/**
* Component disconnected callback.
*/
disconnectedCallback(): void {
this._isVideoMediaLoaded = false;
}
/** /**
* Record that video media is being shown. * Record that video media is being shown.
*/ */
+1
View File
@@ -293,6 +293,7 @@ export class FrigateCardMediaCarousel extends LitElement {
this._resizeObserver.disconnect(); this._resizeObserver.disconnect();
this._intersectionObserver.disconnect(); this._intersectionObserver.disconnect();
this._mediaLoadedInfo = {};
super.disconnectedCallback(); super.disconnectedCallback();
} }