Prevent unnecessary JSMPEG re-rendering.
This commit is contained in:
+22
-17
@@ -1,3 +1,4 @@
|
|||||||
|
// TODO Live scrolling nav buttons disappearing
|
||||||
// TODO conditional elements based on camera name (requires event changed to propagate upwards)
|
// TODO conditional elements based on camera name (requires event changed to propagate upwards)
|
||||||
// TODO _shouldInitCarousel on viewer carousel and thumbnail carousel.
|
// TODO _shouldInitCarousel on viewer carousel and thumbnail carousel.
|
||||||
// TODO call change-event in viewer
|
// TODO call change-event in viewer
|
||||||
@@ -9,7 +10,14 @@
|
|||||||
// TODO readme
|
// TODO readme
|
||||||
// TODO search for TODOs
|
// TODO search for TODOs
|
||||||
|
|
||||||
import { CSSResultGroup, LitElement, TemplateResult, html, unsafeCSS, PropertyValues } from 'lit';
|
import {
|
||||||
|
CSSResultGroup,
|
||||||
|
LitElement,
|
||||||
|
TemplateResult,
|
||||||
|
html,
|
||||||
|
unsafeCSS,
|
||||||
|
PropertyValues,
|
||||||
|
} from 'lit';
|
||||||
import {
|
import {
|
||||||
BrowseMediaSource,
|
BrowseMediaSource,
|
||||||
ExtendedHomeAssistant,
|
ExtendedHomeAssistant,
|
||||||
@@ -207,12 +215,11 @@ export class FrigateCardLiveCarousel extends FrigateCardMediaCarousel {
|
|||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
protected liveConfig?: LiveConfig;
|
protected liveConfig?: LiveConfig;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the carousel should be (re-)initialized when the given
|
* Whether or not the carousel should be (re-)initialized when the given
|
||||||
* properties change.
|
* properties change.
|
||||||
* @param changedProperties The properties that triggered the (re-)render.
|
* @param changedProperties The properties that triggered the (re-)render.
|
||||||
* @returns
|
* @returns Whether to re-initialize the carousel.
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
protected _shouldInitCarousel(changedProps: PropertyValues): boolean {
|
protected _shouldInitCarousel(changedProps: PropertyValues): boolean {
|
||||||
@@ -220,7 +227,7 @@ export class FrigateCardLiveCarousel extends FrigateCardMediaCarousel {
|
|||||||
// dimensions. Don't allow other properties to re-initialize the carousel as
|
// dimensions. Don't allow other properties to re-initialize the carousel as
|
||||||
// it's a jarring experience to the user (and 'view' is itself set as a
|
// it's a jarring experience to the user (and 'view' is itself set as a
|
||||||
// result of a carousel move).
|
// result of a carousel move).
|
||||||
return (changedProps.has('cameras') || changedProps.has('liveConfig'));
|
return changedProps.has('cameras') || changedProps.has('liveConfig');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -341,7 +348,7 @@ export class FrigateCardLiveCarousel extends FrigateCardMediaCarousel {
|
|||||||
const target = direction == 'previous' ? prev : next;
|
const target = direction == 'previous' ? prev : next;
|
||||||
|
|
||||||
control.disabled = target == null;
|
control.disabled = target == null;
|
||||||
control.title = getCameraTitle(this.hass, target)
|
control.title = getCameraTitle(this.hass, target);
|
||||||
control.icon = getCameraIcon(this.hass, target);
|
control.icon = getCameraIcon(this.hass, target);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -439,8 +446,7 @@ export class FrigateCardLiveProvider extends LitElement {
|
|||||||
</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.cameraConfig.camera_name}
|
.cameraConfig=${this.cameraConfig}
|
||||||
.clientId=${this.cameraConfig.client_id}
|
|
||||||
.jsmpegConfig=${this.liveConfig.jsmpeg}
|
.jsmpegConfig=${this.liveConfig.jsmpeg}
|
||||||
>
|
>
|
||||||
</frigate-card-live-jsmpeg>`}
|
</frigate-card-live-jsmpeg>`}
|
||||||
@@ -509,7 +515,7 @@ export class FrigateCardLiveWebRTC extends LitElement {
|
|||||||
const webrtcElement = customElements.get('webrtc-camera') as any;
|
const webrtcElement = customElements.get('webrtc-camera') as any;
|
||||||
if (webrtcElement) {
|
if (webrtcElement) {
|
||||||
const webrtc = new webrtcElement();
|
const webrtc = new webrtcElement();
|
||||||
const config = {...this.webRTCConfig};
|
const config = { ...this.webRTCConfig };
|
||||||
|
|
||||||
// If the live WebRTC configuration does not specify a URL/entity to use,
|
// If the live WebRTC configuration does not specify a URL/entity to use,
|
||||||
// then take values from the camera configuration instead (if there are
|
// then take values from the camera configuration instead (if there are
|
||||||
@@ -544,7 +550,8 @@ export class FrigateCardLiveWebRTC extends LitElement {
|
|||||||
this,
|
this,
|
||||||
e instanceof FrigateCardError
|
e instanceof FrigateCardError
|
||||||
? (e as FrigateCardError).message
|
? (e as FrigateCardError).message
|
||||||
: localize('error.webrtc_reported_error') + ': ' + (e as Error).message);
|
: localize('error.webrtc_reported_error') + ': ' + (e as Error).message,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return html`${webrtcElement}`;
|
return html`${webrtcElement}`;
|
||||||
}
|
}
|
||||||
@@ -552,7 +559,7 @@ export class FrigateCardLiveWebRTC extends LitElement {
|
|||||||
/**
|
/**
|
||||||
* Updated lifecycle callback.
|
* Updated lifecycle callback.
|
||||||
*/
|
*/
|
||||||
public updated(changedProps: PropertyValues): void {
|
public updated(): void {
|
||||||
// Extract the video component after it has been rendered and generate the
|
// Extract the video component after it has been rendered and generate the
|
||||||
// media load event.
|
// media load event.
|
||||||
this.updateComplete.then(() => {
|
this.updateComplete.then(() => {
|
||||||
@@ -595,16 +602,13 @@ export class FrigateCardLiveWebRTC extends LitElement {
|
|||||||
@customElement('frigate-card-live-jsmpeg')
|
@customElement('frigate-card-live-jsmpeg')
|
||||||
export class FrigateCardLiveJSMPEG extends LitElement {
|
export class FrigateCardLiveJSMPEG extends LitElement {
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
protected cameraName?: string;
|
protected cameraConfig?: CameraConfig;
|
||||||
|
|
||||||
@property({ attribute: false })
|
|
||||||
protected clientId?: string;
|
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
protected jsmpegConfig?: JSMPEGConfig;
|
protected jsmpegConfig?: JSMPEGConfig;
|
||||||
|
|
||||||
@property({ attribute: false })
|
|
||||||
protected hass?: HomeAssistant & ExtendedHomeAssistant;
|
protected hass?: HomeAssistant & ExtendedHomeAssistant;
|
||||||
|
|
||||||
protected _jsmpegCanvasElement?: HTMLCanvasElement;
|
protected _jsmpegCanvasElement?: HTMLCanvasElement;
|
||||||
protected _jsmpegVideoPlayer?: JSMpeg.VideoElement;
|
protected _jsmpegVideoPlayer?: JSMpeg.VideoElement;
|
||||||
protected _refreshPlayerTimerID?: number;
|
protected _refreshPlayerTimerID?: number;
|
||||||
@@ -614,7 +618,7 @@ export class FrigateCardLiveJSMPEG extends LitElement {
|
|||||||
* @returns A URL or null.
|
* @returns A URL or null.
|
||||||
*/
|
*/
|
||||||
protected async _getURL(): Promise<string | null> {
|
protected async _getURL(): Promise<string | null> {
|
||||||
if (!this.hass || !this.clientId || !this.cameraName) {
|
if (!this.hass || !this.cameraConfig?.client_id || !this.cameraConfig?.camera_name) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -622,7 +626,8 @@ export class FrigateCardLiveJSMPEG extends LitElement {
|
|||||||
try {
|
try {
|
||||||
response = await homeAssistantSignPath(
|
response = await homeAssistantSignPath(
|
||||||
this.hass,
|
this.hass,
|
||||||
`/api/frigate/${this.clientId}` + `/jsmpeg/${this.cameraName}`,
|
`/api/frigate/${this.cameraConfig.client_id}` +
|
||||||
|
`/jsmpeg/${this.cameraConfig.camera_name}`,
|
||||||
URL_SIGN_EXPIRY_SECONDS,
|
URL_SIGN_EXPIRY_SECONDS,
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user