Merge pull request #116 from dermotduffy/avoid-double-render

Improve initial live camera load time
This commit is contained in:
Dermot Duffy
2021-10-10 16:57:00 -07:00
committed by GitHub
+17 -10
View File
@@ -250,14 +250,14 @@ export class FrigateCard extends LitElement {
return null; return null;
} }
protected _getParseErrorPathString(path: (string|number)[]): string { protected _getParseErrorPathString(path: (string | number)[]): string {
let out = ''; let out = '';
for (let i = 0; i < path.length; i++) { for (let i = 0; i < path.length; i++) {
const item = path[i]; const item = path[i];
if (typeof item == 'number') { if (typeof item == 'number') {
out += '[' + item + ']'; out += '[' + item + ']';
} else if (out) { } else if (out) {
out += " -> " + item; out += ' -> ' + item;
} else { } else {
out = item; out = item;
} }
@@ -277,7 +277,9 @@ export class FrigateCard extends LitElement {
if (parseResult.error && parseResult.error.issues) { if (parseResult.error && parseResult.error.issues) {
hint = this._getParseErrorPathString(parseResult.error.issues[0].path); hint = this._getParseErrorPathString(parseResult.error.issues[0].path);
} }
throw new Error(localize('error.invalid_configuration') + (hint ? `: ${hint}` : '')); throw new Error(
localize('error.invalid_configuration') + (hint ? `: ${hint}` : ''),
);
} }
const config = parseResult.data; const config = parseResult.data;
@@ -448,7 +450,7 @@ export class FrigateCard extends LitElement {
} }
let requestRefresh = false; let requestRefresh = false;
if ( if (
(this.config.dimensions?.aspect_ratio_mode ?? 'dynamic') == 'dynamic' && this._isAspectRatioEnforced() &&
(mediaInfo.width != this._mediaInfo?.width || (mediaInfo.width != this._mediaInfo?.width ||
mediaInfo.height != this._mediaInfo?.height) mediaInfo.height != this._mediaInfo?.height)
) { ) {
@@ -480,22 +482,27 @@ export class FrigateCard extends LitElement {
super.disconnectedCallback(); super.disconnectedCallback();
} }
protected _getAspectRatioPadding(): number | null { protected _isAspectRatioEnforced(): boolean {
const aspect_ratio_mode = this.config.dimensions?.aspect_ratio_mode ?? 'dynamic'; const aspect_ratio_mode = this.config.dimensions?.aspect_ratio_mode ?? 'dynamic';
// Do not artifically constrain aspect ratio if: // Do not artifically constrain aspect ratio if:
// - It's fullscreen. // - It's fullscreen.
// - Aspect ratio enforcement is disabled. // - Aspect ratio enforcement is disabled.
// - Or it's a media view (i.e. not the gallery) and there's a loaded media // - Or aspect ratio enforcement is dynamic and it's a media view (i.e. not the gallery).
// item.
if ( return !(
(screenfull.isEnabled && screenfull.isFullscreen) || (screenfull.isEnabled && screenfull.isFullscreen) ||
aspect_ratio_mode == 'unconstrained' || aspect_ratio_mode == 'unconstrained' ||
(this._view.isMediaView() && aspect_ratio_mode == 'dynamic' && this._mediaInfo) (aspect_ratio_mode == 'dynamic' && this._view.isMediaView())
) { );
}
protected _getAspectRatioPadding(): number | null {
if (!this._isAspectRatioEnforced()) {
return null; return null;
} }
const aspect_ratio_mode = this.config.dimensions?.aspect_ratio_mode ?? 'dynamic';
if (aspect_ratio_mode == 'dynamic' && this._mediaInfo) { if (aspect_ratio_mode == 'dynamic' && this._mediaInfo) {
return (this._mediaInfo.height / this._mediaInfo.width) * 100; return (this._mediaInfo.height / this._mediaInfo.width) * 100;
} }