From 5e4aa24e4d12ae2f374ceb134d6964e70db2e074 Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Tue, 12 Nov 2024 20:28:28 +1100 Subject: [PATCH] Use PlayRequest type in more places --- src/components/jellyfinActions.ts | 8 ++++---- src/components/maincontroller.ts | 3 +-- src/components/playbackManager.ts | 30 +++++++++++++++--------------- src/types/global.d.ts | 11 ++++++----- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/components/jellyfinActions.ts b/src/components/jellyfinActions.ts index 5a4f48cd..20fe252c 100644 --- a/src/components/jellyfinActions.ts +++ b/src/components/jellyfinActions.ts @@ -231,7 +231,7 @@ export async function getPlaybackInfo( item: BaseItemDto, maxBitrate: number, deviceProfile: DeviceProfile, - startPosition: number, + startPosition: number | null, mediaSourceId: string | null, audioStreamIndex: number | null, subtitleStreamIndex: number | null, @@ -247,7 +247,7 @@ export async function getPlaybackInfo( const query: PlaybackInfoDto = { DeviceProfile: deviceProfile, MaxStreamingBitrate: maxBitrate, - StartTimeTicks: startPosition || 0 + StartTimeTicks: startPosition ?? 0 }; if (audioStreamIndex != null) { @@ -293,7 +293,7 @@ export async function getLiveStream( playSessionId: string, maxBitrate: number, deviceProfile: DeviceProfile, - startPosition: number, + startPosition: number | null, mediaSource: MediaSourceInfo, audioStreamIndex: number | null, subtitleStreamIndex: number | null @@ -308,7 +308,7 @@ export async function getLiveStream( MaxStreamingBitrate: maxBitrate, OpenToken: mediaSource.OpenToken, PlaySessionId: playSessionId, - StartTimeTicks: startPosition || 0, + StartTimeTicks: startPosition ?? 0, SubtitleStreamIndex: subtitleStreamIndex } }); diff --git a/src/components/maincontroller.ts b/src/components/maincontroller.ts index feeeae72..174e9e88 100644 --- a/src/components/maincontroller.ts +++ b/src/components/maincontroller.ts @@ -622,8 +622,7 @@ export async function shuffle( */ export async function onStopPlayerBeforePlaybackDone( item: BaseItemDto, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - options: any + options: PlayRequest ): Promise { if (item.Id) { const response = await getUserLibraryApi( diff --git a/src/components/playbackManager.ts b/src/components/playbackManager.ts index bba44cde..1d3aa292 100644 --- a/src/components/playbackManager.ts +++ b/src/components/playbackManager.ts @@ -4,7 +4,6 @@ import type { PlayMethod } from '@jellyfin/sdk/lib/generated-client'; import { RepeatMode } from '@jellyfin/sdk/lib/generated-client'; -import type { MediaInformationCustomData } from 'chromecast-caf-receiver/cast.framework.messages'; import { AppStatus } from '../types/appStatus'; import { broadcastConnectionErrorMessage, @@ -122,13 +121,14 @@ export abstract class PlaybackManager { return this.playFromOptionsInternal(options); } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - private static playFromOptionsInternal(options: any): Promise { + private static playFromOptionsInternal( + options: PlayRequest + ): Promise { const stopPlayer = this.activePlaylist && this.activePlaylist.length > 0; this.activePlaylist = options.items; - this.activePlaylistIndex = options.startIndex || 0; + this.activePlaylistIndex = options.startIndex ?? 0; console.log('Loaded new playlist:', this.activePlaylist); @@ -162,7 +162,7 @@ export abstract class PlaybackManager { if (nextItemInfo) { this.activePlaylistIndex = nextItemInfo.index; - this.playItem({}, stopPlayer); + this.playItem({ items: [] }, stopPlayer); return true; } @@ -173,7 +173,7 @@ export abstract class PlaybackManager { static playPreviousItem(): boolean { if (this.activePlaylist && this.activePlaylistIndex > 0) { this.activePlaylistIndex--; - this.playItem({}, true); + this.playItem({ items: [] }, true); return true; } @@ -183,7 +183,7 @@ export abstract class PlaybackManager { // play item from playlist private static async playItem( - options: any, // eslint-disable-line @typescript-eslint/no-explicit-any + options: PlayRequest, stopPlayer = false ): Promise { if (stopPlayer) { @@ -200,7 +200,7 @@ export abstract class PlaybackManager { // Would set private, but some refactorings need to happen first. static async playItemInternal( item: BaseItemDto, - options: MediaInformationCustomData + options: PlayRequest ): Promise { DocumentManager.setAppStatus(AppStatus.Loading); @@ -213,10 +213,10 @@ export abstract class PlaybackManager { item, maxBitrate, deviceProfile, - options.startPositionTicks, - options.mediaSourceId, - options.audioStreamIndex, - options.subtitleStreamIndex, + options.startPositionTicks ?? null, + options.mediaSourceId ?? null, + options.audioStreamIndex ?? null, + options.subtitleStreamIndex ?? null, options.liveStreamId ).catch(broadcastConnectionErrorMessage); @@ -240,7 +240,7 @@ export abstract class PlaybackManager { playbackInfo.PlaySessionId, maxBitrate, deviceProfile, - options.startPositionTicks, + options.startPositionTicks ?? null, mediaSource, null, null @@ -264,14 +264,14 @@ export abstract class PlaybackManager { playSessionId: string, item: BaseItemDto, mediaSource: MediaSourceInfo, - options: any // eslint-disable-line @typescript-eslint/no-explicit-any + options: PlayRequest ): void { DocumentManager.setAppStatus(AppStatus.Loading); const streamInfo = createStreamInfo( item, mediaSource, - options.startPositionTicks + options.startPositionTicks ?? null ); const mediaInfo = createMediaInformation( diff --git a/src/types/global.d.ts b/src/types/global.d.ts index 34c25518..9d0b448e 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -30,12 +30,13 @@ export interface ItemIndex { // From commandHandler export interface PlayRequest { + startIndex?: number; items: BaseItemDto[]; - startPositionTicks: number | undefined; - mediaSourceId: string | undefined; - audioStreamIndex: number | undefined; - subtitleStreamIndex: number | undefined; - liveStreamId: string | undefined; + startPositionTicks?: number; + mediaSourceId?: string; + audioStreamIndex?: number; + subtitleStreamIndex?: number; + liveStreamId?: string; } export interface DisplayRequest {