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
@@ -0,0 +1,125 @@
|
||||
import { secToTicks, ticksToSec } from "@/utils/date/time";
|
||||
import {
|
||||
setVolume as setAudioVolume,
|
||||
setIsMuted,
|
||||
stopPlayback,
|
||||
useAudioPlayback,
|
||||
} from "@/utils/store/audioPlayback";
|
||||
import { usePlaybackStore } from "@/utils/store/playback";
|
||||
|
||||
export type LocalPlaybackSnapshot = {
|
||||
kind: "video" | "audio" | "none";
|
||||
itemId: string | null;
|
||||
positionTicks: number;
|
||||
paused: boolean;
|
||||
};
|
||||
|
||||
const getVideoElement = () =>
|
||||
document
|
||||
.querySelector("hls-video")
|
||||
?.shadowRoot?.querySelector("video") as HTMLVideoElement | null;
|
||||
|
||||
/** What this client is currently playing, if anything. */
|
||||
export const getLocalPlayback = (): LocalPlaybackSnapshot => {
|
||||
const video = usePlaybackStore.getState();
|
||||
if (video.playbackStream && video.metadata.item?.Id) {
|
||||
return {
|
||||
kind: "video",
|
||||
itemId: video.metadata.item.Id,
|
||||
positionTicks: video.playerState.currentTime ?? 0,
|
||||
paused: !video.playerState.isPlayerPlaying,
|
||||
};
|
||||
}
|
||||
|
||||
const audio = useAudioPlayback.getState();
|
||||
if (audio.display && audio.item?.Id) {
|
||||
const element = audio.player.ref?.current;
|
||||
return {
|
||||
kind: "audio",
|
||||
itemId: audio.item.Id,
|
||||
positionTicks: element
|
||||
? secToTicks(element.currentTime)
|
||||
: audio.player.currentTick,
|
||||
paused: element ? element.paused : !audio.player.playing,
|
||||
};
|
||||
}
|
||||
|
||||
return { kind: "none", itemId: null, positionTicks: 0, paused: false };
|
||||
};
|
||||
|
||||
export const pauseLocalPlayback = () => {
|
||||
const video = usePlaybackStore.getState();
|
||||
if (video.playbackStream && video.metadata.item?.Id) {
|
||||
getVideoElement()?.pause();
|
||||
video.setIsPlaying(false);
|
||||
}
|
||||
useAudioPlayback.getState().player.ref?.current?.pause();
|
||||
};
|
||||
|
||||
export const resumeLocalPlayback = () => {
|
||||
const video = usePlaybackStore.getState();
|
||||
if (video.playbackStream && video.metadata.item?.Id) {
|
||||
video.setIsPlaying(true);
|
||||
getVideoElement()
|
||||
?.play()
|
||||
.catch(() => {
|
||||
// The ReactPlayer `playing` prop retries once the media is ready.
|
||||
});
|
||||
}
|
||||
const audio = useAudioPlayback.getState();
|
||||
if (audio.display && audio.item?.Id) {
|
||||
audio.player.ref?.current?.play().catch(() => undefined);
|
||||
}
|
||||
};
|
||||
|
||||
export const seekLocalPlayback = (positionTicks: number) => {
|
||||
const ticks = Math.max(0, Math.round(positionTicks));
|
||||
const video = usePlaybackStore.getState();
|
||||
if (video.playbackStream && video.metadata.item?.Id) {
|
||||
if (!video.playerState.isPlayerReady) {
|
||||
usePlaybackStore.setState((state) => {
|
||||
state.playerState.seekValue = ticks;
|
||||
state.playerState.currentTime = ticks;
|
||||
});
|
||||
return;
|
||||
}
|
||||
video.seekTo(ticksToSec(ticks));
|
||||
return;
|
||||
}
|
||||
|
||||
const audio = useAudioPlayback.getState();
|
||||
const element = audio.player.ref?.current;
|
||||
if (element) {
|
||||
element.currentTime = ticksToSec(ticks);
|
||||
}
|
||||
};
|
||||
|
||||
export const setLocalVolume = (volume: number) => {
|
||||
const value = Math.min(1, Math.max(0, volume));
|
||||
const video = usePlaybackStore.getState();
|
||||
if (video.playbackStream && video.metadata.item?.Id) {
|
||||
video.setVolume(value);
|
||||
}
|
||||
if (useAudioPlayback.getState().display) {
|
||||
setAudioVolume(value);
|
||||
}
|
||||
};
|
||||
|
||||
export const setLocalMuted = (muted: boolean) => {
|
||||
const video = usePlaybackStore.getState();
|
||||
if (video.playbackStream && video.metadata.item?.Id) {
|
||||
if (video.playerState.isPlayerMuted !== muted) {
|
||||
video.toggleIsPlayerMuted();
|
||||
}
|
||||
}
|
||||
if (useAudioPlayback.getState().display) {
|
||||
setIsMuted(muted);
|
||||
}
|
||||
};
|
||||
|
||||
export const stopLocalPlayback = () => {
|
||||
pauseLocalPlayback();
|
||||
if (useAudioPlayback.getState().display) {
|
||||
stopPlayback();
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user