fix: Guard the ha provider MJPEG stream URL against a missing access_token (#2602)
- Closes: #2601
This commit is contained in:
@@ -56,8 +56,10 @@ void customElements.whenDefined('ha-camera-stream').then(() => {
|
|||||||
// - https://github.com/home-assistant/frontend/blob/dev/src/common/entity/compute_state_name.ts
|
// - https://github.com/home-assistant/frontend/blob/dev/src/common/entity/compute_state_name.ts
|
||||||
// - https://github.com/home-assistant/frontend/blob/dev/src/common/entity/compute_object_id.ts
|
// - https://github.com/home-assistant/frontend/blob/dev/src/common/entity/compute_object_id.ts
|
||||||
// ========================================================================================
|
// ========================================================================================
|
||||||
const computeMJPEGStreamUrl = (entity: CameraEntity): string =>
|
const computeMJPEGStreamUrl = (entity: CameraEntity): string | undefined =>
|
||||||
`/api/camera_proxy_stream/${entity.entity_id}?token=${entity.attributes.access_token}`;
|
entity.attributes.access_token
|
||||||
|
? `/api/camera_proxy_stream/${entity.entity_id}?token=${entity.attributes.access_token}`
|
||||||
|
: undefined;
|
||||||
|
|
||||||
const STREAM_TYPE_HLS = 'hls';
|
const STREAM_TYPE_HLS = 'hls';
|
||||||
const STREAM_TYPE_WEB_RTC = 'web_rtc';
|
const STREAM_TYPE_WEB_RTC = 'web_rtc';
|
||||||
@@ -188,15 +190,23 @@ void customElements.whenDefined('ha-camera-stream').then(() => {
|
|||||||
return nothing;
|
return nothing;
|
||||||
}
|
}
|
||||||
if (stream.type === STREAM_TYPE_MJPEG) {
|
if (stream.type === STREAM_TYPE_MJPEG) {
|
||||||
|
// A missing `access_token` (e.g. transient token rotation) yields no
|
||||||
|
// URL; render nothing rather than a broken `token=undefined` image.
|
||||||
|
const url =
|
||||||
|
typeof this._connected == 'undefined' || this._connected
|
||||||
|
? computeMJPEGStreamUrl(this.stateObj)
|
||||||
|
: this._posterUrl;
|
||||||
|
if (!url) {
|
||||||
|
return nothing;
|
||||||
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<advanced-camera-card-image-player
|
<advanced-camera-card-image-player
|
||||||
.targetID=${this.targetID}
|
.targetID=${this.targetID}
|
||||||
@advanced-camera-card:media:loaded=${(
|
@advanced-camera-card:media:loaded=${(
|
||||||
ev: CustomEvent<MediaLoadedInfoEventDetail>,
|
ev: CustomEvent<MediaLoadedInfoEventDetail>,
|
||||||
) => this._captureInnerLoad(STREAM_TYPE_MJPEG, ev)}
|
) => this._captureInnerLoad(STREAM_TYPE_MJPEG, ev)}
|
||||||
url=${typeof this._connected == 'undefined' || this._connected
|
url=${url}
|
||||||
? computeMJPEGStreamUrl(this.stateObj)
|
|
||||||
: this._posterUrl || ''}
|
|
||||||
technology="mjpeg"
|
technology="mjpeg"
|
||||||
class="player"
|
class="player"
|
||||||
></advanced-camera-card-image-player>
|
></advanced-camera-card-image-player>
|
||||||
|
|||||||
Reference in New Issue
Block a user