Skip to content

Commit

Permalink
Merge pull request #715 from 3flex/custom-data
Browse files Browse the repository at this point in the history
Create interface to hold custom data received from cast sender
  • Loading branch information
nielsvanvelzen authored Nov 26, 2024
2 parents 6cd22fa + 634ce46 commit d0a8c9a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
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;

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
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;
}

0 comments on commit d0a8c9a

Please sign in to comment.