Skip to content

Commit

Permalink
fix(jellyfin): Gaurd against active session without now playing data
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxxMD committed Oct 10, 2024
1 parent 9001bf1 commit c2b294f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/backend/common/infrastructure/Atomic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,13 @@ export interface ConfigMeta {

export type SourceData = (PlayObject | PlayerStateData);

export interface PlayerStateData {
platformId: PlayPlatformId
export interface PlayerStateData extends PlayerStateDataMaybePlay {
play: PlayObject
}

export interface PlayerStateDataMaybePlay {
platformId: PlayPlatformId
play?: PlayObject
status?: ReportedPlayerStatus
position?: number
timestamp?: Dayjs
Expand Down
8 changes: 6 additions & 2 deletions src/backend/sources/JellyfinApiSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
FormatPlayObjectOptions,
InternalConfig,
PlayerStateData,
PlayerStateDataMaybePlay,
PlayPlatformId, REPORTED_PLAYER_STATUSES
} from "../common/infrastructure/Atomic.js";
import { JellyApiSourceConfig } from "../common/infrastructure/config/source/jellyfin.js";
Expand Down Expand Up @@ -278,7 +279,10 @@ export default class JellyfinApiSource extends MemorySource {
//const userData = await getItemsApi(this.api).getItemUserData({itemId: 'ID', userId: this.user.Id});

const sessions = await getSessionApi(this.api).getSessions();
const nonMSSessions = sessions.data.filter(x => x.DeviceId !== this.deviceId).map(x => this.sessionToPlayerState(x)) as PlayerStateData[];
const nonMSSessions = sessions.data
.filter(x => x.DeviceId !== this.deviceId)
.map(x => this.sessionToPlayerState(x))
.filter((x: PlayerStateDataMaybePlay) => x.play !== undefined) as PlayerStateData[];
const validSessions: PlayerStateData[] = [];

for(const session of nonMSSessions) {
Expand All @@ -292,7 +296,7 @@ export default class JellyfinApiSource extends MemorySource {
return this.processRecentPlays(validSessions);
}

sessionToPlayerState = (obj: SessionInfo): PlayerStateData => {
sessionToPlayerState = (obj: SessionInfo): PlayerStateDataMaybePlay => {

const {
UserName,
Expand Down

0 comments on commit c2b294f

Please sign in to comment.