fix: Fix issues with lazy loading and overridden configuration (#2012)

- Closes #2011
This commit is contained in:
Dermot Duffy authored and GitHub committed 2025-04-15 17:10:18 +01:00
1 parent 54ee1e1cf3
commit 168b9b0c90
4 files changed
+62 -48

No files matched your search

+10 -7
View File
@@ -7,22 +7,25 @@ export class LazyLoadController implements ReactiveController {
private _host: ReactiveControllerHost & HTMLElement;
private _documentVisible = true;
private _intersects = false;
private _loaded: boolean;
private _loaded = false;
private _unloadConditions: LazyUnloadCondition[] | null = null;
private _intersectionObserver = new IntersectionObserver(
this._intersectionHandler.bind(this),
);
private _listeners: LazyLoadListener[] = [];
constructor(
host: ReactiveControllerHost & HTMLElement,
constructor(host: ReactiveControllerHost & HTMLElement) {
this._host = host;
this._host.addController(this);
}
public setConfiguration(
lazyLoad?: boolean,
lazyUnloadConditions?: LazyUnloadCondition[],
) {
this._host = host;
this._host.addController(this);
this._loaded = !lazyLoad;
if (!lazyLoad && !this._loaded) {
this._setLoaded(true);
}
this._unloadConditions = lazyUnloadConditions ?? null;
}
+12 -11
View File
@@ -69,7 +69,7 @@ export class AdvancedCameraCardLiveProvider extends LitElement implements MediaP
protected _showStreamTroubleshooting = false;
protected _refProvider: Ref<MediaPlayerElement> = createRef();
protected _lazyLoadController: LazyLoadController | null = null;
protected _lazyLoadController: LazyLoadController = new LazyLoadController(this);
// A note on dynamic imports:
//
@@ -83,6 +83,16 @@ export class AdvancedCameraCardLiveProvider extends LitElement implements MediaP
// background. These calls fail without waiting for loading here.
protected _importPromises: Promise<unknown>[] = [];
constructor() {
super();
this._lazyLoadController.addListener((loaded: boolean) => {
if (!loaded) {
this._isVideoMediaLoaded = false;
dispatchMediaUnloadedEvent(this);
}
});
}
public async getMediaPlayerController(): Promise<MediaPlayerController | null> {
await this.updateComplete;
return (await this._refProvider.value?.getMediaPlayerController()) ?? null;
@@ -145,19 +155,10 @@ export class AdvancedCameraCardLiveProvider extends LitElement implements MediaP
changedProps.has('liveConfig') ||
(!this._lazyLoadController && this.liveConfig)
) {
this._lazyLoadController?.destroy();
this._lazyLoadController?.removeController();
this._lazyLoadController = new LazyLoadController(
this,
this._lazyLoadController.setConfiguration(
this.liveConfig?.lazy_load,
this.liveConfig?.lazy_unload,
);
this._lazyLoadController.addListener((loaded: boolean) => {
if (!loaded) {
this._isVideoMediaLoaded = false;
dispatchMediaUnloadedEvent(this);
}
});
}
if (changedProps.has('liveConfig')) {
+7 -8
View File
@@ -69,11 +69,16 @@ export class AdvancedCameraCardViewerProvider extends LitElement implements Medi
public cardWideConfig?: CardWideConfig;
protected _refProvider: Ref<MediaPlayerElement> = createRef();
protected _lazyLoadController: LazyLoadController | null = null;
protected _lazyLoadController: LazyLoadController = new LazyLoadController(this);
@state()
protected _url: string | null = null;
constructor() {
super();
this._lazyLoadController.addListener((loaded) => loaded && this._setURL());
}
public async getMediaPlayerController(): Promise<MediaPlayerController | null> {
await this.updateComplete;
return (await this._refProvider.value?.getMediaPlayerController()) ?? null;
@@ -184,13 +189,7 @@ export class AdvancedCameraCardViewerProvider extends LitElement implements Medi
changedProps.has('viewerConfig') ||
(!this._lazyLoadController && this.viewerConfig)
) {
this._lazyLoadController?.destroy();
this._lazyLoadController?.removeController();
this._lazyLoadController = new LazyLoadController(
this,
this.viewerConfig?.lazy_load,
);
this._lazyLoadController.addListener((loaded) => loaded && this._setURL());
this._lazyLoadController.setConfiguration(this.viewerConfig?.lazy_load);
}
if (