diff --git a/src/patches/ha-camera-stream.ts b/src/patches/ha-camera-stream.ts index ebfca95e..68a4ddd9 100644 --- a/src/patches/ha-camera-stream.ts +++ b/src/patches/ha-camera-stream.ts @@ -9,9 +9,11 @@ // available as compilation time. // ==================================================================== -import { Ref, createRef, ref } from 'lit/directives/ref.js'; import { TemplateResult, css, html } from 'lit'; import { customElement } from 'lit/decorators.js'; +import { query } from 'lit/decorators/query.js'; + +import { FrigateCardMediaPlayer } from '../types.js'; import { dispatchMediaShowEvent } from '../common.js'; customElements.whenDefined('ha-camera-stream').then(() => { @@ -38,7 +40,10 @@ customElements.whenDefined('ha-camera-stream').then(() => { @customElement('frigate-card-ha-camera-stream') // eslint-disable-next-line @typescript-eslint/no-unused-vars class FrigateCardHaCameraStream extends customElements.get('ha-camera-stream') { - protected _playerRef: Ref = createRef(); + // Due to an obscure behavior when this card is casted, this element needs + // to use query rather than the ref directive to find the player. + @query('#player') + protected _player: FrigateCardMediaPlayer; // ======================================================================================== // Minor modifications from: @@ -49,28 +54,28 @@ customElements.whenDefined('ha-camera-stream').then(() => { * Play the video. */ public play(): void { - this._playerRef.value?.play(); + this._player?.play(); } /** * Pause the video. */ public pause(): void { - this._playerRef.value?.pause(); + this._player?.pause(); } /** * Mute the video. */ public mute(): void { - this._playerRef.value?.mute(); + this._player?.mute(); } /** * Unmute the video. */ public unmute(): void { - this._playerRef.value?.unmute(); + this._player?.unmute(); } /** @@ -98,7 +103,7 @@ customElements.whenDefined('ha-camera-stream').then(() => { if (this.stateObj.attributes.frontend_stream_type === STREAM_TYPE_HLS) { return this._url ? html` { } if (this.stateObj.attributes.frontend_stream_type === STREAM_TYPE_WEB_RTC) { return html` { @customElement('frigate-card-ha-hls-player') // eslint-disable-next-line @typescript-eslint/no-unused-vars class FrigateCardHaHlsPlayer extends customElements.get('ha-hls-player') { - protected _videoRef: Ref = createRef(); + // Due to an obscure behavior when this card is casted, this element needs + // to use query rather than the ref directive to find the player. + @query('#video') + protected _video: HTMLVideoElement; /** * Play the video. */ public play(): void { - this._videoRef.value?.play(); + this._video?.play(); } /** * Pause the video. */ public pause(): void { - this._videoRef.value?.pause(); + this._video?.pause(); } /** @@ -40,8 +44,8 @@ customElements.whenDefined('ha-hls-player').then(() => { public mute(): void { // The muted property is only for the initial muted state. Must explicitly // set the muted on the video player to make the change dynamic. - if (this._videoRef.value) { - this._videoRef.value.muted = true; + if (this._video) { + this._video.muted = true; } } @@ -50,8 +54,8 @@ customElements.whenDefined('ha-hls-player').then(() => { */ public unmute(): void { // See note in mute(). - if (this._videoRef.value) { - this._videoRef.value.muted = false; + if (this._video) { + this._video.muted = false; } } @@ -66,7 +70,7 @@ customElements.whenDefined('ha-hls-player').then(() => { } return html`