From 55abb5725f4cdf7b9d0849a38b6bff7031e7cb11 Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Tue, 26 Nov 2024 18:11:35 +1100 Subject: [PATCH 1/4] Create interface to hold custom data received from cast sender --- src/types/global.d.ts | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/types/global.d.ts b/src/types/global.d.ts index 9d0b448e..de2feef6 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -106,17 +106,21 @@ declare global { } declare module 'chromecast-caf-receiver/cast.framework.messages' { - interface MediaInformationCustomData { - audioStreamIndex: number | null; - canClientSeek: boolean; - canSeek: boolean; - itemId: string | undefined; - liveStreamId: string | null; - mediaSourceId: string | null; - playMethod: 'DirectStream' | 'Transcode'; - playSessionId: string; - runtimeTicks: number | null; - startPositionTicks: number; - subtitleStreamIndex: number | null; - } + // eslint-disable-next-line @typescript-eslint/no-empty-object-type + interface MediaInformationCustomData + extends JellyfinMediaInformationCustomData {} +} + +interface JellyfinMediaInformationCustomData { + audioStreamIndex: number | null; + canClientSeek: boolean; + canSeek: boolean; + itemId: string | undefined; + liveStreamId: string | null; + mediaSourceId: string | null; + playMethod: 'DirectStream' | 'Transcode'; + playSessionId: string; + runtimeTicks: number | null; + startPositionTicks: number; + subtitleStreamIndex: number | null; } From 06aec3123653b818727646b4d2bd0417e826344c Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Tue, 26 Nov 2024 18:12:15 +1100 Subject: [PATCH 2/4] Use custom data interface when loading media --- src/components/jellyfinActions.ts | 7 +++++-- src/components/playbackManager.ts | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/components/jellyfinActions.ts b/src/components/jellyfinActions.ts index 20fe252c..a84b2684 100644 --- a/src/components/jellyfinActions.ts +++ b/src/components/jellyfinActions.ts @@ -16,6 +16,7 @@ import { AppStatus } from '../types/appStatus'; import { JellyfinApi } from './jellyfinApi'; import { DocumentManager } from './documentManager'; import { PlaybackManager, type PlaybackState } from './playbackManager'; +import type { JellyfinMediaInformationCustomData } from '~/types/global'; let pingInterval: number; let lastTranscoderPing = 0; @@ -164,8 +165,10 @@ export async function pingTranscoder(playSessionId: string): Promise { * @param customData - data to set on playback state. * @param serverItem - item that is playing */ -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export function load(customData: any, serverItem: BaseItemDto): void { +export function load( + customData: JellyfinMediaInformationCustomData, + serverItem: BaseItemDto +): void { PlaybackManager.resetPlaybackScope(); const state = PlaybackManager.playbackState; diff --git a/src/components/playbackManager.ts b/src/components/playbackManager.ts index 1d3aa292..92223337 100644 --- a/src/components/playbackManager.ts +++ b/src/components/playbackManager.ts @@ -295,7 +295,10 @@ export abstract class PlaybackManager { const isChangingStream = this.playbackState.isChangingStream; - load(mediaInfo.customData, item); + if (mediaInfo.customData) { + load(mediaInfo.customData, item); + } + this.playbackState.isChangingStream = isChangingStream; this.playerManager.load(loadRequestData); From 33a06d4e4e996d6c7cfcde5aea54b06850835727 Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Tue, 26 Nov 2024 18:13:31 +1100 Subject: [PATCH 3/4] Fix PlaybackState typing --- src/components/playbackManager.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/playbackManager.ts b/src/components/playbackManager.ts index 92223337..96efa96d 100644 --- a/src/components/playbackManager.ts +++ b/src/components/playbackManager.ts @@ -31,12 +31,12 @@ import type { ItemIndex, PlayRequest } from '~/types/global'; export interface PlaybackState { startPositionTicks: number; mediaType: string | null | undefined; - itemId: string; + itemId: string | undefined; audioStreamIndex: number | null; subtitleStreamIndex: number | null; mediaSource: MediaSourceInfo | null; - mediaSourceId: string; + mediaSourceId: string | null; PlaybackMediaSource: MediaSourceInfo | null; playMethod: PlayMethod | undefined; @@ -45,10 +45,10 @@ export interface PlaybackState { playNextItemBool: boolean; item: BaseItemDto | null; - liveStreamId: string; + liveStreamId: string | null; playSessionId: string; - runtimeTicks: number; + runtimeTicks: number | null; } // eslint-disable-next-line @typescript-eslint/no-extraneous-class From 634ce467efd0e53574402cbb68f091efd63ebc2b Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Tue, 26 Nov 2024 20:24:34 +1100 Subject: [PATCH 4/4] Use type from SDK for playMethod property --- src/types/global.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/types/global.d.ts b/src/types/global.d.ts index de2feef6..9b07561f 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -6,6 +6,7 @@ import { SystemVolumeData } from 'chromecast-caf-receiver/cast.framework.system' import type { BaseItemDto, MediaSourceInfo, + PlayMethod, RepeatMode } from '@jellyfin/sdk/lib/generated-client'; import type { @@ -118,7 +119,7 @@ interface JellyfinMediaInformationCustomData { itemId: string | undefined; liveStreamId: string | null; mediaSourceId: string | null; - playMethod: 'DirectStream' | 'Transcode'; + playMethod: PlayMethod; playSessionId: string; runtimeTicks: number | null; startPositionTicks: number;