mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-06-18 11:50:26 +01:00
feat: closes pr/181
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
import { BITRATES } from "@/components/BitrateSelector";
|
import { BITRATES } from "@/components/BitrateSelector";
|
||||||
import { Text } from "@/components/common/Text";
|
import { Text } from "@/components/common/Text";
|
||||||
import { Loader } from "@/components/Loader";
|
import { Loader } from "@/components/Loader";
|
||||||
import { getDownloadedFileUrl } from "@/hooks/useDownloadedFileOpener";
|
|
||||||
import { Controls } from "@/components/video-player/controls/Controls";
|
import { Controls } from "@/components/video-player/controls/Controls";
|
||||||
|
import { getDownloadedFileUrl } from "@/hooks/useDownloadedFileOpener";
|
||||||
import { useOrientation } from "@/hooks/useOrientation";
|
import { useOrientation } from "@/hooks/useOrientation";
|
||||||
import { useOrientationSettings } from "@/hooks/useOrientationSettings";
|
import { useOrientationSettings } from "@/hooks/useOrientationSettings";
|
||||||
|
import { useRevalidatePlaybackProgressCache } from "@/hooks/useRevalidatePlaybackProgressCache";
|
||||||
import { useWebSocket } from "@/hooks/useWebsockets";
|
import { useWebSocket } from "@/hooks/useWebsockets";
|
||||||
import { VlcPlayerView } from "@/modules/vlc-player";
|
import { VlcPlayerView } from "@/modules/vlc-player";
|
||||||
import {
|
import {
|
||||||
@@ -20,32 +21,18 @@ import { writeToLog } from "@/utils/log";
|
|||||||
import native from "@/utils/profiles/native";
|
import native from "@/utils/profiles/native";
|
||||||
import { msToTicks, ticksToSeconds } from "@/utils/time";
|
import { msToTicks, ticksToSeconds } from "@/utils/time";
|
||||||
import { Api } from "@jellyfin/sdk";
|
import { Api } from "@jellyfin/sdk";
|
||||||
import {
|
import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||||
BaseItemDto,
|
|
||||||
MediaSourceType,
|
|
||||||
} from "@jellyfin/sdk/lib/generated-client";
|
|
||||||
import {
|
import {
|
||||||
getPlaystateApi,
|
getPlaystateApi,
|
||||||
getUserLibraryApi,
|
getUserLibraryApi,
|
||||||
} from "@jellyfin/sdk/lib/utils/api";
|
} from "@jellyfin/sdk/lib/utils/api";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import * as Haptics from "expo-haptics";
|
import * as Haptics from "expo-haptics";
|
||||||
import {
|
import { useFocusEffect, useGlobalSearchParams } from "expo-router";
|
||||||
useFocusEffect,
|
|
||||||
useGlobalSearchParams,
|
|
||||||
useLocalSearchParams,
|
|
||||||
} from "expo-router";
|
|
||||||
import { useAtomValue } from "jotai";
|
import { useAtomValue } from "jotai";
|
||||||
import React, {
|
import React, { useCallback, useMemo, useRef, useState } from "react";
|
||||||
useCallback,
|
|
||||||
useEffect,
|
|
||||||
useMemo,
|
|
||||||
useRef,
|
|
||||||
useState,
|
|
||||||
} from "react";
|
|
||||||
import { Alert, Pressable, View } from "react-native";
|
import { Alert, Pressable, View } from "react-native";
|
||||||
import { useSharedValue } from "react-native-reanimated";
|
import { useSharedValue } from "react-native-reanimated";
|
||||||
import { SafeAreaView } from "react-native-safe-area-context";
|
|
||||||
|
|
||||||
export default function page() {
|
export default function page() {
|
||||||
const videoRef = useRef<VlcPlayerViewRef>(null);
|
const videoRef = useRef<VlcPlayerViewRef>(null);
|
||||||
@@ -64,6 +51,7 @@ export default function page() {
|
|||||||
const cacheProgress = useSharedValue(0);
|
const cacheProgress = useSharedValue(0);
|
||||||
|
|
||||||
const { getDownloadedItem } = useDownload();
|
const { getDownloadedItem } = useDownload();
|
||||||
|
const revalidateProgressCache = useRevalidatePlaybackProgressCache();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
itemId,
|
itemId,
|
||||||
@@ -253,6 +241,8 @@ export default function page() {
|
|||||||
positionTicks: currentTimeInTicks,
|
positionTicks: currentTimeInTicks,
|
||||||
playSessionId: stream?.sessionId!,
|
playSessionId: stream?.sessionId!,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
revalidateProgressCache();
|
||||||
}, [api, item, mediaSourceId, stream]);
|
}, [api, item, mediaSourceId, stream]);
|
||||||
|
|
||||||
const reportPlaybackStart = useCallback(async () => {
|
const reportPlaybackStart = useCallback(async () => {
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import Video, {
|
|||||||
} from "react-native-video";
|
} from "react-native-video";
|
||||||
import { Controls } from "@/components/video-player/controls/Controls";
|
import { Controls } from "@/components/video-player/controls/Controls";
|
||||||
import transcoding from "@/utils/profiles/transcoding";
|
import transcoding from "@/utils/profiles/transcoding";
|
||||||
|
import { useRevalidatePlaybackProgressCache } from "@/hooks/useRevalidatePlaybackProgressCache";
|
||||||
|
|
||||||
const Player = () => {
|
const Player = () => {
|
||||||
const api = useAtomValue(apiAtom);
|
const api = useAtomValue(apiAtom);
|
||||||
@@ -45,7 +46,7 @@ const Player = () => {
|
|||||||
const videoRef = useRef<VideoRef | null>(null);
|
const videoRef = useRef<VideoRef | null>(null);
|
||||||
|
|
||||||
const firstTime = useRef(true);
|
const firstTime = useRef(true);
|
||||||
const dimensions = useWindowDimensions();
|
const revalidateProgressCache = useRevalidatePlaybackProgressCache();
|
||||||
|
|
||||||
const [isPlaybackStopped, setIsPlaybackStopped] = useState(false);
|
const [isPlaybackStopped, setIsPlaybackStopped] = useState(false);
|
||||||
const [showControls, setShowControls] = useState(true);
|
const [showControls, setShowControls] = useState(true);
|
||||||
@@ -239,6 +240,7 @@ const Player = () => {
|
|||||||
positionTicks: Math.floor(progress.value),
|
positionTicks: Math.floor(progress.value),
|
||||||
playSessionId: stream?.sessionId,
|
playSessionId: stream?.sessionId,
|
||||||
});
|
});
|
||||||
|
revalidateProgressCache();
|
||||||
};
|
};
|
||||||
|
|
||||||
const reportPlaybackStart = async () => {
|
const reportPlaybackStart = async () => {
|
||||||
|
|||||||
@@ -41,9 +41,6 @@ export const PlayedStatus: React.FC<Props> = ({ item, ...props }) => {
|
|||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: ["seasons"],
|
queryKey: ["seasons"],
|
||||||
});
|
});
|
||||||
queryClient.invalidateQueries({
|
|
||||||
queryKey: ["nextUp-all"],
|
|
||||||
});
|
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: ["home"],
|
queryKey: ["home"],
|
||||||
});
|
});
|
||||||
|
|||||||
29
hooks/useRevalidatePlaybackProgressCache.ts
Normal file
29
hooks/useRevalidatePlaybackProgressCache.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* useRevalidatePlaybackProgressCache invalidates queries related to playback progress.
|
||||||
|
*/
|
||||||
|
export function useRevalidatePlaybackProgressCache() {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
const revalidate = () => {
|
||||||
|
// List of all the queries to invalidate
|
||||||
|
const queriesToInvalidate = [
|
||||||
|
["item"],
|
||||||
|
["resumeItems"],
|
||||||
|
["continueWatching"],
|
||||||
|
["nextUp-all"],
|
||||||
|
["nextUp"],
|
||||||
|
["episodes"],
|
||||||
|
["seasons"],
|
||||||
|
["home"],
|
||||||
|
];
|
||||||
|
|
||||||
|
// Invalidate each query
|
||||||
|
queriesToInvalidate.forEach((queryKey) => {
|
||||||
|
queryClient.invalidateQueries({ queryKey });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return revalidate;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user