diff --git a/src/components/appBar/appBar.tsx b/src/components/appBar/appBar.tsx index 76534c8..53ce626 100644 --- a/src/components/appBar/appBar.tsx +++ b/src/components/appBar/appBar.tsx @@ -29,6 +29,7 @@ const HIDDEN_PATHS = [ "/settings", "/library", "/search", + "/remote", // The home page draws its own header inside the hero frame. "/home", ]; @@ -36,9 +37,7 @@ const HIDDEN_PATHS = [ /** Whether the global app header is drawn for this route. */ export const shouldShowAppBar = (pathname: string) => !HIDDEN_PATHS.some( - (path) => - (pathname.startsWith(path) && pathname !== "/player/audio") || - pathname === "/", + (path) => pathname.startsWith(path) || pathname === "/", ); const AppBarContent = () => { @@ -146,6 +145,14 @@ const AppBarContent = () => { search + + navigate({ to: "/remote" })} + aria-label="Пульт" + > + settings_remote + + { primary="Поиск" onClick={onClose} /> + ApiRoute, } as any) +const ApiRemoteRoute = ApiRemoteRouteImport.update({ + id: '/remote', + path: '/remote', + getParentRoute: () => ApiRoute, +} as any) const ApiSettingsRoute = ApiSettingsRouteImport.update({ id: '/settings', path: '/settings', @@ -164,6 +170,7 @@ const ApiSettingsChangeServerIndexRoute = export interface FileRoutesByFullPath { '/': typeof IndexRoute '/login': typeof ApiLoginRouteWithChildren + '/remote': typeof ApiRemoteRoute '/settings': typeof ApiSettingsRouteWithChildren '/error/$code': typeof ErrorCodeRoute '/item/$id': typeof ApiItemIdRoute @@ -190,6 +197,7 @@ export interface FileRoutesByFullPath { export interface FileRoutesByTo { '/': typeof IndexRoute '/login': typeof ApiLoginRouteWithChildren + '/remote': typeof ApiRemoteRoute '/settings': typeof ApiSettingsRouteWithChildren '/error/$code': typeof ErrorCodeRoute '/item/$id': typeof ApiItemIdRoute @@ -218,6 +226,7 @@ export interface FileRoutesById { '/': typeof IndexRoute '/_api': typeof ApiRouteWithChildren '/_api/login': typeof ApiLoginRouteWithChildren + '/_api/remote': typeof ApiRemoteRoute '/_api/settings': typeof ApiSettingsRouteWithChildren '/error/$code': typeof ErrorCodeRoute '/_api/item/$id': typeof ApiItemIdRoute @@ -246,6 +255,7 @@ export interface FileRouteTypes { fullPaths: | '/' | '/login' + | '/remote' | '/settings' | '/error/$code' | '/item/$id' @@ -272,6 +282,7 @@ export interface FileRouteTypes { to: | '/' | '/login' + | '/remote' | '/settings' | '/error/$code' | '/item/$id' @@ -299,6 +310,7 @@ export interface FileRouteTypes { | '/' | '/_api' | '/_api/login' + | '/_api/remote' | '/_api/settings' | '/error/$code' | '/_api/item/$id' @@ -355,6 +367,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof ApiLoginRouteImport parentRoute: typeof ApiRoute } + '/_api/remote': { + id: '/_api/remote' + path: '/remote' + fullPath: '/remote' + preLoaderRoute: typeof ApiRemoteRouteImport + parentRoute: typeof ApiRoute + } '/_api/settings': { id: '/_api/settings' path: '/settings' @@ -546,6 +565,7 @@ const ApiSettingsRouteWithChildren = ApiSettingsRoute._addFileChildren( interface ApiRouteChildren { ApiLoginRoute: typeof ApiLoginRouteWithChildren + ApiRemoteRoute: typeof ApiRemoteRoute ApiSettingsRoute: typeof ApiSettingsRouteWithChildren ApiItemIdRoute: typeof ApiItemIdRoute ApiLibraryIdRoute: typeof ApiLibraryIdRoute @@ -562,6 +582,7 @@ interface ApiRouteChildren { const ApiRouteChildren: ApiRouteChildren = { ApiLoginRoute: ApiLoginRouteWithChildren, + ApiRemoteRoute: ApiRemoteRoute, ApiSettingsRoute: ApiSettingsRouteWithChildren, ApiItemIdRoute: ApiItemIdRoute, ApiLibraryIdRoute: ApiLibraryIdRoute, diff --git a/src/routes/_api/remote.scss b/src/routes/_api/remote.scss new file mode 100644 index 0000000..32f227b --- /dev/null +++ b/src/routes/_api/remote.scss @@ -0,0 +1,640 @@ +/** + * Remote control for another Jellyfin client. + * Layout follows the reference player: brand bar, poster + details + round + * transport, a full-width timeline, and a service bar with subtitles, volume, + * quality and fullscreen. + */ +.remote-page { + --remote-accent: #{$clr-accent-default}; + --remote-panel: #16191f; + --remote-chip: #1b1e25; + --remote-muted: #a9b0bb; + + position: fixed; + inset: 0; + display: flex; + flex-direction: column; + overflow: hidden; + color: #fff; + background: linear-gradient( + 180deg, + var(--remote-base, #1b0f2e), + var(--remote-deep, #08001f) + ); + font-family: "Plus Jakarta Sans Variable", "Segoe UI", "Inter", Arial, + sans-serif; +} + +/* ------------------------------------------------------------------ top */ + +.remote-topbar { + display: flex; + flex: 0 0 auto; + align-items: center; + justify-content: space-between; + gap: 24px; + height: 88px; + padding: 0 32px; + box-sizing: border-box; + + &-left, + &-right { + display: flex; + align-items: center; + gap: 14px; + min-width: 0; + } + + .MuiIconButton-root { + color: #dfe3ea; + + &:hover { + color: #fff; + background: rgb(255 255 255 / 0.08); + } + + .material-symbols-rounded { + font-size: 1.5rem; + } + } + + &-divider { + width: 1px; + height: 26px; + background: rgb(255 255 255 / 0.12); + } +} + +.remote-brand { + display: flex; + align-items: center; + gap: 10px; + + &-mark { + display: grid; + place-items: center; + width: 38px; + height: 38px; + border-radius: 50%; + background: linear-gradient( + 135deg, + $clr-accent-default, + $clr-secondary-default + ); + color: #fff; + + .material-symbols-rounded { + font-size: 1.3rem; + } + } + + &-name { + font-size: 1.35rem; + font-weight: 600; + letter-spacing: -0.01em; + } +} + +.remote-device-chip { + display: inline-flex; + align-items: center; + gap: 8px; + padding: 8px 12px 8px 14px; + border: 0; + border-radius: 999px; + background: var(--remote-panel); + color: #e8ebf1; + font: inherit; + font-size: 0.88rem; + cursor: pointer; + transition: background-color 0.15s ease; + + &:hover { + background: #1d2028; + } + + > .material-symbols-rounded { + font-size: 1.2rem; + } +} + +.remote-chevron { + opacity: 0.6; + font-size: 1.15rem !important; +} + +/* ---------------------------------------------------------------- hero */ + +.remote-body { + display: flex; + flex: 1 1 auto; + min-height: 0; +} + +.remote-devices { + display: flex; + flex: 0 0 clamp(220px, 19vw, 280px); + flex-direction: column; + min-height: 0; + padding: clamp(0.5rem, 3vh, 2rem) 0 0 clamp(1.5rem, 4vw, 3.5rem); + box-sizing: border-box; + overflow: hidden; +} + +.remote-devices-title { + margin: 0 0 0.5em 0.6em; + font-size: 0.72rem; + font-weight: 500; + letter-spacing: 0.2em; + text-transform: uppercase; + color: rgb(255 255 255 / 0.5); +} + +.remote-device-list { + display: flex; + flex-direction: column; + gap: 0.25em; + margin: 0; + padding: 0; + overflow-y: auto; + list-style: none; +} + +.remote-device { + display: flex; + align-items: center; + gap: 0.75em; + width: 100%; + padding: 0.6em 0.7em; + border: 0; + border-radius: 10px; + background: transparent; + color: rgb(255 255 255 / 0.75); + font: inherit; + text-align: left; + cursor: pointer; + transition: background-color 0.15s ease, color 0.15s ease; + + &:hover { + background: rgb(255 255 255 / 0.06); + } + + &.is-active { + background: rgb(255 255 255 / 0.1); + color: #fff; + } + + &-icon { + font-size: 1.3rem; + opacity: 0.8; + } + + &-info { + display: flex; + flex-direction: column; + min-width: 0; + } + + &-name { + font-size: 0.9rem; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + + &-meta { + font-size: 0.72rem; + color: rgb(255 255 255 / 0.5); + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + + &-dot { + flex: 0 0 auto; + width: 6px; + height: 6px; + margin-left: auto; + border-radius: 50%; + background: $clr-accent-default; + + &.is-paused { + background: rgb(255 255 255 / 0.35); + } + } +} + +.remote-hero { + display: flex; + flex: 1 1 auto; + align-items: center; + gap: clamp(2rem, 4vw, 4rem); + min-width: 0; + min-height: 0; + margin: 0 auto; + padding: clamp(0.5rem, 3vh, 2.5rem) clamp(1.5rem, 4vw, 3.5rem) 0; + box-sizing: border-box; + overflow: hidden; +} + +.remote-poster { + position: relative; + flex: 0 0 auto; + height: 100%; + max-height: 560px; + width: auto; + max-width: 340px; + aspect-ratio: 2 / 3; + + &-frame { + position: relative; + z-index: 1; + display: grid; + place-items: center; + width: 100%; + height: 100%; + overflow: hidden; + border-radius: 8px; + background: var(--remote-panel); + box-shadow: 0 24px 60px rgb(0 0 0 / 0.45); + + img { + display: block; + width: 100%; + height: 100%; + object-fit: cover; + } + + > .material-symbols-rounded { + font-size: 4rem; + color: rgb(255 255 255 / 0.3); + } + } +} + +.remote-details { + flex: 1 1 auto; + min-width: 0; + max-width: 820px; + padding-top: clamp(0.5rem, 4vh, 3rem); +} + +.remote-title { + margin: 0; + font-size: clamp(1.9rem, 3vw, 3rem); + font-weight: 700; + line-height: 1.1; + letter-spacing: -0.02em; + overflow-wrap: anywhere; +} + +.remote-subtitle { + margin: 0.55em 0 0; + font-size: clamp(1.1rem, 1.6vw, 1.55rem); + font-weight: 500; + line-height: 1.3; + color: #d3d8e0; + overflow-wrap: anywhere; +} + +.remote-chips { + display: flex; + flex-wrap: wrap; + gap: 10px; + margin-top: clamp(1.2rem, 3vh, 2rem); +} + +.remote-chip { + padding: 7px 15px; + border-radius: 999px; + background: var(--remote-chip); + font-size: 0.95rem; + color: #dfe3ea; +} + +.remote-overview { + display: -webkit-box; + -webkit-line-clamp: 4; + -webkit-box-orient: vertical; + overflow: hidden; + max-width: 660px; + margin: clamp(1rem, 3vh, 1.8rem) 0 0; + font-size: 1rem; + line-height: 1.6; + color: var(--remote-muted); +} + +.remote-transport { + display: flex; + align-items: center; + gap: clamp(1rem, 2.4vw, 2rem); + margin-top: clamp(2rem, 6vh, 3.5rem); +} + +.remote-round { + display: grid; + place-items: center; + width: clamp(64px, 6vw, 86px); + height: clamp(64px, 6vw, 86px); + padding: 0; + border: 0; + border-radius: 50%; + background: var(--remote-panel); + color: #fff; + cursor: pointer; + transition: background-color 0.15s ease, transform 0.15s ease; + + .material-symbols-rounded { + font-size: clamp(1.5rem, 2vw, 2rem); + } + + &:hover:not(:disabled) { + background: #1e222b; + transform: scale(1.03); + } + + &:disabled { + opacity: 0.4; + cursor: default; + } + + &.remote-round-primary { + width: clamp(74px, 7vw, 98px); + height: clamp(74px, 7vw, 98px); + background: var(--remote-accent); + box-shadow: 0 10px 24px rgb(0 0 0 / 0.3); + + .material-symbols-rounded { + font-size: clamp(1.9rem, 2.6vw, 2.6rem); + } + + &:hover:not(:disabled) { + background: #8b70ff; + transform: scale(1.04); + } + } +} + +/* ------------------------------------------------------------ timeline */ + +.remote-timeline { + display: flex; + flex: 0 0 auto; + align-items: center; + gap: 22px; + padding: clamp(0.5rem, 1.5vh, 1rem) clamp(1.5rem, 4vw, 3.5rem) 0; + box-sizing: border-box; + + .MuiSlider-root { + padding: 12px 0; + color: var(--remote-accent); + } + + .MuiSlider-rail { + background: rgb(255 255 255 / 0.18); + opacity: 1; + } + + .MuiSlider-thumb { + width: 16px; + height: 16px; + background: #fff; + box-shadow: 0 0 0 4px rgb(255 255 255 / 0.14); + + &:hover, + &.Mui-focusVisible { + box-shadow: 0 0 0 8px rgb(255 255 255 / 0.14); + } + } +} + +.remote-timeline-slider { + flex: 1 1 auto; +} + +.remote-time { + flex: 0 0 auto; + min-width: 4.5em; + font-size: 1.05rem; + font-variant-numeric: tabular-nums; + color: #e8ebf1; + + &:last-child { + text-align: right; + } +} + +/* ---------------------------------------------------------- bottom bar */ + +.remote-bottombar { + display: flex; + flex: 0 0 auto; + align-items: center; + justify-content: space-between; + gap: 24px; + height: 72px; + padding: 0 clamp(1.5rem, 4vw, 3rem); + box-sizing: border-box; + background: rgb(0 0 0 / 0.22); + border-top: 1px solid rgb(255 255 255 / 0.06); +} + +.remote-bottom-item { + display: inline-flex; + align-items: center; + gap: 10px; + min-width: 0; + padding: 8px 0; + border: 0; + background: transparent; + color: #dfe3ea; + font: inherit; + font-size: 0.9rem; + cursor: pointer; + transition: color 0.15s ease; + + > .material-symbols-rounded { + font-size: 1.3rem; + } + + &:hover:not(:disabled) { + color: #fff; + } + + &:disabled { + opacity: 0.2; + cursor: default; + } + + > span:nth-child(2) { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } +} + +.remote-bottom-volume { + flex: 0 1 320px; + gap: 8px; + + .MuiIconButton-root { + color: #dfe3ea; + + &:hover { + color: #fff; + background: rgb(255 255 255 / 0.06); + } + } + + .MuiSlider-root { + color: var(--remote-accent); + } + + .MuiSlider-rail { + background: rgb(255 255 255 / 0.18); + opacity: 1; + } + + .MuiSlider-thumb { + width: 14px; + height: 14px; + background: #fff; + box-shadow: none; + } +} + +/* --------------------------------------------------------------- empty */ + +.remote-empty { + display: flex; + flex: 1 1 auto; + flex-direction: column; + align-items: center; + justify-content: center; + gap: 0.6em; + padding: 0 24px; + text-align: center; + + > .material-symbols-rounded { + font-size: 3.5rem; + opacity: 0.4; + } + + h1 { + margin: 0; + font-size: 1.7rem; + } + + p { + max-width: 46ch; + margin: 0; + font-size: 0.95rem; + line-height: 1.6; + color: var(--remote-muted); + } +} + +/* ------------------------------------------------------------ adapt */ + +@media (max-height: 780px) { + .remote-topbar { + height: 72px; + } + + .remote-title { + font-size: clamp(1.6rem, 2.6vw, 2.3rem); + } + + .remote-subtitle { + font-size: clamp(1rem, 1.3vw, 1.2rem); + } + + .remote-chips { + margin-top: 1rem; + } + + .remote-overview { + display: none; + } + + .remote-transport { + margin-top: 1.4rem; + } + + .remote-round { + width: 64px; + height: 64px; + } + + .remote-round.remote-round-primary { + width: 78px; + height: 78px; + } + + .remote-bottombar { + height: 64px; + } +} + +@media (max-width: 1100px) { + .remote-hero { + gap: 2.5rem; + } + + .remote-poster { + width: clamp(200px, 30vw, 280px); + } + + .remote-bottombar { + height: 90px; + gap: 16px; + } + + .remote-bottom-item > span:nth-child(2) { + font-size: 0.9rem; + } +} + +@media (max-width: 820px) { + .remote-topbar { + height: 72px; + padding: 0 16px; + } + + .remote-hero { + flex-direction: column; + align-items: center; + overflow-y: auto; + } + + .remote-details { + width: 100%; + text-align: center; + } + + .remote-transport { + justify-content: center; + } + + .remote-chips { + justify-content: center; + } + + .remote-overview { + margin-left: auto; + margin-right: auto; + } + + .remote-bottombar { + justify-content: center; + flex-wrap: wrap; + height: auto; + padding: 12px 16px; + } + + .remote-bottom-volume { + flex-basis: 200px; + } +} + + diff --git a/src/routes/_api/remote.tsx b/src/routes/_api/remote.tsx new file mode 100644 index 0000000..14597ae --- /dev/null +++ b/src/routes/_api/remote.tsx @@ -0,0 +1,611 @@ +import { + GeneralCommandType, + PlaystateCommand, + type SessionInfoDto, +} from "@jellyfin/sdk/lib/generated-client"; +import { getSessionApi } from "@jellyfin/sdk/lib/utils/api/session-api"; +import IconButton from "@mui/material/IconButton"; +import Menu from "@mui/material/Menu"; +import MenuItem from "@mui/material/MenuItem"; +import Slider from "@mui/material/Slider"; +import Tooltip from "@mui/material/Tooltip"; +import { useQuery } from "@tanstack/react-query"; +import { createFileRoute, useNavigate } from "@tanstack/react-router"; +import React, { useEffect, useMemo, useRef, useState } from "react"; +import { UserAvatarMenu } from "@/components/userAvatarMenu"; +import WindowControls from "@/components/windowControls"; +import { getRuntimeCompact } from "@/utils/date/time"; +import { getCoverPalette } from "@/utils/methods/coverColor"; +import getImageUrlsApi from "@/utils/methods/getImageUrlsApi"; +import { useApiInContext } from "@/utils/store/api"; +import { useCentralStore } from "@/utils/store/central"; +import useSearchStore from "@/utils/store/search"; + +import "./remote.scss"; + +export const Route = createFileRoute("/_api/remote")({ + component: RemotePage, +}); + +const TICKS_PER_SECOND = 10_000_000; + +const formatTime = (ticks: number | null | undefined) => { + const total = Math.max(0, Math.round((ticks ?? 0) / TICKS_PER_SECOND)); + const h = Math.floor(total / 3600); + const m = Math.floor((total % 3600) / 60); + const s = total % 60; + return h > 0 + ? `${h}:${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")}` + : `${m}:${String(s).padStart(2, "0")}`; +}; + +const sessionLabel = (session: SessionInfoDto) => + session.DeviceName || + session.Client || + session.DeviceId || + "Неизвестное устройство"; + +const channelLabel = (channels?: number | null) => { + if (!channels) return null; + if (channels === 1) return "Mono"; + if (channels === 2) return "Stereo"; + if (channels === 6) return "5.1"; + if (channels === 8) return "7.1"; + return `${channels} ch`; +}; + +const sessionKind = (session: SessionInfoDto) => { + const type = session.NowPlayingItem?.Type; + if (type === "TvChannel") return "tv"; + if (type === "Audio" || type === "MusicAlbum") return "speaker"; + if (type) return "tv"; + return session.Client?.toLowerCase().includes("web") ? "computer" : "tv"; +}; + +function RemotePage() { + const api = useApiInContext((s) => s.api); + const user = useCentralStore((s) => s.currentUser); + const navigate = useNavigate(); + const toggleSearchDialog = useSearchStore((s) => s.toggleSearchDialog); + + const [selectedId, setSelectedId] = useState(null); + const [subtitleAnchor, setSubtitleAnchor] = useState( + null, + ); + const [qualityAnchor, setQualityAnchor] = useState(null); + const [subtitleIndex, setSubtitleIndex] = useState(-1); + const [volumeDraft, setVolumeDraft] = useState(null); + const volumeTimerRef = useRef | null>(null); + + const clearVolumeTimer = () => { + if (volumeTimerRef.current) { + clearTimeout(volumeTimerRef.current); + volumeTimerRef.current = null; + } + }; + + useEffect(() => clearVolumeTimer, []); + + const sessions = useQuery({ + queryKey: ["remoteSessions"], + queryFn: async () => { + if (!api || !user?.Id) return []; + const result = await getSessionApi(api).getSessions(); + return result.data; + }, + enabled: !!api && !!user?.Id, + refetchInterval: () => { + if (document.visibilityState !== "visible") return false; + return 2500; + }, + refetchIntervalInBackground: false, + networkMode: "always", + }); + + const remoteSessions = (sessions.data ?? []).filter( + (session) => + session.Id && + session.DeviceId !== api?.deviceInfo.id && + session.UserId === user?.Id, + ); + + const playing = remoteSessions.find((session) => session.NowPlayingItem); + const selected = + remoteSessions.find((session) => session.Id === selectedId) ?? + playing ?? + remoteSessions[0]; + + useEffect(() => { + setVolumeDraft(null); + setSubtitleIndex(-1); + clearVolumeTimer(); + }, [selected?.Id]); + + // Keep the picked volume until the target reports it back (progress updates + // can lag), then drop the optimistic value. + useEffect(() => { + if (volumeDraft == null) return; + const server = selected?.PlayState?.VolumeLevel; + if (server != null && Math.abs(server / 100 - volumeDraft) <= 0.02) { + setVolumeDraft(null); + clearVolumeTimer(); + } + }, [selected?.PlayState?.VolumeLevel, volumeDraft]); + + const command = async ( + session: SessionInfoDto, + name: PlaystateCommand, + seekPositionTicks?: number, + ) => { + if (!api || !session.Id) return; + try { + await getSessionApi(api).sendPlaystateCommand({ + sessionId: session.Id, + command: name, + seekPositionTicks, + controllingUserId: user?.Id, + }); + await sessions.refetch(); + } catch (error) { + console.error("Remote command failed", error); + } + }; + + const general = async ( + session: SessionInfoDto, + name: GeneralCommandType, + args?: Record, + ) => { + if (!api || !session.Id) return; + try { + await getSessionApi(api).sendFullGeneralCommand({ + sessionId: session.Id, + generalCommand: { + Name: name, + Arguments: args, + ControllingUserId: user?.Id, + }, + }); + await sessions.refetch(); + } catch (error) { + console.error("Remote general command failed", error); + } + }; + + const nowPlaying = selected?.NowPlayingItem; + const playState = selected?.PlayState; + const isPaused = playState?.IsPaused ?? true; + const duration = nowPlaying?.RunTimeTicks ?? 0; + const position = playState?.PositionTicks ?? 0; + const volume = volumeDraft ?? (playState?.VolumeLevel ?? 100) / 100; + const isMuted = playState?.IsMuted ?? false; + + const coverUrl = useMemo(() => { + if (!api || !nowPlaying) return undefined; + const imageItemId = nowPlaying.AlbumId ?? nowPlaying.Id; + if (!imageItemId) return undefined; + return getImageUrlsApi(api).getItemImageUrlById(imageItemId, "Primary", { + quality: 90, + fillHeight: 720, + fillWidth: 480, + }); + }, [api, nowPlaying?.AlbumId, nowPlaying?.Id]); + + const palette = useMemo(() => getCoverPalette(nowPlaying), [nowPlaying?.Id]); + + const isEpisode = nowPlaying?.Type === "Episode"; + const title = isEpisode + ? (nowPlaying?.SeriesName ?? nowPlaying?.Name) + : nowPlaying?.Name; + const subtitle = isEpisode + ? `Сезон ${nowPlaying?.ParentIndexNumber ?? 1}, Серия ${ + nowPlaying?.IndexNumber ?? 1 + } — «${nowPlaying?.Name}»` + : [ + nowPlaying?.AlbumArtist ?? nowPlaying?.Artists?.join(", "), + nowPlaying?.Album, + ] + .filter(Boolean) + .join(" · "); + + const videoStream = nowPlaying?.MediaStreams?.find( + (stream) => stream.Type === "Video", + ); + const audioStream = nowPlaying?.MediaStreams?.find( + (stream) => stream.Type === "Audio", + ); + const subtitleStreams = + nowPlaying?.MediaStreams?.filter((stream) => stream.Type === "Subtitle") ?? + []; + + const chips = [ + nowPlaying?.OfficialRating, + nowPlaying?.ProductionYear, + nowPlaying?.RunTimeTicks + ? getRuntimeCompact(nowPlaying.RunTimeTicks) + : null, + videoStream?.Height ? `${videoStream.Height}p` : null, + channelLabel(audioStream?.Channels), + ].filter(Boolean) as string[]; + + const qualityLabel = videoStream?.Height + ? `${videoStream.Height}p` + : (nowPlaying?.MediaSources?.[0]?.Name ?? "Авто"); + const subtitleLabel = + subtitleIndex < 0 + ? "Выкл." + : (subtitleStreams.find((s) => s.Index === subtitleIndex)?.DisplayTitle ?? + `Дорожка ${subtitleIndex}`); + + const toggleMute = () => { + if (!selected) return; + void general( + selected, + isMuted ? GeneralCommandType.Unmute : GeneralCommandType.Mute, + ); + }; + + const chooseSubtitle = (index: number) => { + if (!selected) return; + setSubtitleIndex(index); + setSubtitleAnchor(null); + void general(selected, GeneralCommandType.SetSubtitleStreamIndex, { + Index: String(index), + }); + }; + + const transport = (name: PlaystateCommand) => { + if (!selected) return; + void command(selected, name); + }; + + return ( +
+
+
+
+ + settings_remote + + Пульт +
+ + navigate({ to: "/home" })} + > + home + +
+ +
+ + search + + + navigate({ to: "/settings/preferences" })} + > + settings + + + +
+
+ + {!selected ? ( +
+ settings_remote +

Нет доступных устройств

+

+ Откройте клиент Jellyfin (телевизор, браузер, телефон) под этой + учётной записью, и он появится здесь. +

+
+ ) : ( + <> +
+ + +
+
+
+ {coverUrl ? ( + {title + ) : ( + live_tv + )} +
+
+ +
+

+ {title ?? sessionLabel(selected)} +

+ {subtitle &&

{subtitle}

} + + {chips.length > 0 && ( +
+ {chips.map((chip) => ( + + {chip} + + ))} +
+ )} + + {nowPlaying?.Overview && ( +

{nowPlaying.Overview}

+ )} + {!nowPlaying && ( +

+ Устройство свободно. Запустите воспроизведение на нём, и + здесь появятся название, постер и управление. +

+ )} + +
+ + + + + + + + + + + + + +
+
+
+
+ +
+ {formatTime(position)} + { + const next = Array.isArray(value) ? value[0] : value; + if (selected) { + void command( + selected, + PlaystateCommand.Seek, + Math.round(next), + ); + } + }} + /> + {formatTime(duration)} +
+ +
+ + +
+ + + {isMuted || volume === 0 ? "volume_off" : "volume_up"} + + + { + setVolumeDraft(Array.isArray(value) ? value[0] : value); + }} + onChangeCommitted={(_, value) => { + const next = Array.isArray(value) ? value[0] : value; + setVolumeDraft(next); + clearVolumeTimer(); + volumeTimerRef.current = setTimeout(() => { + setVolumeDraft(null); + }, 12000); + if (isMuted) { + void general(selected, GeneralCommandType.Unmute); + } + void general(selected, GeneralCommandType.SetVolume, { + Volume: String(Math.round(next * 100)), + }); + }} + /> +
+ + + + +
+ + setSubtitleAnchor(null)} + > + chooseSubtitle(-1)} + > + Выключены + + {subtitleStreams.map((stream) => ( + chooseSubtitle(stream.Index ?? -1)} + > + {stream.DisplayTitle ?? stream.Language ?? "Дорожка"} + + ))} + + + setQualityAnchor(null)} + > + Качество выбирает сам клиент + {nowPlaying?.MediaSources?.map((source) => ( + + {source.Name ?? "Источник"} + + ))} + + + )} +
+ ); +}