From 595e13ecac2e664a02e92a25a0efb4fc6ae66be2 Mon Sep 17 00:00:00 2001 From: Philip Allgaier Date: Fri, 7 Jan 2022 17:44:57 +0100 Subject: [PATCH] Fix HLS player cleanup (null access to `removeAttribute`) (#11074) --- src/components/ha-hls-player.ts | 14 +++++++------- src/components/ha-web-rtc-player.ts | 5 ++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/components/ha-hls-player.ts b/src/components/ha-hls-player.ts index dbabf84b20..d99547b6ba 100644 --- a/src/components/ha-hls-player.ts +++ b/src/components/ha-hls-player.ts @@ -98,7 +98,6 @@ class HaHLSPlayer extends LitElement { private async _startHls(): Promise { this._error = undefined; - const videoEl = this._videoEl; const useExoPlayerPromise = this._getUseExoPlayer(); const masterPlaylistPromise = fetch(this.url); @@ -113,7 +112,7 @@ class HaHLSPlayer extends LitElement { if (!hlsSupported) { hlsSupported = - videoEl.canPlayType("application/vnd.apple.mpegurl") !== ""; + this._videoEl.canPlayType("application/vnd.apple.mpegurl") !== ""; } if (!hlsSupported) { @@ -151,9 +150,9 @@ class HaHLSPlayer extends LitElement { if (useExoPlayer && match !== null && match[1] !== undefined) { this._renderHLSExoPlayer(playlist_url); } else if (Hls.isSupported()) { - this._renderHLSPolyfill(videoEl, Hls, playlist_url); + this._renderHLSPolyfill(this._videoEl, Hls, playlist_url); } else { - this._renderHLSNative(videoEl, playlist_url); + this._renderHLSNative(this._videoEl, playlist_url); } } @@ -261,9 +260,10 @@ class HaHLSPlayer extends LitElement { this.hass!.auth.external!.fireMessage({ type: "exoplayer/stop" }); this._exoPlayer = false; } - const videoEl = this._videoEl; - videoEl.removeAttribute("src"); - videoEl.load(); + if (this._videoEl) { + this._videoEl.removeAttribute("src"); + this._videoEl.load(); + } } static get styles(): CSSResultGroup { diff --git a/src/components/ha-web-rtc-player.ts b/src/components/ha-web-rtc-player.ts index b2f64a0645..e65017265e 100644 --- a/src/components/ha-web-rtc-player.ts +++ b/src/components/ha-web-rtc-player.ts @@ -136,9 +136,8 @@ class HaWebRtcPlayer extends LitElement { this._remoteStream = undefined; } if (this._videoEl) { - const videoEl = this._videoEl; - videoEl.removeAttribute("src"); - videoEl.load(); + this._videoEl.removeAttribute("src"); + this._videoEl.load(); } if (this._peerConnection) { this._peerConnection.close();