Skip to content

Commit

Permalink
Merge pull request #704 from 3flex/typing-playrequest
Browse files Browse the repository at this point in the history
Use PlayRequest type in more places
  • Loading branch information
nielsvanvelzen authored Nov 12, 2024
2 parents e6fc985 + 5e4aa24 commit 3ceac4b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions src/components/jellyfinActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -247,7 +247,7 @@ export async function getPlaybackInfo(
const query: PlaybackInfoDto = {
DeviceProfile: deviceProfile,
MaxStreamingBitrate: maxBitrate,
StartTimeTicks: startPosition || 0
StartTimeTicks: startPosition ?? 0
};

if (audioStreamIndex != null) {
Expand Down Expand Up @@ -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
Expand All @@ -308,7 +308,7 @@ export async function getLiveStream(
MaxStreamingBitrate: maxBitrate,
OpenToken: mediaSource.OpenToken,
PlaySessionId: playSessionId,
StartTimeTicks: startPosition || 0,
StartTimeTicks: startPosition ?? 0,
SubtitleStreamIndex: subtitleStreamIndex
}
});
Expand Down
3 changes: 1 addition & 2 deletions src/components/maincontroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
if (item.Id) {
const response = await getUserLibraryApi(
Expand Down
30 changes: 15 additions & 15 deletions src/components/playbackManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<void> {
private static playFromOptionsInternal(
options: PlayRequest
): Promise<void> {
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);

Expand Down Expand Up @@ -162,7 +162,7 @@ export abstract class PlaybackManager {

if (nextItemInfo) {
this.activePlaylistIndex = nextItemInfo.index;
this.playItem({}, stopPlayer);
this.playItem({ items: [] }, stopPlayer);

return true;
}
Expand All @@ -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;
}
Expand All @@ -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<void> {
if (stopPlayer) {
Expand All @@ -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<void> {
DocumentManager.setAppStatus(AppStatus.Loading);

Expand All @@ -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);

Expand All @@ -240,7 +240,7 @@ export abstract class PlaybackManager {
playbackInfo.PlaySessionId,
maxBitrate,
deviceProfile,
options.startPositionTicks,
options.startPositionTicks ?? null,
mediaSource,
null,
null
Expand All @@ -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(
Expand Down
11 changes: 6 additions & 5 deletions src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3ceac4b

Please sign in to comment.