Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create interface to hold custom data received from cast sender #715

Merged
merged 4 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/components/jellyfinActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -164,8 +165,10 @@ export async function pingTranscoder(playSessionId: string): Promise<void> {
* @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;
Expand Down
13 changes: 8 additions & 5 deletions src/components/playbackManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
3flex marked this conversation as resolved.
Show resolved Hide resolved

audioStreamIndex: number | null;
subtitleStreamIndex: number | null;
mediaSource: MediaSourceInfo | null;
mediaSourceId: string;
mediaSourceId: string | null;
PlaybackMediaSource: MediaSourceInfo | null;

playMethod: PlayMethod | undefined;
Expand All @@ -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
Expand Down Expand Up @@ -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);

Expand Down
31 changes: 18 additions & 13 deletions src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -106,17 +107,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
3flex marked this conversation as resolved.
Show resolved Hide resolved
interface MediaInformationCustomData
extends JellyfinMediaInformationCustomData {}
}

interface JellyfinMediaInformationCustomData {
audioStreamIndex: number | null;
canClientSeek: boolean;
canSeek: boolean;
itemId: string | undefined;
liveStreamId: string | null;
mediaSourceId: string | null;
playMethod: PlayMethod;
playSessionId: string;
runtimeTicks: number | null;
startPositionTicks: number;
subtitleStreamIndex: number | null;
}