feat: add cross-device playback and remote control
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
- native SyncPlay groups with shared queues, ready/buffering and local pause/seek reporting - follow-me prompt that transfers another session's playback to this device - auto-skip intros/recaps and skip-credits for final items - blink:// deep links with timestamped scene sharing via QR - Quick Connect approval and QR onboarding from a phone - Rust WebSocket client with Authorization header for Jellyfin 12, capabilities advertising, live sessions and remote commands
This commit is contained in:
1 parent
cb5ee9b672
commit
5746bf35a5
39 files changed
+3235
-18
No files matched your search
@@ -23,12 +23,19 @@ import type { QueryClient } from "@tanstack/react-query";
|
||||
import { DndProvider } from "react-dnd";
|
||||
import { HTML5Backend } from "react-dnd-html5-backend";
|
||||
import Backdrop from "@/components/backdrop";
|
||||
import DeepLinkHandler from "@/components/deepLinks";
|
||||
import FollowMe from "@/components/followMe";
|
||||
import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice";
|
||||
import QuickConnectApprovalDialog from "@/components/quickConnectApproval";
|
||||
import ShareDialog from "@/components/share";
|
||||
import OverlayScrollbar from "@/components/overlayScrollbar";
|
||||
import PlaybackSync from "@/components/playback/PlaybackSync";
|
||||
import RealtimeBridge from "@/components/realtime";
|
||||
import SplashHider from "@/components/splash";
|
||||
import RemoteControlDialog from "@/components/remoteControl";
|
||||
import RouterLoading from "@/components/routerLoading";
|
||||
import SyncPlayController from "@/components/syncPlay/controller";
|
||||
import SyncPlayDialog from "@/components/syncPlay";
|
||||
import Search from "@/components/search";
|
||||
import Updater from "@/components/updater";
|
||||
import WindowChrome from "@/components/windowControls/windowChrome";
|
||||
@@ -60,12 +67,19 @@ export const Route = createRootRouteWithContext<ApiContext>()({
|
||||
<Backdrop />
|
||||
<Search />
|
||||
<RemoteControlDialog />
|
||||
<SyncPlayDialog />
|
||||
<SyncPlayController />
|
||||
<ShareDialog />
|
||||
<QuickConnectApprovalDialog />
|
||||
<DeepLinkHandler />
|
||||
<AppBar />
|
||||
<WindowChrome />
|
||||
<WindowDrag />
|
||||
<WindowResizeHandles />
|
||||
<AudioPlayer />
|
||||
<PlaybackSync />
|
||||
<RealtimeBridge />
|
||||
<FollowMe />
|
||||
<OverlayScrollbar />
|
||||
<Outlet />
|
||||
</SnackbarProvider>
|
||||
|
||||
@@ -7,6 +7,7 @@ import { NavigationDrawer } from "@/components/appBar/navigationDrawer";
|
||||
import CastButton from "@/components/buttons/castButton";
|
||||
import { UserAvatarMenu } from "@/components/userAvatarMenu";
|
||||
import WindowControls from "@/components/windowControls";
|
||||
import { openSyncPlayDialog } from "@/utils/methods/syncPlay";
|
||||
import useSearchStore from "@/utils/store/search";
|
||||
|
||||
type HomeHeaderProps = {
|
||||
@@ -102,6 +103,13 @@ const HomeHeader = ({ libraries, onNewAndPopular }: HomeHeaderProps) => {
|
||||
</div>
|
||||
|
||||
<div className="home-header-right">
|
||||
<IconButton
|
||||
aria-label="Watch together"
|
||||
title="Watch together"
|
||||
onClick={openSyncPlayDialog}
|
||||
>
|
||||
<span className="material-symbols-rounded">groups</span>
|
||||
</IconButton>
|
||||
<IconButton aria-label="Search" onClick={toggleSearchDialog}>
|
||||
<span className="material-symbols-rounded">search</span>
|
||||
</IconButton>
|
||||
|
||||
@@ -27,8 +27,18 @@ import StatsForNerds from "@/components/playback/videoPlayer/StatsForNerds";
|
||||
import UpNextFlyout from "@/components/playback/videoPlayer/upNextFlyout";
|
||||
import VolumeChangeOverlay from "@/components/playback/videoPlayer/VolumeChangeOverlay";
|
||||
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
||||
import { getAutoSkipSegments } from "@/utils/storage/player";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useBackdropStore } from "@/utils/store/backdrop";
|
||||
import {
|
||||
inSyncPlayGroup,
|
||||
nextSyncPlayItem,
|
||||
reportSyncPlayBuffering,
|
||||
reportSyncPlayPause,
|
||||
reportSyncPlayReady,
|
||||
reportSyncPlayResume,
|
||||
reportSyncPlaySeek,
|
||||
} from "@/utils/methods/syncPlay";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
import useQueue, { clearQueue } from "@/utils/store/queue";
|
||||
import type subtitlePlaybackInfo from "@/utils/types/subtitlePlaybackInfo";
|
||||
@@ -101,7 +111,9 @@ export function VideoPlayer() {
|
||||
const {
|
||||
itemId,
|
||||
userDataLastPlayedPositionTicks,
|
||||
// mediaSegments,
|
||||
mediaSegments,
|
||||
activeSegmentId,
|
||||
skipSegment,
|
||||
setCurrentTime,
|
||||
volume,
|
||||
isPlayerPlaying,
|
||||
@@ -131,7 +143,9 @@ export function VideoPlayer() {
|
||||
itemId: state.metadata.item?.Id,
|
||||
userDataLastPlayedPositionTicks:
|
||||
state.metadata.userDataLastPlayedPositionTicks,
|
||||
// mediaSegments: state.metadata.mediaSegments,
|
||||
mediaSegments: state.metadata.mediaSegments,
|
||||
activeSegmentId: state.activeSegmentId,
|
||||
skipSegment: state.skipSegment,
|
||||
setCurrentTime: state.setCurrentTime,
|
||||
volume: state.playerState.volume,
|
||||
isPlayerPlaying: state.playerState.isPlayerPlaying,
|
||||
@@ -170,6 +184,70 @@ export function VideoPlayer() {
|
||||
]);
|
||||
|
||||
const [error, setError] = React.useState<any>(null);
|
||||
const autoSkippedSegmentRef = useRef<string | null>(null);
|
||||
|
||||
// Deep links, transfers and resume all set a start position. Do not rely
|
||||
// on a single `onReady` callback (HLS wrappers can fire it late or reset
|
||||
// the media afterwards), keep enforcing it until the player settles.
|
||||
useEffect(() => {
|
||||
if (!playbackStream) return;
|
||||
const target = ticksToSec(userDataLastPlayedPositionTicks ?? 0);
|
||||
if (target <= 1) {
|
||||
startSeekRef.current = null;
|
||||
return;
|
||||
}
|
||||
startSeekRef.current = {
|
||||
target,
|
||||
expiresAt: Date.now() + 15000,
|
||||
};
|
||||
const seek = () => {
|
||||
// A user seek clears the pending target; stop enforcing then.
|
||||
if (!startSeekRef.current) return true;
|
||||
const video = getVideoElement();
|
||||
if (!video) return false;
|
||||
if (Math.abs(video.currentTime - target) > 3) {
|
||||
video.currentTime = target;
|
||||
}
|
||||
// HLS wrappers can report the new time and then reset to the
|
||||
// manifest start; keep the target until the 15s window expires.
|
||||
return false;
|
||||
};
|
||||
seek();
|
||||
const timer = window.setInterval(() => {
|
||||
if (seek() || Date.now() > (startSeekRef.current?.expiresAt ?? 0)) {
|
||||
window.clearInterval(timer);
|
||||
startSeekRef.current = null;
|
||||
}
|
||||
}, 500);
|
||||
return () => window.clearInterval(timer);
|
||||
}, [playbackStream, userDataLastPlayedPositionTicks, getVideoElement]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!activeSegmentId || !mediaSegments) return;
|
||||
const segment = mediaSegments.Items?.find(
|
||||
(entry) => entry.Id === activeSegmentId,
|
||||
);
|
||||
if (!segment?.Id) return;
|
||||
if (
|
||||
segment.Type !== "Intro" &&
|
||||
segment.Type !== "Recap" &&
|
||||
segment.Type !== "Commercial" &&
|
||||
segment.Type !== "Preview"
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const segmentId = segment.Id;
|
||||
let cancelled = false;
|
||||
getAutoSkipSegments().then((enabled) => {
|
||||
if (!enabled || cancelled) return;
|
||||
if (autoSkippedSegmentRef.current === segmentId) return;
|
||||
autoSkippedSegmentRef.current = segmentId;
|
||||
skipSegment();
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [activeSegmentId, mediaSegments, skipSegment]);
|
||||
|
||||
const setBackdrop = useBackdropStore(useShallow((s) => s.setBackdrop));
|
||||
useEffect(() => setBackdrop(""), []);
|
||||
@@ -281,6 +359,11 @@ export function VideoPlayer() {
|
||||
VolumeLevel: Math.floor(volume * 100),
|
||||
},
|
||||
});
|
||||
reportSyncPlayReady(
|
||||
api,
|
||||
secToTicks(getVideoElement()?.currentTime ?? 0),
|
||||
true,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -374,6 +457,7 @@ export function VideoPlayer() {
|
||||
VolumeLevel: Math.floor(volume * 100),
|
||||
},
|
||||
});
|
||||
reportSyncPlayPause(api);
|
||||
}, [
|
||||
setCurrentTime,
|
||||
api,
|
||||
@@ -547,13 +631,19 @@ export function VideoPlayer() {
|
||||
]);
|
||||
|
||||
const handlePlaybackEnded = useCallback(() => {
|
||||
clearActiveSegment(); // Clear active segment when playback ends
|
||||
if (api && inSyncPlayGroup()) {
|
||||
// The group owns the queue while watching together; the server will
|
||||
// broadcast the next item so every device moves on together.
|
||||
void nextSyncPlayItem(api);
|
||||
return;
|
||||
}
|
||||
if (queue?.length !== currentQueueItemIndex + 1) {
|
||||
clearActiveSegment(); // Clear active segment when playback ends
|
||||
playItemFromQueue("next", user?.Id, api);
|
||||
} else {
|
||||
handleExitPlayer(); // Exit player if playback has finished and the queue is empty
|
||||
}
|
||||
}, []);
|
||||
}, [api, queue?.length, currentQueueItemIndex, user?.Id]);
|
||||
|
||||
const idleTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
|
||||
@@ -590,10 +680,22 @@ export function VideoPlayer() {
|
||||
|
||||
const handleOnBuffer = useCallback(() => {
|
||||
setIsBuffering(true);
|
||||
}, [setIsBuffering]);
|
||||
reportSyncPlayBuffering(
|
||||
api,
|
||||
true,
|
||||
secToTicks(getVideoElement()?.currentTime ?? 0),
|
||||
isPlayerPlaying,
|
||||
);
|
||||
}, [setIsBuffering, api, isPlayerPlaying]);
|
||||
const handleOnBufferEnd = useCallback(() => {
|
||||
setIsBuffering(false);
|
||||
}, [setIsBuffering]);
|
||||
reportSyncPlayBuffering(
|
||||
api,
|
||||
false,
|
||||
secToTicks(getVideoElement()?.currentTime ?? 0),
|
||||
true,
|
||||
);
|
||||
}, [setIsBuffering, api]);
|
||||
|
||||
const handleError = useCallback((e: any) => {
|
||||
console.error("Video playback error:", e);
|
||||
@@ -666,7 +768,10 @@ export function VideoPlayer() {
|
||||
onReady={handleReady}
|
||||
onTimeUpdate={handleTimeUpdate}
|
||||
onPause={handlePause}
|
||||
onPlay={handleTimeUpdate}
|
||||
onPlay={() => {
|
||||
handleTimeUpdate();
|
||||
reportSyncPlayResume(api);
|
||||
}}
|
||||
onError={handleError}
|
||||
onEnded={handlePlaybackEnded}
|
||||
width="100vw"
|
||||
@@ -678,7 +783,10 @@ export function VideoPlayer() {
|
||||
volume={isPlayerMuted ? 0 : volume}
|
||||
onWaiting={handleOnBuffer}
|
||||
onPlaying={handleOnBufferEnd}
|
||||
onSeeking={(e) => handleOnSeek(e.currentTarget.currentTime)}
|
||||
onSeeking={(e) => {
|
||||
handleOnSeek(e.currentTarget.currentTime);
|
||||
reportSyncPlaySeek(api, secToTicks(e.currentTarget.currentTime));
|
||||
}}
|
||||
playsInline
|
||||
crossOrigin="anonymous"
|
||||
/>
|
||||
|
||||
Reference in new issue
Block a user