feat(casting): add CastSelection model and resolution helpers

This commit is contained in:
Uruk
2026-05-21 23:46:19 +02:00
parent e5d61bf3ea
commit 3d65c3bb7a
4 changed files with 163 additions and 20 deletions

View File

@@ -17,6 +17,7 @@ import {
} from "@/utils/casting/capabilities";
import { isLoadFailedError } from "@/utils/casting/castErrors";
import { buildCastMediaInfo } from "@/utils/casting/mediaInfo";
import { resolveDefaultAudioIndex } from "@/utils/casting/selection";
import { getStreamUrl } from "@/utils/jellyfin/media/getStreamUrl";
export interface CastLoadOptions {
@@ -42,26 +43,6 @@ export interface CastLoadParams {
export type CastLoadResult = { ok: true } | { ok: false; error: unknown };
/**
* Resolve the default audio stream index for an item.
* Fixes the previous `audioStreamIndex = 0` default, which selected the video stream.
*/
export const resolveDefaultAudioIndex = (
item: BaseItemDto,
mediaSourceId?: string,
): number | undefined => {
const source = mediaSourceId
? item.MediaSources?.find((s) => s.Id === mediaSourceId)
: item.MediaSources?.[0];
if (source?.DefaultAudioStreamIndex != null) {
return source.DefaultAudioStreamIndex;
}
const audio =
item.MediaStreams?.find((s) => s.Type === "Audio" && s.IsDefault) ??
item.MediaStreams?.find((s) => s.Type === "Audio");
return audio?.Index ?? undefined;
};
const attemptLoad = async (
params: CastLoadParams,
caps: Parameters<typeof buildChromecastProfile>[0],