refactor(casting): route all cast loads through loadCastMedia

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Uruk
2026-05-21 02:27:20 +02:00
parent fb8c649f6f
commit bcf6b705e1
5 changed files with 85 additions and 321 deletions

View File

@@ -52,6 +52,14 @@ export const useCasting = (item: BaseItemDto | null) => {
[],
);
// Real Jellyfin PlaySessionId, embedded in customData by buildCastMediaInfo.
const playSessionId =
(
mediaStatus?.mediaInfo?.customData as
| { playSessionId?: string }
| undefined
)?.playSessionId ?? mediaStatus?.mediaInfo?.contentId;
// Detect which protocol is active - use CastState for reliable detection
const chromecastConnected = castState === CastState.CONNECTED;
// Future: Add detection for other protocols here
@@ -139,7 +147,7 @@ export const useCasting = (item: BaseItemDto | null) => {
activeProtocol === "chromecast" ? "DirectStream" : "DirectPlay",
VolumeLevel: Math.floor(currentState.volume * 100),
IsMuted: currentState.volume === 0,
PlaySessionId: mediaStatus?.mediaInfo?.contentId,
PlaySessionId: playSessionId,
},
})
.catch((error) => {
@@ -179,7 +187,7 @@ export const useCasting = (item: BaseItemDto | null) => {
activeProtocol === "chromecast" ? "DirectStream" : "DirectPlay",
VolumeLevel: Math.floor(s.volume * 100),
IsMuted: s.volume === 0,
PlaySessionId: mediaStatus?.mediaInfo?.contentId,
PlaySessionId: playSessionId,
},
})
.catch((error) => {
@@ -190,14 +198,7 @@ export const useCasting = (item: BaseItemDto | null) => {
// Report progress on a fixed interval, reading latest state from ref
const interval = setInterval(reportProgress, 10000);
return () => clearInterval(interval);
}, [
api,
item?.Id,
user?.Id,
isConnected,
activeProtocol,
mediaStatus?.mediaInfo?.contentId,
]);
}, [api, item?.Id, user?.Id, isConnected, activeProtocol, playSessionId]);
// Play/Pause controls
const play = useCallback(async () => {