Don't use createRef for patched players.

This commit is contained in:
Dermot Duffy
2022-05-10 12:38:05 -07:00
parent 495170561f
commit cf87e8543a
3 changed files with 46 additions and 29 deletions
+15 -11
View File
@@ -10,28 +10,32 @@
// ====================================================================
import { TemplateResult, css, html } from 'lit';
import { Ref, createRef, ref } from 'lit/directives/ref.js';
import { customElement } from 'lit/decorators.js';
import { query } from 'lit/decorators/query.js';
import { dispatchErrorMessageEvent, dispatchMediaShowEvent } from '../common.js';
customElements.whenDefined('ha-hls-player').then(() => {
@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<HTMLVideoElement> = 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`
<video
${ref(this._videoRef)}
id="video"
?autoplay=${this.autoPlay}
.muted=${this.muted}
?playsinline=${this.playsInline}
@@ -91,8 +95,8 @@ customElements.whenDefined('ha-hls-player').then(() => {
height: 100%;
width: 100%;
}
`
]
`,
];
}
}
});