mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 19:26:36 +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 static streamCount = 0;
|
||||||
|
|
||||||
|
private _handleVisibilityChange = () => {
|
||||||
|
if (document.hidden) {
|
||||||
|
this._cleanUp();
|
||||||
|
} else {
|
||||||
|
this._resetError();
|
||||||
|
this._startHls();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public connectedCallback() {
|
public connectedCallback() {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
HaHLSPlayer.streamCount += 1;
|
HaHLSPlayer.streamCount += 1;
|
||||||
@ -66,10 +75,15 @@ class HaHLSPlayer extends LitElement {
|
|||||||
this._resetError();
|
this._resetError();
|
||||||
this._startHls();
|
this._startHls();
|
||||||
}
|
}
|
||||||
|
document.addEventListener("visibilitychange", this._handleVisibilityChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
public disconnectedCallback() {
|
public disconnectedCallback() {
|
||||||
super.disconnectedCallback();
|
super.disconnectedCallback();
|
||||||
|
document.removeEventListener(
|
||||||
|
"visibilitychange",
|
||||||
|
this._handleVisibilityChange
|
||||||
|
);
|
||||||
HaHLSPlayer.streamCount -= 1;
|
HaHLSPlayer.streamCount -= 1;
|
||||||
this._cleanUp();
|
this._cleanUp();
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,14 @@ class HaWebRtcPlayer extends LitElement {
|
|||||||
|
|
||||||
private _candidatesList: RTCIceCandidate[] = [];
|
private _candidatesList: RTCIceCandidate[] = [];
|
||||||
|
|
||||||
|
private _handleVisibilityChange = () => {
|
||||||
|
if (document.hidden) {
|
||||||
|
this._cleanUp();
|
||||||
|
} else {
|
||||||
|
this._startWebRtc();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
protected override render(): TemplateResult {
|
protected override render(): TemplateResult {
|
||||||
if (this._error) {
|
if (this._error) {
|
||||||
return html`<ha-alert alert-type="error">${this._error}</ha-alert>`;
|
return html`<ha-alert alert-type="error">${this._error}</ha-alert>`;
|
||||||
@ -88,10 +96,15 @@ class HaWebRtcPlayer extends LitElement {
|
|||||||
if (this.hasUpdated && this.entityid) {
|
if (this.hasUpdated && this.entityid) {
|
||||||
this._startWebRtc();
|
this._startWebRtc();
|
||||||
}
|
}
|
||||||
|
document.addEventListener("visibilitychange", this._handleVisibilityChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override disconnectedCallback() {
|
public override disconnectedCallback() {
|
||||||
super.disconnectedCallback();
|
super.disconnectedCallback();
|
||||||
|
document.removeEventListener(
|
||||||
|
"visibilitychange",
|
||||||
|
this._handleVisibilityChange
|
||||||
|
);
|
||||||
this._cleanUp();
|
this._cleanUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user