-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add stream preview element to generic camera (#21463)
Co-authored-by: Bram Kragten <[email protected]>
- Loading branch information
1 parent
5ccc336
commit 8fa36c8
Showing
4 changed files
with
68 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/dialogs/config-flow/previews/flow-preview-generic_camera.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { html, nothing } from "lit"; | ||
import { customElement } from "lit/decorators"; | ||
import { FlowPreviewGeneric } from "./flow-preview-generic"; | ||
import "../../../components/ha-hls-player"; | ||
import "../../../components/ha-circular-progress"; | ||
|
||
@customElement("flow-preview-generic_camera") | ||
class FlowPreviewGenericCamera extends FlowPreviewGeneric { | ||
protected override render() { | ||
if (!this._preview) { | ||
return nothing; | ||
} | ||
if (this._error) { | ||
return html`<ha-alert alert-type="error">${this._error}</ha-alert>`; | ||
} | ||
|
||
const stillUrl = this._preview.attributes.still_url; | ||
const streamUrl = this._preview.attributes.stream_url; | ||
|
||
return html` ${stillUrl | ||
? html`<p>Still image:</p> | ||
<p> | ||
<img src=${stillUrl} alt="Still preview" /> | ||
</p>` | ||
: ""} | ||
${streamUrl | ||
? html`<p>Stream:</p> | ||
<ha-circular-progress | ||
class="render-spinner" | ||
id="hls-load-spinner" | ||
indeterminate | ||
size="large" | ||
></ha-circular-progress> | ||
<ha-hls-player | ||
autoplay | ||
playsinline | ||
.hass=${this.hass} | ||
.url=${streamUrl} | ||
@load=${this._videoLoaded} | ||
></ha-hls-player>` | ||
: ""}`; | ||
} | ||
|
||
private _videoLoaded() { | ||
this.shadowRoot!.getElementById("hls-load-spinner")?.remove(); | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"flow-preview-generic_camera": FlowPreviewGenericCamera; | ||
} | ||
} |