feat: Spotify-style transfer between devices
Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
- persistent remote playback bar when another session is playing (device, title, play/pause, Transfer here) - transfer remote -> local for audio and video, preserving position and queue, then stop the remote session - cast from local players now sends the queue, start index and position, and stops local playback after the transfer - full-screen player and remote dialog share the transfer payload
This commit is contained in:
1 parent
a98663691d
commit
fa29331c1c
12 files changed
+421
-21
No files matched your search
@@ -2,21 +2,36 @@ import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import Tooltip from "@mui/material/Tooltip";
|
||||
import React from "react";
|
||||
import useRemoteControlStore from "@/utils/store/remoteControl";
|
||||
import useRemoteControlStore, {
|
||||
type RemoteTransfer,
|
||||
} from "@/utils/store/remoteControl";
|
||||
|
||||
type CastButtonProps = {
|
||||
item?: BaseItemDto | null;
|
||||
transfer?: Omit<RemoteTransfer, "item">;
|
||||
/** Computed on click so playback position/queue are current. */
|
||||
getTransfer?: () => Omit<RemoteTransfer, "item">;
|
||||
size?: "small" | "medium" | "large";
|
||||
};
|
||||
|
||||
const CastButton = ({ item, size = "medium" }: CastButtonProps) => {
|
||||
const CastButton = ({
|
||||
item,
|
||||
transfer,
|
||||
getTransfer,
|
||||
size = "medium",
|
||||
}: CastButtonProps) => {
|
||||
const openDialog = useRemoteControlStore((s) => s.openDialog);
|
||||
return (
|
||||
<Tooltip title={item ? "Play on another device" : "Remote control"}>
|
||||
<IconButton
|
||||
size={size}
|
||||
aria-label={item ? "Play on another device" : "Remote control"}
|
||||
onClick={() => openDialog(item ?? null)}
|
||||
onClick={() =>
|
||||
openDialog({
|
||||
...(getTransfer ? getTransfer() : transfer),
|
||||
item: item ?? null,
|
||||
})
|
||||
}
|
||||
>
|
||||
<span className="material-symbols-rounded">cast</span>
|
||||
</IconButton>
|
||||
|
||||
@@ -12,15 +12,34 @@ interface PlayerActionsProps {
|
||||
onClose: () => void;
|
||||
/** The track currently playing (for cast / instant mix). */
|
||||
item?: BaseItemDto | null;
|
||||
positionTicks?: number;
|
||||
queue?: BaseItemDto[];
|
||||
startIndex?: number;
|
||||
/** Volume control, rendered between the queue and expand buttons. */
|
||||
children?: ReactNode;
|
||||
}
|
||||
|
||||
const PlayerActions = ({ onExpand, onClose, item, children }: PlayerActionsProps) => {
|
||||
const PlayerActions = ({
|
||||
onExpand,
|
||||
onClose,
|
||||
item,
|
||||
positionTicks = 0,
|
||||
queue = [],
|
||||
startIndex = 0,
|
||||
children,
|
||||
}: PlayerActionsProps) => {
|
||||
return (
|
||||
<div className="audio-player-actions">
|
||||
{item && <InstantMixButton item={item} />}
|
||||
{item && <CastButton item={item} />}
|
||||
{item && <CastButton
|
||||
item={item}
|
||||
transfer={{
|
||||
kind: "audio",
|
||||
positionTicks,
|
||||
queue,
|
||||
startIndex,
|
||||
}}
|
||||
/>}
|
||||
<QueueButton />
|
||||
<div className="audio-player-volume">{children}</div>
|
||||
<Tooltip title="Open player">
|
||||
|
||||
@@ -245,7 +245,14 @@ const AudioPlayer = () => {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<PlayerActions onExpand={handleNavigate} onClose={handleClose} item={item}>
|
||||
<PlayerActions
|
||||
onExpand={handleNavigate}
|
||||
onClose={handleClose}
|
||||
item={item}
|
||||
positionTicks={secToTicks(progress)}
|
||||
queue={tracks ?? []}
|
||||
startIndex={currentTrack}
|
||||
>
|
||||
<PlayerVolume
|
||||
volume={volume}
|
||||
isMuted={isMuted}
|
||||
|
||||
@@ -31,6 +31,7 @@ import VideoPlayerSettingsMenu from "./settingsMenu";
|
||||
|
||||
import "./controls.scss";
|
||||
import { clearQueue } from "@/utils/store/queue";
|
||||
import useQueue from "@/utils/store/queue";
|
||||
import ProgressDisplay from "./ProgressDisplay";
|
||||
|
||||
/**
|
||||
@@ -307,7 +308,17 @@ const VideoPlayerControls = ({
|
||||
: "volume_up"}
|
||||
</span>
|
||||
</IconButton>
|
||||
<CastButton item={item} />
|
||||
<CastButton
|
||||
item={item}
|
||||
getTransfer={() => ({
|
||||
kind: "video",
|
||||
positionTicks: secToTicks(
|
||||
usePlaybackStore.getState().getCurrentTime(),
|
||||
),
|
||||
queue: useQueue.getState().tracks ?? [],
|
||||
startIndex: useQueue.getState().currentItemIndex,
|
||||
})}
|
||||
/>
|
||||
<QueueButton />
|
||||
|
||||
<ChaptersListButton />
|
||||
|
||||
@@ -20,10 +20,14 @@ import {
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import { useSnackbar } from "notistack";
|
||||
import React from "react";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { stopPlayback } from "@/utils/store/audioPlayback";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
import { usePlaybackStore } from "@/utils/store/playback";
|
||||
import { clearQueue } from "@/utils/store/queue";
|
||||
import useRemoteControlStore from "@/utils/store/remoteControl";
|
||||
|
||||
const TICKS_PER_SECOND = 10_000_000;
|
||||
@@ -42,10 +46,12 @@ const sessionLabel = (session: SessionInfoDto) =>
|
||||
session.DeviceName || session.Client || session.DeviceId || "Unknown device";
|
||||
|
||||
const RemoteControlDialog = () => {
|
||||
const { open, item, closeDialog } = useRemoteControlStore();
|
||||
const { open, transfer, closeDialog } = useRemoteControlStore();
|
||||
const item = transfer?.item;
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const user = useCentralStore((s) => s.currentUser);
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const sessions = useQuery({
|
||||
queryKey: ["remoteSessions"],
|
||||
@@ -87,18 +93,33 @@ const RemoteControlDialog = () => {
|
||||
const playOn = useMutation({
|
||||
mutationFn: async (session: SessionInfoDto) => {
|
||||
if (!api || !session.Id || !item?.Id) return;
|
||||
const queueIds =
|
||||
transfer?.queue
|
||||
?.map((queueItem) => queueItem.Id)
|
||||
.filter((id): id is string => Boolean(id)) ?? [];
|
||||
await getSessionApi(api).play({
|
||||
sessionId: session.Id,
|
||||
playCommand: PlayCommand.PlayNow,
|
||||
itemIds: [item.Id],
|
||||
startPositionTicks: 0,
|
||||
itemIds: queueIds.length > 0 ? queueIds : [item.Id],
|
||||
startIndex: transfer?.startIndex ?? 0,
|
||||
startPositionTicks: transfer?.positionTicks ?? 0,
|
||||
mediaSourceId: item.MediaSources?.[0]?.Id ?? undefined,
|
||||
});
|
||||
},
|
||||
onSuccess: (_data, session) => {
|
||||
enqueueSnackbar(`Playing on ${sessionLabel(session)}`, {
|
||||
variant: "success",
|
||||
});
|
||||
enqueueSnackbar(
|
||||
transfer?.kind === "audio" || transfer?.kind === "video"
|
||||
? `Playback transferred to ${sessionLabel(session)}`
|
||||
: `Playing on ${sessionLabel(session)}`,
|
||||
{ variant: "success" },
|
||||
);
|
||||
if (transfer?.kind === "audio") {
|
||||
stopPlayback();
|
||||
} else if (transfer?.kind === "video") {
|
||||
usePlaybackStore.setState(usePlaybackStore.getInitialState());
|
||||
clearQueue();
|
||||
navigate({ to: "/home" });
|
||||
}
|
||||
closeDialog();
|
||||
},
|
||||
onError: () =>
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
import { PlaystateCommand, type SessionInfoDto } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getSessionApi } from "@jellyfin/sdk/lib/utils/api/session-api";
|
||||
import { Button, IconButton, Tooltip, Typography } from "@mui/material";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { useLocation, useNavigate } from "@tanstack/react-router";
|
||||
import { useSnackbar } from "notistack";
|
||||
import React from "react";
|
||||
import { transferSessionToLocal } from "@/utils/methods/transferPlayback";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useAudioPlayback } from "@/utils/store/audioPlayback";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
import useRemoteControlStore from "@/utils/store/remoteControl";
|
||||
|
||||
import "./remotePlaybackBar.scss";
|
||||
|
||||
const RemotePlaybackBar = () => {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const user = useCentralStore((s) => s.currentUser);
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
const openDialog = useRemoteControlStore((s) => s.openDialog);
|
||||
const audioDisplay = useAudioPlayback((s) => s.display);
|
||||
|
||||
const sessions = useQuery({
|
||||
queryKey: ["remoteSessions"],
|
||||
queryFn: async () => {
|
||||
if (!api || !user?.Id) return [];
|
||||
const result = await getSessionApi(api).getSessions({
|
||||
controllableByUserId: user.Id,
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
enabled: !!api && !!user?.Id,
|
||||
refetchInterval: 5000,
|
||||
networkMode: "always",
|
||||
});
|
||||
|
||||
const remote = (sessions.data ?? []).find(
|
||||
(session: SessionInfoDto) =>
|
||||
session.Id &&
|
||||
session.DeviceId !== api?.deviceInfo.id &&
|
||||
session.NowPlayingItem,
|
||||
);
|
||||
|
||||
const command = useMutation({
|
||||
mutationFn: async ({
|
||||
session,
|
||||
command,
|
||||
}: {
|
||||
session: SessionInfoDto;
|
||||
command: PlaystateCommand;
|
||||
}) => {
|
||||
if (!api || !session.Id) return;
|
||||
await getSessionApi(api).sendPlaystateCommand({
|
||||
sessionId: session.Id,
|
||||
command,
|
||||
controllingUserId: user?.Id,
|
||||
});
|
||||
},
|
||||
onSettled: () => sessions.refetch(),
|
||||
});
|
||||
|
||||
const transfer = useMutation({
|
||||
mutationFn: async (session: SessionInfoDto) =>
|
||||
transferSessionToLocal(api, user?.Id, session),
|
||||
onSuccess: async (kind) => {
|
||||
await sessions.refetch();
|
||||
if (kind === "none") {
|
||||
enqueueSnackbar("Could not transfer playback", { variant: "error" });
|
||||
return;
|
||||
}
|
||||
enqueueSnackbar("Playback transferred to this device", {
|
||||
variant: "success",
|
||||
});
|
||||
if (kind === "video") {
|
||||
navigate({ to: "/player" });
|
||||
}
|
||||
},
|
||||
onError: () =>
|
||||
enqueueSnackbar("Could not transfer playback", { variant: "error" }),
|
||||
});
|
||||
|
||||
if (!remote || location.pathname.startsWith("/player")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const paused = remote.PlayState?.IsPaused;
|
||||
const title = remote.NowPlayingItem?.Name ?? "Unknown";
|
||||
|
||||
return (
|
||||
<div className={`remote-playback-bar${audioDisplay ? " with-audio" : ""}`}>
|
||||
<IconButton
|
||||
size="small"
|
||||
aria-label="Open remote control"
|
||||
onClick={() => openDialog()}
|
||||
>
|
||||
<span className="material-symbols-rounded">cast_connected</span>
|
||||
</IconButton>
|
||||
<div className="remote-playback-bar-info">
|
||||
<Typography variant="caption" className="remote-playback-bar-device">
|
||||
Playing on {remote.DeviceName || remote.Client || "device"}
|
||||
</Typography>
|
||||
<Typography variant="body2" noWrap className="remote-playback-bar-title">
|
||||
{title}
|
||||
</Typography>
|
||||
</div>
|
||||
<Tooltip title={paused ? "Play" : "Pause"}>
|
||||
<IconButton
|
||||
size="small"
|
||||
onClick={() =>
|
||||
command.mutate({
|
||||
session: remote,
|
||||
command: paused
|
||||
? PlaystateCommand.Unpause
|
||||
: PlaystateCommand.Pause,
|
||||
})
|
||||
}
|
||||
>
|
||||
<span className="material-symbols-rounded">
|
||||
{paused ? "play_arrow" : "pause"}
|
||||
</span>
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
<Button
|
||||
size="small"
|
||||
variant="contained"
|
||||
disabled={transfer.isPending}
|
||||
onClick={() => transfer.mutate(remote)}
|
||||
>
|
||||
Transfer here
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default React.memo(RemotePlaybackBar);
|
||||
@@ -0,0 +1,42 @@
|
||||
.remote-playback-bar {
|
||||
position: fixed;
|
||||
left: 50%;
|
||||
bottom: 1rem;
|
||||
transform: translateX(-50%);
|
||||
z-index: 99;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
width: min(620px, calc(100% - 2rem));
|
||||
padding: 0.4rem 0.4rem 0.4rem 0.6rem;
|
||||
box-sizing: border-box;
|
||||
border-radius: 12px;
|
||||
background: rgb(18 18 24 / 0.97);
|
||||
border: 1px solid rgb(255 255 255 / 0.1);
|
||||
box-shadow: 0 10px 30px rgb(0 0 0 / 0.45);
|
||||
color: white;
|
||||
|
||||
&.with-audio {
|
||||
bottom: 6.2rem; // above the 80px audio player
|
||||
}
|
||||
|
||||
.material-symbols-rounded {
|
||||
color: rgb(255 255 255 / 0.85);
|
||||
}
|
||||
|
||||
&-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
line-height: 1.15;
|
||||
}
|
||||
|
||||
&-device {
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
&-title {
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user