Compare commits

...
Author SHA1 Message Date
WendelinandClaude Opus 5.5 78f64081dd Keep the camera stream when entering full screen in the companion apps
The Android app hides the page for a moment while it enters full screen.
The WebRTC and HLS players stop the stream right away when the page gets
hidden in the companion apps, so entering full screen restarted it, which
can take a while or stall over remote connections, and the paused video
showed the play button.

Entering full screen with the player's button now lets the first hidden
page within a second through with a short delayed clean up, and the player
plays on if the app paused the video. Leaving full screen, locking the
phone or leaving the app still stop the streams right away.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-30 17:13:26 +01:00
WendelinandClaude Opus 5.5 cafb485e1e Keep the camera zoom when entering or leaving full screen
The player refits the zoom whenever its size changes, so it keeps the part
of the picture in the middle instead of resetting it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-30 16:58:27 +01:00
4 changed files with 109 additions and 18 deletions

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
/**
* How long after the full screen button the companion apps hide the page for
* the change, and after that how long they keep it hidden. A later hide ends
* streams as usual.
*/
export const FULLSCREEN_ENTER_TIME = 1000;
let enterStart = 0;
let enterId = 0;
// The last entering each stream let a hidden page through for
const claimedEnters = new WeakMap<object, number>();
/**
* Marks that the full screen button was pressed to enter full screen. The
* companion apps hide the page for a moment then, which shouldn't end a
* stream. Leaving full screen isn't marked, so locking the phone or leaving
* the app right after it always ends the streams.
*/
export const startEnteringFullscreen = () => {
enterId++;
enterStart = Date.now();
};
/** Ends it early, like when the browser denies full screen. */
export const cancelEnteringFullscreen = () => {
enterStart = 0;
};
export const isEnteringFullscreen = () =>
Date.now() - enterStart < FULLSCREEN_ENTER_TIME;
/**
* Whether the page is hidden by entering full screen, which hides it only
* once. Any later hiding is the user leaving, so each stream gets true only
* once per entering.
*/
export const claimFullscreenEnterHide = (stream: object): boolean => {
if (!isEnteringFullscreen() || claimedEnters.get(stream) === enterId) {
return false;
}
claimedEnters.set(stream, enterId);
// Counts from here, so the video still plays on when the page shows again
enterStart = Date.now();
return true;
};
+38 -8
View File
@@ -17,11 +17,17 @@ import { consumeLocalize } from "../../common/decorators/consume-context-entry";
import { storage } from "../../common/decorators/storage";
import { deepActiveElement } from "../../common/dom/deep-active-element";
import { fireEvent, type HASSDomEvent } from "../../common/dom/fire_event";
import {
cancelEnteringFullscreen,
isEnteringFullscreen,
startEnteringFullscreen,
} from "../../common/dom/entering-fullscreen";
import { ctrlOrCmdLabel } from "../../common/keyboard/ctrl-or-cmd";
import type { LocalizeFunc } from "../../common/translations/localize";
import { nextRender } from "../../common/util/render-status";
import type { CameraCapabilities, CameraEntity } from "../../data/camera";
import type { CameraStreamStatus } from "../../data/camera-streams";
import { isExternal } from "../../data/external";
import {
showCameraStreamInfoDialog,
type CameraStreamInfo,
@@ -142,6 +148,10 @@ export class HaCameraPlayer extends LitElement {
// full screen player
@state() private _paused = false;
// Playing when its button entered full screen, so a pause meanwhile is the
// companion app's
private _playingBeforeFullscreen = false;
@query("ha-camera-stream") private _stream?: HaCameraStream;
@query(".player") private _player?: HTMLElement;
@@ -195,7 +205,7 @@ export class HaCameraPlayer extends LitElement {
public connectedCallback() {
super.connectedCallback();
document.addEventListener("visibilitychange", this._requestWakeLock);
document.addEventListener("visibilitychange", this._visibilityChanged);
// The first update requests it, once keep-awake is set
if (this.hasUpdated) {
this._requestWakeLock();
@@ -209,7 +219,7 @@ export class HaCameraPlayer extends LitElement {
public disconnectedCallback() {
super.disconnectedCallback();
document.removeEventListener("visibilitychange", this._requestWakeLock);
document.removeEventListener("visibilitychange", this._visibilityChanged);
this._releaseWakeLock();
document.removeEventListener("fullscreenchange", this._fullscreenChanged);
document.removeEventListener(
@@ -485,6 +495,11 @@ export class HaCameraPlayer extends LitElement {
</div>`;
}
private _visibilityChanged = () => {
this._requestWakeLock();
this._resumeAfterEnteringFullscreen();
};
/**
* Browsers release the lock when the page is hidden, so it is requested
* again whenever the page shows.
@@ -720,6 +735,7 @@ export class HaCameraPlayer extends LitElement {
this._paused = Boolean(
video?.paused && (video.srcObject || video.currentSrc)
);
this._resumeAfterEnteringFullscreen();
};
private _toggleMute() {
@@ -771,16 +787,25 @@ export class HaCameraPlayer extends LitElement {
("webkitFullscreenElement" in document
? (document.webkitFullscreenElement as Element | null)
: null);
const fullscreen = Boolean(
this._fullscreen = Boolean(
this._player && fullscreenElement === this._player
);
if (fullscreen !== this._fullscreen) {
this._fullscreen = fullscreen;
// The size changes, so the zoomed in area would be off
this._zoom = ZOOM_PAN_IDENTITY;
}
this._resumeAfterEnteringFullscreen();
};
// The companion apps pause the video while entering full screen
private _resumeAfterEnteringFullscreen() {
if (
isExternal &&
this._playingBeforeFullscreen &&
this._paused &&
document.visibilityState === "visible" &&
isEnteringFullscreen()
) {
this._ensurePlaying();
}
}
private async _toggleFullscreen() {
const player = this._player;
if (!player) {
@@ -795,6 +820,10 @@ export class HaCameraPlayer extends LitElement {
}
return;
}
this._playingBeforeFullscreen = Boolean(
this._video && !this._video.paused
);
startEnteringFullscreen();
if (player.requestFullscreen) {
await player.requestFullscreen();
} else if ("webkitRequestFullscreen" in player) {
@@ -808,6 +837,7 @@ export class HaCameraPlayer extends LitElement {
}
} catch (_err: unknown) {
// Denied by the browser
cancelEnteringFullscreen();
}
}
+12 -5
View File
@@ -9,6 +9,10 @@ import { consume } from "../common/decorators/consume";
import { isComponentLoaded } from "../common/config/is_component_loaded";
import { consumeLocalize } from "../common/decorators/consume-context-entry";
import { fireEvent } from "../common/dom/fire_event";
import {
claimFullscreenEnterHide,
FULLSCREEN_ENTER_TIME,
} from "../common/dom/entering-fullscreen";
import type { LocalizeFunc } from "../common/translations/localize";
import { nextRender } from "../common/util/render-status";
import { fetchStreamUrl } from "../data/camera";
@@ -101,16 +105,19 @@ export class HaHLSPlayer extends LitElement {
return;
}
if (document.hidden) {
if (isExternal) {
if (isExternal && !claimFullscreenEnterHide(this)) {
// The companion apps pause JavaScript timers while in the background,
// so a delayed clean up would not run until the app is opened again
this._cleanUp();
return;
}
this._hiddenCleanupTimeout = window.setTimeout(() => {
this._hiddenCleanupTimeout = undefined;
this._cleanUp();
}, HIDDEN_CLEANUP_DELAY);
this._hiddenCleanupTimeout = window.setTimeout(
() => {
this._hiddenCleanupTimeout = undefined;
this._cleanUp();
},
isExternal ? FULLSCREEN_ENTER_TIME : HIDDEN_CLEANUP_DELAY
);
} else if (this._hiddenCleanupTimeout) {
// stream was not cleaned up yet, just cancel the cleanup
clearTimeout(this._hiddenCleanupTimeout);
+12 -5
View File
@@ -8,6 +8,10 @@ import { styleMap } from "lit/directives/style-map";
import { consume } from "../common/decorators/consume";
import { consumeLocalize } from "../common/decorators/consume-context-entry";
import { fireEvent } from "../common/dom/fire_event";
import {
claimFullscreenEnterHide,
FULLSCREEN_ENTER_TIME,
} from "../common/dom/entering-fullscreen";
import type { LocalizeFunc } from "../common/translations/localize";
import {
addWebRtcCandidate,
@@ -242,16 +246,19 @@ export class HaWebRtcPlayer extends LitElement {
return;
}
if (document.hidden) {
if (isExternal) {
if (isExternal && !claimFullscreenEnterHide(this)) {
// The companion apps pause JavaScript timers while in the background,
// so a delayed clean up would not run until the app is opened again
this._cleanUp();
return;
}
this._hiddenCleanupTimeout = window.setTimeout(() => {
this._hiddenCleanupTimeout = undefined;
this._cleanUp();
}, HIDDEN_CLEANUP_DELAY);
this._hiddenCleanupTimeout = window.setTimeout(
() => {
this._hiddenCleanupTimeout = undefined;
this._cleanUp();
},
isExternal ? FULLSCREEN_ENTER_TIME : HIDDEN_CLEANUP_DELAY
);
} else if (this._hiddenCleanupTimeout) {
// stream was not cleaned up yet, just cancel the cleanup
clearTimeout(this._hiddenCleanupTimeout);