mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 11:16:35 +00:00
Handle visibility changes in camera players (#26235)
* Handle visibility changes in webrtc player * Implement visibility handling for hls * Remove console logs
This commit is contained in:
parent
aae1a3604c
commit
3e2f5b0dd3
@ -59,6 +59,15 @@ class HaHLSPlayer extends LitElement {
|
||||
|
||||
private static streamCount = 0;
|
||||
|
||||
private _handleVisibilityChange = () => {
|
||||
if (document.hidden) {
|
||||
this._cleanUp();
|
||||
} else {
|
||||
this._resetError();
|
||||
this._startHls();
|
||||
}
|
||||
};
|
||||
|
||||
public connectedCallback() {
|
||||
super.connectedCallback();
|
||||
HaHLSPlayer.streamCount += 1;
|
||||
@ -66,10 +75,15 @@ class HaHLSPlayer extends LitElement {
|
||||
this._resetError();
|
||||
this._startHls();
|
||||
}
|
||||
document.addEventListener("visibilitychange", this._handleVisibilityChange);
|
||||
}
|
||||
|
||||
public disconnectedCallback() {
|
||||
super.disconnectedCallback();
|
||||
document.removeEventListener(
|
||||
"visibilitychange",
|
||||
this._handleVisibilityChange
|
||||
);
|
||||
HaHLSPlayer.streamCount -= 1;
|
||||
this._cleanUp();
|
||||
}
|
||||
|
@ -61,6 +61,14 @@ class HaWebRtcPlayer extends LitElement {
|
||||
|
||||
private _candidatesList: RTCIceCandidate[] = [];
|
||||
|
||||
private _handleVisibilityChange = () => {
|
||||
if (document.hidden) {
|
||||
this._cleanUp();
|
||||
} else {
|
||||
this._startWebRtc();
|
||||
}
|
||||
};
|
||||
|
||||
protected override render(): TemplateResult {
|
||||
if (this._error) {
|
||||
return html`<ha-alert alert-type="error">${this._error}</ha-alert>`;
|
||||
@ -88,10 +96,15 @@ class HaWebRtcPlayer extends LitElement {
|
||||
if (this.hasUpdated && this.entityid) {
|
||||
this._startWebRtc();
|
||||
}
|
||||
document.addEventListener("visibilitychange", this._handleVisibilityChange);
|
||||
}
|
||||
|
||||
public override disconnectedCallback() {
|
||||
super.disconnectedCallback();
|
||||
document.removeEventListener(
|
||||
"visibilitychange",
|
||||
this._handleVisibilityChange
|
||||
);
|
||||
this._cleanUp();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user