-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(plex): Refactor player state to allow for drift and tracking paus…
…e based on Source behavior Plex only updates player position every 15 seconds (of played track) so player state needs to be adapted to not detect this as a pause or seek. * Allow per-source drift allowed before triggering seek * Allow per-source pause detection
- Loading branch information
Showing
7 changed files
with
94 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Logger } from "@foxxmd/logging"; | ||
import { PlayPlatformId, REPORTED_PLAYER_STATUSES } from "../../common/infrastructure/Atomic.js"; | ||
import { AbstractPlayerState, PlayerStateOptions } from "./AbstractPlayerState.js"; | ||
import { GenericPlayerState } from "./GenericPlayerState.js"; | ||
|
||
export class PlexPlayerState extends GenericPlayerState { | ||
constructor(logger: Logger, platformId: PlayPlatformId, opts?: PlayerStateOptions) { | ||
super(logger, platformId, opts); | ||
this.allowedDrift = 17000; | ||
} | ||
|
||
protected isSessionStillPlaying(position: number): boolean { | ||
return this.reportedStatus === REPORTED_PLAYER_STATUSES.playing; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { childLogger, Logger } from "@foxxmd/logging"; | ||
import { SimpleIntervalJob, Task, ToadScheduler } from "toad-scheduler"; | ||
|
||
const RT_TICK = 500; | ||
|
||
abstract class RealtimePlayer { | ||
|
||
logger: Logger; | ||
scheduler: ToadScheduler = new ToadScheduler(); | ||
|
||
protected position: number = 0; | ||
|
||
protected constructor(logger: Logger) { | ||
this.logger = childLogger(logger, `RT`); | ||
const job = new SimpleIntervalJob({ | ||
milliseconds: RT_TICK, | ||
runImmediately: true | ||
}, new Task('updatePos', () => this.position += RT_TICK), { id: 'rt' }); | ||
this.scheduler.addSimpleIntervalJob(job); | ||
this.scheduler.stop(); | ||
} | ||
|
||
public play(position?: number) { | ||
if (position !== undefined) { | ||
this.position = position; | ||
} | ||
this.scheduler.startById('rt'); | ||
} | ||
|
||
public pause() { | ||
this.scheduler.stop(); | ||
} | ||
|
||
public stop() { | ||
this.pause(); | ||
this.position = 0; | ||
} | ||
|
||
public seek(position: number) { | ||
this.position = position; | ||
} | ||
|
||
public getPosition() { | ||
return this.position; | ||
} | ||
} | ||
|
||
export class GenericRealtimePlayer extends RealtimePlayer {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters