refactor: Convert protected methods to private (#2358)
This commit is contained in:
@@ -71,15 +71,15 @@ export class AdvancedCameraCardLiveCarousel extends LitElement {
|
||||
public viewFilterCameraID?: string;
|
||||
|
||||
// Index between camera name and slide number.
|
||||
protected _cameraToSlide: Record<string, number> = {};
|
||||
protected _refPTZControl: Ref<AdvancedCameraCardPTZ> = createRef();
|
||||
protected _refCarousel: Ref<HTMLElement> = createRef();
|
||||
private _cameraToSlide: Record<string, number> = {};
|
||||
private _refPTZControl: Ref<AdvancedCameraCardPTZ> = createRef();
|
||||
private _refCarousel: Ref<HTMLElement> = createRef();
|
||||
|
||||
protected _mediaActionsController = new MediaActionsController();
|
||||
protected _mediaHeightController = new MediaHeightController(this, '.embla__slide');
|
||||
private _mediaActionsController = new MediaActionsController();
|
||||
private _mediaHeightController = new MediaHeightController(this, '.embla__slide');
|
||||
|
||||
@state()
|
||||
protected _mediaHasLoaded = false;
|
||||
private _mediaHasLoaded = false;
|
||||
|
||||
public connectedCallback(): void {
|
||||
super.connectedCallback();
|
||||
@@ -96,11 +96,11 @@ export class AdvancedCameraCardLiveCarousel extends LitElement {
|
||||
super.disconnectedCallback();
|
||||
}
|
||||
|
||||
protected _getTransitionEffect(): TransitionEffect {
|
||||
private _getTransitionEffect(): TransitionEffect {
|
||||
return this.liveConfig?.transition_effect ?? configDefaults.live.transition_effect;
|
||||
}
|
||||
|
||||
protected _getSelectedCameraIndex(): number {
|
||||
private _getSelectedCameraIndex(): number {
|
||||
if (this.viewFilterCameraID) {
|
||||
// If the carousel is limited to a single cameraID, the first (only)
|
||||
// element is always the selected one.
|
||||
@@ -140,7 +140,7 @@ export class AdvancedCameraCardLiveCarousel extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
protected _getPlugins(): EmblaCarouselPlugins {
|
||||
private _getPlugins(): EmblaCarouselPlugins {
|
||||
return [AutoMediaLoadedInfo()];
|
||||
}
|
||||
|
||||
@@ -151,12 +151,12 @@ export class AdvancedCameraCardLiveCarousel extends LitElement {
|
||||
* should load simultaneously.
|
||||
* @returns
|
||||
*/
|
||||
protected _getLazyLoadCount(): number | null {
|
||||
private _getLazyLoadCount(): number | null {
|
||||
// Defaults to fully-lazy loading.
|
||||
return this.liveConfig?.lazy_load === false ? null : 0;
|
||||
}
|
||||
|
||||
protected _getSlides(): [TemplateResult[], Record<string, number>] {
|
||||
private _getSlides(): [TemplateResult[], Record<string, number>] {
|
||||
if (!this.cameraManager) {
|
||||
return [[], {}];
|
||||
}
|
||||
@@ -179,14 +179,14 @@ export class AdvancedCameraCardLiveCarousel extends LitElement {
|
||||
return [slides, cameraToSlide];
|
||||
}
|
||||
|
||||
protected _setViewHandler(ev: CustomEvent<CarouselSelected>): void {
|
||||
private _setViewHandler(ev: CustomEvent<CarouselSelected>): void {
|
||||
const cameraIDs = this.cameraManager?.getStore().getCameraIDsWithCapability('live');
|
||||
if (cameraIDs?.size && ev.detail.index !== this._getSelectedCameraIndex()) {
|
||||
this._setViewCameraID([...cameraIDs][ev.detail.index]);
|
||||
}
|
||||
}
|
||||
|
||||
protected _setViewCameraID(cameraID?: string | null): void {
|
||||
private _setViewCameraID(cameraID?: string | null): void {
|
||||
if (cameraID) {
|
||||
this.viewManagerEpoch?.manager.setViewByParametersWithNewQuery({
|
||||
params: {
|
||||
@@ -196,7 +196,7 @@ export class AdvancedCameraCardLiveCarousel extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
protected _renderLive(cameraID: string): TemplateResult | void {
|
||||
private _renderLive(cameraID: string): TemplateResult | void {
|
||||
const camera = this.cameraManager?.getStore().getCamera(cameraID);
|
||||
if (!this.liveConfig || !this.hass || !this.cameraManager || !camera) {
|
||||
return;
|
||||
@@ -233,11 +233,11 @@ export class AdvancedCameraCardLiveCarousel extends LitElement {
|
||||
`;
|
||||
}
|
||||
|
||||
protected _getSubstreamCameraID(cameraID: string, view?: View | null): string {
|
||||
private _getSubstreamCameraID(cameraID: string, view?: View | null): string {
|
||||
return view?.context?.live?.overrides?.get(cameraID) ?? cameraID;
|
||||
}
|
||||
|
||||
protected _getCameraNeighbors(): CameraNeighbors | null {
|
||||
private _getCameraNeighbors(): CameraNeighbors | null {
|
||||
const cameraIDs = this.cameraManager
|
||||
? [...this.cameraManager?.getStore().getCameraIDsWithCapability('live')]
|
||||
: [];
|
||||
@@ -279,7 +279,7 @@ export class AdvancedCameraCardLiveCarousel extends LitElement {
|
||||
};
|
||||
}
|
||||
|
||||
protected _renderNextPrevious(
|
||||
private _renderNextPrevious(
|
||||
side: 'left' | 'right',
|
||||
neighbors: CameraNeighbors | null,
|
||||
): TemplateResult {
|
||||
@@ -370,7 +370,7 @@ export class AdvancedCameraCardLiveCarousel extends LitElement {
|
||||
`;
|
||||
}
|
||||
|
||||
protected _setMediaTarget(): void {
|
||||
private _setMediaTarget(): void {
|
||||
const view = this.viewManagerEpoch?.manager.getView();
|
||||
const selectedCameraIndex = this._getSelectedCameraIndex();
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ export class AdvancedCameraCardLiveGrid extends LitElement {
|
||||
@property({ attribute: false })
|
||||
public triggeredCameraIDs?: Set<string>;
|
||||
|
||||
protected _renderCarousel(cameraID?: string): TemplateResult {
|
||||
private _renderCarousel(cameraID?: string): TemplateResult {
|
||||
const view = this.viewManagerEpoch?.manager.getView();
|
||||
const triggeredCameraID = cameraID ?? view?.camera;
|
||||
|
||||
@@ -69,7 +69,7 @@ export class AdvancedCameraCardLiveGrid extends LitElement {
|
||||
`;
|
||||
}
|
||||
|
||||
protected _gridSelectCamera(cameraID: string): void {
|
||||
private _gridSelectCamera(cameraID: string): void {
|
||||
this.viewManagerEpoch?.manager.setViewByParameters({
|
||||
params: {
|
||||
camera: cameraID,
|
||||
@@ -77,7 +77,7 @@ export class AdvancedCameraCardLiveGrid extends LitElement {
|
||||
});
|
||||
}
|
||||
|
||||
protected _needsGrid(): boolean {
|
||||
private _needsGrid(): boolean {
|
||||
const cameraIDs = this.cameraManager?.getStore().getCameraIDsWithCapability('live');
|
||||
const view = this.viewManagerEpoch?.manager.getView();
|
||||
return (
|
||||
|
||||
@@ -33,7 +33,7 @@ export class AdvancedCameraCardLive extends LitElement {
|
||||
@property({ attribute: false })
|
||||
public triggeredCameraIDs?: Set<string>;
|
||||
|
||||
protected _controller = new LiveController(this);
|
||||
private _controller = new LiveController(this);
|
||||
|
||||
protected render(): TemplateResult | void {
|
||||
if (!this.hass || !this.cameraManager) {
|
||||
|
||||
@@ -62,17 +62,17 @@ export class AdvancedCameraCardLiveProvider extends LitElement implements MediaP
|
||||
public zoomSettings?: PartialZoomSettings | null;
|
||||
|
||||
@state()
|
||||
protected _isVideoMediaLoaded = false;
|
||||
private _isVideoMediaLoaded = false;
|
||||
|
||||
@state()
|
||||
protected _hasProviderError = false;
|
||||
private _hasProviderError = false;
|
||||
|
||||
@state()
|
||||
protected _showStreamTroubleshooting = false;
|
||||
private _showStreamTroubleshooting = false;
|
||||
|
||||
protected _refProvider: Ref<MediaPlayerElement> = createRef();
|
||||
private _refProvider: Ref<MediaPlayerElement> = createRef();
|
||||
|
||||
protected _lazyLoadController: LazyLoadController = new LazyLoadController(this);
|
||||
private _lazyLoadController: LazyLoadController = new LazyLoadController(this);
|
||||
|
||||
// A note on dynamic imports:
|
||||
//
|
||||
@@ -84,7 +84,7 @@ export class AdvancedCameraCardLiveProvider extends LitElement implements MediaP
|
||||
// Test case: A card with a non-live view, but live pre-loaded, attempts to
|
||||
// call mute() when the <advanced-camera-card-live> element first renders in
|
||||
// the background. These calls fail without waiting for loading here.
|
||||
protected _importPromises: Promise<unknown>[] = [];
|
||||
private _importPromises: Promise<unknown>[] = [];
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
@@ -106,7 +106,7 @@ export class AdvancedCameraCardLiveProvider extends LitElement implements MediaP
|
||||
* whilst loading.
|
||||
* @returns`true` if an image should be shown.
|
||||
*/
|
||||
protected _shouldShowImageDuringLoading(): boolean {
|
||||
private _shouldShowImageDuringLoading(): boolean {
|
||||
return (
|
||||
!this._isVideoMediaLoaded &&
|
||||
!!this.camera?.getConfig()?.camera_entity &&
|
||||
@@ -123,12 +123,12 @@ export class AdvancedCameraCardLiveProvider extends LitElement implements MediaP
|
||||
super.disconnectedCallback();
|
||||
}
|
||||
|
||||
protected _videoMediaShowHandler(): void {
|
||||
private _videoMediaShowHandler(): void {
|
||||
this._isVideoMediaLoaded = true;
|
||||
this._showStreamTroubleshooting = false;
|
||||
}
|
||||
|
||||
protected _providerErrorHandler(): void {
|
||||
private _providerErrorHandler(): void {
|
||||
this._hasProviderError = true;
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ export class AdvancedCameraCardLiveProvider extends LitElement implements MediaP
|
||||
return result;
|
||||
}
|
||||
|
||||
protected _renderContainer(template: TemplateResult): TemplateResult {
|
||||
private _renderContainer(template: TemplateResult): TemplateResult {
|
||||
const config = this.camera?.getConfig();
|
||||
const intermediateTemplate = html` <advanced-camera-card-media-dimensions-container
|
||||
.dimensionsConfig=${config?.dimensions}
|
||||
|
||||
@@ -53,11 +53,11 @@ export class AdvancedCameraCardGo2RTC extends LitElement implements MediaPlayer
|
||||
public controls = false;
|
||||
|
||||
@state()
|
||||
protected _message: Message | null = null;
|
||||
private _message: Message | null = null;
|
||||
|
||||
protected _player?: VideoRTC;
|
||||
private _player?: VideoRTC;
|
||||
|
||||
protected _mediaPlayerController = new VideoMediaPlayerController(
|
||||
private _mediaPlayerController = new VideoMediaPlayerController(
|
||||
this,
|
||||
() => this._player?.video ?? null,
|
||||
() => this.controls,
|
||||
@@ -81,7 +81,7 @@ export class AdvancedCameraCardGo2RTC extends LitElement implements MediaPlayer
|
||||
this.requestUpdate();
|
||||
}
|
||||
|
||||
protected _handleError(message: Message, e?: Error): void {
|
||||
private _handleError(message: Message, e?: Error): void {
|
||||
if (e) {
|
||||
errorToConsole(e as Error);
|
||||
}
|
||||
@@ -94,7 +94,7 @@ export class AdvancedCameraCardGo2RTC extends LitElement implements MediaPlayer
|
||||
return;
|
||||
}
|
||||
|
||||
protected async _getPlayerSource(): Promise<string | null> {
|
||||
private async _getPlayerSource(): Promise<string | null> {
|
||||
const cameraConfig = this.camera?.getConfig();
|
||||
const proxyConfig = this.camera?.getProxyConfig();
|
||||
if (!this.hass || !cameraConfig) {
|
||||
@@ -155,7 +155,7 @@ export class AdvancedCameraCardGo2RTC extends LitElement implements MediaPlayer
|
||||
return result;
|
||||
}
|
||||
|
||||
protected async _createPlayer(): Promise<void> {
|
||||
private async _createPlayer(): Promise<void> {
|
||||
const src = await this._getPlayerSource();
|
||||
if (!src) {
|
||||
return;
|
||||
|
||||
@@ -24,7 +24,7 @@ export class AdvancedCameraCardLiveHA extends LitElement implements MediaPlayer
|
||||
@property({ attribute: true, type: Boolean })
|
||||
public controls = false;
|
||||
|
||||
protected _playerRef: Ref<MediaPlayerElement> = createRef();
|
||||
private _playerRef: Ref<MediaPlayerElement> = createRef();
|
||||
|
||||
public async getMediaPlayerController(): Promise<MediaPlayerController | null> {
|
||||
await this.updateComplete;
|
||||
|
||||
@@ -19,7 +19,7 @@ export class AdvancedCameraCardLiveImage extends LitElement implements MediaPlay
|
||||
@property({ attribute: false })
|
||||
public cameraConfig?: CameraConfig;
|
||||
|
||||
protected _refImage: Ref<MediaPlayerElement> = createRef();
|
||||
private _refImage: Ref<MediaPlayerElement> = createRef();
|
||||
|
||||
public async getMediaPlayerController(): Promise<MediaPlayerController | null> {
|
||||
await this.updateComplete;
|
||||
|
||||
@@ -39,7 +39,7 @@ const JSMPEG_URL_SIGN_REFRESH_THRESHOLD_SECONDS = 1 * 60 * 60;
|
||||
|
||||
@customElement('advanced-camera-card-live-jsmpeg')
|
||||
export class AdvancedCameraCardLiveJSMPEG extends LitElement implements MediaPlayer {
|
||||
protected hass?: HomeAssistant;
|
||||
private hass?: HomeAssistant;
|
||||
|
||||
@property({ attribute: false })
|
||||
public cameraConfig?: CameraConfig;
|
||||
@@ -51,13 +51,13 @@ export class AdvancedCameraCardLiveJSMPEG extends LitElement implements MediaPla
|
||||
public cardWideConfig?: CardWideConfig;
|
||||
|
||||
@state()
|
||||
protected _message: Message | null = null;
|
||||
private _message: Message | null = null;
|
||||
|
||||
protected _jsmpegCanvasElement?: HTMLCanvasElement;
|
||||
protected _jsmpegVideoPlayer?: JSMpeg.VideoElement;
|
||||
protected _refreshPlayerTimer = new Timer();
|
||||
private _jsmpegCanvasElement?: HTMLCanvasElement;
|
||||
private _jsmpegVideoPlayer?: JSMpeg.VideoElement;
|
||||
private _refreshPlayerTimer = new Timer();
|
||||
|
||||
protected _mediaPlayerController = new JSMPEGMediaPlayerController(
|
||||
private _mediaPlayerController = new JSMPEGMediaPlayerController(
|
||||
this,
|
||||
() => this._jsmpegVideoPlayer ?? null,
|
||||
() => this._jsmpegCanvasElement ?? null,
|
||||
@@ -75,7 +75,7 @@ export class AdvancedCameraCardLiveJSMPEG extends LitElement implements MediaPla
|
||||
}
|
||||
}
|
||||
|
||||
protected async _createJSMPEGPlayer(url: string): Promise<JSMpeg.VideoElement> {
|
||||
private async _createJSMPEGPlayer(url: string): Promise<JSMpeg.VideoElement> {
|
||||
this._jsmpegVideoPlayer = await new Promise<JSMpeg.VideoElement>((resolve) => {
|
||||
let videoDecoded = false;
|
||||
const player = new JSMpeg.VideoElement(
|
||||
@@ -132,7 +132,7 @@ export class AdvancedCameraCardLiveJSMPEG extends LitElement implements MediaPla
|
||||
}
|
||||
}
|
||||
|
||||
protected _resetPlayer(): void {
|
||||
private _resetPlayer(): void {
|
||||
this._message = null;
|
||||
this._refreshPlayerTimer.stop();
|
||||
if (this._jsmpegVideoPlayer) {
|
||||
@@ -164,7 +164,7 @@ export class AdvancedCameraCardLiveJSMPEG extends LitElement implements MediaPla
|
||||
super.disconnectedCallback();
|
||||
}
|
||||
|
||||
protected async _refreshPlayer(): Promise<void> {
|
||||
private async _refreshPlayer(): Promise<void> {
|
||||
if (!this.hass) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -59,11 +59,11 @@ export class AdvancedCameraCardLiveWebRTCCard extends LitElement implements Medi
|
||||
public controls = false;
|
||||
|
||||
@state()
|
||||
protected _message: Message | null = null;
|
||||
private _message: Message | null = null;
|
||||
|
||||
protected hass?: HomeAssistant;
|
||||
private hass?: HomeAssistant;
|
||||
|
||||
protected _mediaPlayerController = new VideoMediaPlayerController(
|
||||
private _mediaPlayerController = new VideoMediaPlayerController(
|
||||
this,
|
||||
() => this._getVideo(),
|
||||
() => this.controls,
|
||||
@@ -74,7 +74,7 @@ export class AdvancedCameraCardLiveWebRTCCard extends LitElement implements Medi
|
||||
}
|
||||
|
||||
// A task to await the load of the WebRTC component.
|
||||
protected _webrtcTask = new Task(this, this._getWebRTCCardElement, () => [1]);
|
||||
private _webrtcTask = new Task(this, this._getWebRTCCardElement, () => [1]);
|
||||
|
||||
connectedCallback(): void {
|
||||
super.connectedCallback();
|
||||
@@ -97,7 +97,7 @@ export class AdvancedCameraCardLiveWebRTCCard extends LitElement implements Medi
|
||||
}
|
||||
}
|
||||
|
||||
protected _getVideoRTC(): VideoRTC | null {
|
||||
private _getVideoRTC(): VideoRTC | null {
|
||||
return (this.renderRoot?.querySelector('#webrtc') ?? null) as VideoRTC | null;
|
||||
}
|
||||
|
||||
@@ -105,13 +105,11 @@ export class AdvancedCameraCardLiveWebRTCCard extends LitElement implements Medi
|
||||
* Get the underlying video player.
|
||||
* @returns The player or `null` if not found.
|
||||
*/
|
||||
protected _getVideo(): HTMLVideoElement | null {
|
||||
private _getVideo(): HTMLVideoElement | null {
|
||||
return this._getVideoRTC()?.video ?? null;
|
||||
}
|
||||
|
||||
protected async _getWebRTCCardElement(): Promise<
|
||||
CustomElementConstructor | undefined
|
||||
> {
|
||||
private async _getWebRTCCardElement(): Promise<CustomElementConstructor | undefined> {
|
||||
await customElements.whenDefined('webrtc-camera');
|
||||
return customElements.get('webrtc-camera');
|
||||
}
|
||||
@@ -119,7 +117,7 @@ export class AdvancedCameraCardLiveWebRTCCard extends LitElement implements Medi
|
||||
/**
|
||||
* Create the WebRTC element. May throw.
|
||||
*/
|
||||
protected _createWebRTC(): HTMLElement | null {
|
||||
private _createWebRTC(): HTMLElement | null {
|
||||
const webrtcElement = this._webrtcTask.value;
|
||||
if (webrtcElement && this.hass && this.cameraConfig) {
|
||||
const webrtc = new webrtcElement() as HTMLElement & {
|
||||
|
||||
Reference in New Issue
Block a user