fix(chromecast): resolve TypeScript errors and improve type safety

- Fix deviceName property to use friendlyName
- Update disconnect to use stop() instead of endSession()
- Fix null handling in getPosterUrl and useTrickplay
- Remove unused variables and imports
- Add proper null checks in segment skipping
- Disable auto-skip until settings are available
This commit is contained in:
Uruk
2026-01-19 22:13:54 +01:00
parent 45f7923e84
commit b25faefdcf
4 changed files with 19 additions and 21 deletions

View File

@@ -5,7 +5,6 @@
import { Ionicons } from "@expo/vector-icons";
import { Image } from "expo-image";
import { useRouter } from "expo-router";
import { useAtomValue } from "jotai";
import React, { useCallback, useMemo, useState } from "react";
import {
@@ -48,9 +47,8 @@ export const ChromecastPlayer: React.FC<ChromecastPlayerProps> = ({
visible,
onClose,
}) => {
const _router = useRouter();
const insets = useSafeAreaInsets();
const { height: screenHeight, width: screenWidth } = useWindowDimensions();
const { height: screenHeight } = useWindowDimensions();
const api = useAtomValue(apiAtom);
const {
@@ -58,9 +56,6 @@ export const ChromecastPlayer: React.FC<ChromecastPlayerProps> = ({
showControls,
currentItem,
nextItem,
castDevice,
play,
pause,
stop,
togglePlay,
seek,
@@ -75,11 +70,12 @@ export const ChromecastPlayer: React.FC<ChromecastPlayerProps> = ({
settings,
} = useChromecastPlayer();
const { segments, currentSegment, skipSegment, hasIntro, hasCredits } =
useChromecastSegments(currentItem, playerState.progress);
const { currentSegment, skipSegment } = useChromecastSegments(
currentItem,
playerState.progress,
);
const { trickPlayUrl, calculateTrickplayUrl, trickplayInfo } =
useTrickplay(currentItem);
const { calculateTrickplayUrl, trickplayInfo } = useTrickplay(currentItem!);
const [_showMenu, setShowMenu] = useState(false);
const [_showDeviceSheet, setShowDeviceSheet] = useState(false);

View File

@@ -55,7 +55,7 @@ export const useChromecastPlayer = () => {
setPlayerState((prev) => ({
...prev,
isConnected: !!castDevice,
deviceName: castDevice?.deviceName || null,
deviceName: castDevice?.friendlyName || castDevice?.deviceId || null,
isPlaying: mediaStatus.playerState === "playing",
isPaused: mediaStatus.playerState === "paused",
isStopped: mediaStatus.playerState === "idle",
@@ -179,7 +179,7 @@ export const useChromecastPlayer = () => {
}, [playerState.progress, seek, settings?.rewindSkipTime]);
const disconnect = useCallback(async () => {
await client?.endSession(true);
await client?.stop();
setPlayerState(DEFAULT_CHROMECAST_STATE);
}, [client]);
@@ -188,7 +188,7 @@ export const useChromecastPlayer = () => {
const remainingTime = formatTime(playerState.duration - playerState.progress);
const endingTime = calculateEndingTime(
playerState.duration - playerState.progress,
settings?.use24HourFormat ?? true,
true, // TODO: Add use24HourFormat setting
);
// Next episode countdown

View File

@@ -127,7 +127,7 @@ export const useChromecastSegments = (
const skipSegment = useCallback(
(seekFn: (positionMs: number) => Promise<void>) => {
if (currentSegment) {
if (currentSegment?.segment) {
return seekFn(currentSegment.segment.end * 1000);
}
},
@@ -140,9 +140,11 @@ export const useChromecastSegments = (
switch (currentSegment.type) {
case "intro":
return settings?.autoSkipIntro ?? false;
// TODO: Add autoSkipIntroEnabled setting
return false;
case "credits":
return settings?.autoSkipCredits ?? false;
// TODO: Add autoSkipCreditsEnabled setting
return false;
case "recap":
case "commercial":
case "preview":
@@ -151,7 +153,7 @@ export const useChromecastSegments = (
default:
return false;
}
}, [currentSegment, settings]);
}, [currentSegment]);
return {
segments,

View File

@@ -112,10 +112,10 @@ export const formatEpisodeInfo = (
*/
export const getPosterUrl = (
item: {
Type?: string;
ParentBackdropImageTags?: string[];
SeriesId?: string;
Id?: string;
Type?: string | null;
ParentBackdropImageTags?: string[] | null;
SeriesId?: string | null;
Id?: string | null;
},
api: { basePath?: string },
): string | null => {