fix(plex): deep-review follow-ups on E6 transcode + player polish

Eight verified findings from the sprint deep-review:

- Transcode cap: _enforce_cap now counts only transcode sessions, so a
  live remux (stream-copy) stream can no longer be LRU-evicted mid-play —
  matching the config comment + the HU/EN Config hint that promise remux
  is uncapped.
- Player Back: the browser/mouse Back interceptor (BackClose) now also
  mounts for the stats overlay and up-next card, so Back closes them first
  instead of ejecting the whole player (keyboard/Esc already did).
- Honest cold-start: loadSession clears sessionIsTranscode up front, so a
  transcode->direct/remux switch no longer flashes a stale "Preparing
  stream..." during the session request.
- Stats overlay a11y: the close (X) buttons in the stats, help and info
  overlays now read as "Close"/"Bezaras" (new plex.player.close key), not
  "Back"; dropped aria-live from the per-second stat grid so a screen
  reader is not flooded with telemetry.

Tests: route-level transcode routing (transcode item -> HLS re-encode
session, remux stays copy, direct opens none); start_session threading the
preset/crf/max_height knobs + hw/preexec into the ffmpeg argv; UpNextCard
countdown auto-advance, Play-now, Cancel and the S?-E? heading fallback.

Also brings UpNextCard.tsx / plexStats.ts / plexStats.test.ts to prettier.
This commit is contained in:
2026-08-30 02:04:17 +02:00
parent dc24d353e0
commit 00539a4d97
12 changed files with 335 additions and 16 deletions
+1 -1
View File
@@ -425,7 +425,7 @@ export default function PlexInfo({
<button
onClick={onClose}
className="shrink-0 p-1.5 rounded-lg text-white/80 hover:bg-white/15"
aria-label={t("plex.player.back")}
aria-label={t("plex.player.close")}
>
<X className="w-5 h-5" />
</button>
+12 -4
View File
@@ -206,6 +206,10 @@ export default function PlexPlayer({ itemId, onClose, queue }: Props) {
setReady(false);
setBuffering(false);
setLoadError(null);
// Clear the prior item's transcode flag up front so the cold-start overlay can't show a stale
// "Preparing stream…" for a not-yet-known session while the plexSession request is in flight —
// it's re-set honestly from the response below.
setSessionIsTranscode(false);
let sess;
try {
// Multi-audio → request the multi-rendition session (no single `audio` ordinal); the track is
@@ -832,9 +836,13 @@ export default function PlexPlayer({ itemId, onClose, queue }: Props) {
{/* While a panel/menu is open or an auto-skip countdown is running, take over the browser/mouse
Back button (history popstate) so it closes/cancels that instead of dropping to the grid. */}
{(menuOpen || tracksOpen || helpOpen || infoOpen || skipProgress != null) && (
<BackClose onBack={backIntent} />
)}
{(menuOpen ||
tracksOpen ||
helpOpen ||
infoOpen ||
statsOpen ||
upNextOpen ||
skipProgress != null) && <BackClose onBack={backIntent} />}
{/* Top bar */}
<div
@@ -1235,7 +1243,7 @@ export default function PlexPlayer({ itemId, onClose, queue }: Props) {
<button
onClick={() => setHelpOpen(false)}
className="p-1 rounded-lg hover:bg-white/10"
aria-label={t("plex.player.back")}
aria-label={t("plex.player.close")}
>
<X className="w-5 h-5" />
</button>
+5 -2
View File
@@ -109,13 +109,16 @@ export function PlexStatsOverlay({
</span>
<button
onClick={onClose}
aria-label={t("plex.player.back")}
aria-label={t("plex.player.close")}
className="rounded p-0.5 text-white/60 hover:bg-white/10 hover:text-white"
>
<X className="h-4 w-4" />
</button>
</div>
<dl aria-live="polite" className="grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-2xs">
{/* No aria-live here: the rows re-sample every second, so a live region would make a screen
reader announce the changing values continuously and drown out real player announcements.
The overlay is a role="region" (labelled above) a user reads on demand, not a status feed. */}
<dl className="grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-2xs">
{rows.map((r) => (
<div key={r.key} className="contents">
<dt className="text-white/55">{t(r.labelKey)}</dt>
@@ -0,0 +1,93 @@
// @vitest-environment jsdom
//
// The up-next end-card's core behaviour (E6 S4): the countdown that auto-advances at ~10s (the whole
// point — it REPLACED the old instant jump, so a regression that fires early or never is exactly the
// bug to guard), the "Play now"/Cancel controls, and the episode heading's null season/episode
// fallback. i18n is key-passthrough; `../lib/api` is mocked so no network runs; the countdown uses
// performance.now, which vitest's fake timers advance alongside setInterval.
import { describe, it, expect, afterEach, vi } from "vitest";
import { render, screen, fireEvent, cleanup, act } from "@testing-library/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
vi.mock("react-i18next", async (importOriginal) => {
const actual = await importOriginal<typeof import("react-i18next")>();
return { ...actual, useTranslation: () => ({ t: (key: string) => key }) };
});
vi.mock("../lib/api", () => ({
api: { plexItem: vi.fn(), plexImageUrl: () => "/img" },
}));
import { UpNextCard } from "./UpNextCard";
import { api } from "../lib/api";
afterEach(() => {
cleanup();
vi.useRealTimers();
vi.clearAllMocks();
});
function renderCard(opts: { onAdvance?: () => void; onCancel?: () => void } = {}) {
const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });
return render(
<QueryClientProvider client={qc}>
<UpNextCard
nextId="e7"
onAdvance={opts.onAdvance ?? vi.fn()}
onCancel={opts.onCancel ?? vi.fn()}
/>
</QueryClientProvider>,
);
}
describe("UpNextCard", () => {
it("auto-advances after the ~10s countdown, and NOT before", () => {
vi.useFakeTimers();
// A never-resolving detail query: the heading is irrelevant here and this avoids async state
// updates racing the fake clock.
(api.plexItem as ReturnType<typeof vi.fn>).mockReturnValue(new Promise(() => {}));
const onAdvance = vi.fn();
renderCard({ onAdvance });
act(() => {
vi.advanceTimersByTime(9000);
});
expect(onAdvance).not.toHaveBeenCalled(); // still counting down
act(() => {
vi.advanceTimersByTime(1200);
});
expect(onAdvance).toHaveBeenCalledTimes(1); // crossed zero → advanced exactly once
});
it("'Play now' advances immediately, without waiting for the countdown", () => {
(api.plexItem as ReturnType<typeof vi.fn>).mockReturnValue(new Promise(() => {}));
const onAdvance = vi.fn();
renderCard({ onAdvance });
fireEvent.click(screen.getByRole("button", { name: /playNow/ }));
expect(onAdvance).toHaveBeenCalledTimes(1);
});
it("Cancel dismisses via onCancel and does not advance", () => {
(api.plexItem as ReturnType<typeof vi.fn>).mockReturnValue(new Promise(() => {}));
const onAdvance = vi.fn();
const onCancel = vi.fn();
renderCard({ onAdvance, onCancel });
fireEvent.click(screen.getByText("plex.player.upNext.cancel"));
expect(onCancel).toHaveBeenCalledTimes(1);
expect(onAdvance).not.toHaveBeenCalled();
});
it("an episode heading falls back to S?·E? when season/episode are null", async () => {
(api.plexItem as ReturnType<typeof vi.fn>).mockResolvedValue({
id: "e7",
kind: "episode",
show_title: "Westworld",
title: "The Adversary",
season_number: null,
episode_number: null,
});
renderCard();
expect(await screen.findByText("Westworld · S?·E?")).toBeTruthy();
});
});
+8 -1
View File
@@ -90,7 +90,14 @@ export function UpNextCard({
>
<span className="relative grid h-[22px] w-[22px] flex-none place-items-center">
<svg viewBox="0 0 24 24" className="absolute inset-0 -rotate-90">
<circle cx="12" cy="12" r={R} fill="none" stroke="rgba(0,0,0,0.25)" strokeWidth="2" />
<circle
cx="12"
cy="12"
r={R}
fill="none"
stroke="rgba(0,0,0,0.25)"
strokeWidth="2"
/>
<circle
cx="12"
cy="12"
+1
View File
@@ -157,6 +157,7 @@
"buffering": "Buffering…",
"preparing": "Preparing stream…",
"back": "Back",
"close": "Close",
"skipIntro": "Skip intro",
"skipCredits": "Skip credits",
"playPause": "Play / pause (space)",
+1
View File
@@ -157,6 +157,7 @@
"buffering": "Pufferelés…",
"preparing": "Stream előkészítése…",
"back": "Vissza",
"close": "Bezárás",
"skipIntro": "Intro átugrása",
"skipCredits": "Stáblista átugrása",
"playPause": "Lejátszás / szünet (szóköz)",
+3 -1
View File
@@ -119,7 +119,9 @@ describe("buildStatRows", () => {
});
it("shows an empty classification honestly as a dash", () => {
expect(buildStatRows({ ...base, playable: "" }).find((r) => r.key === "mode")?.value).toBe(DASH);
expect(buildStatRows({ ...base, playable: "" }).find((r) => r.key === "mode")?.value).toBe(
DASH,
);
});
});
+10 -2
View File
@@ -109,7 +109,11 @@ export function buildStatRows(s: PlexStatsInput): StatRow[] {
const rows: StatRow[] = [
{ key: "mode", labelKey: "plex.player.stats.mode", value: fmtMode(s.playable, s.hwEncoder) },
{ key: "transport", labelKey: "plex.player.stats.transport", value: s.transport },
{ key: "res", labelKey: "plex.player.stats.resolution", value: fmtRes(s.videoWidth, s.videoHeight) },
{
key: "res",
labelKey: "plex.player.stats.resolution",
value: fmtRes(s.videoWidth, s.videoHeight),
},
];
if (s.transport === "hls") {
rows.push(
@@ -118,7 +122,11 @@ export function buildStatRows(s: PlexStatsInput): StatRow[] {
labelKey: "plex.player.stats.codec",
value: fmtCodec(s.hlsLevel?.videoCodec, s.hlsLevel?.audioCodec),
},
{ key: "bitrate", labelKey: "plex.player.stats.bitrate", value: fmtBitrate(s.hlsLevel?.bitrate) },
{
key: "bitrate",
labelKey: "plex.player.stats.bitrate",
value: fmtBitrate(s.hlsLevel?.bitrate),
},
{ key: "level", labelKey: "plex.player.stats.level", value: fmtLevel(s.hlsLevel) },
);
}