Media servers only learn the position when the player checks in (~10s), so a poll can return an old number. A position up to 12s behind our running estimate is now treated as stale; positions ahead, or further behind (a rewind), are taken as-is. Phone-reported positions are exact and always taken. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MzFywujuH9TiuXbr9vjoX8
This commit is contained in:
@@ -84,6 +84,33 @@ describe('realigning progress bars', () => {
|
||||
expect(later!.progressMs).toBeGreaterThanOrEqual(124_000);
|
||||
});
|
||||
|
||||
it('ignores a Plex position that is only a little behind (stale), but believes rewinds and jumps ahead', async () => {
|
||||
const { user } = await createUser(app(), 'alice');
|
||||
await applyPollResult(user.id, 'plex', playing(30_000));
|
||||
const ago = (ms: number) =>
|
||||
db.update(schema.nowPlaying).set({ updatedAt: new Date(Date.now() - ms) }).where(eq(schema.nowPlaying.userId, user.id));
|
||||
const stored = async () => (await db.select().from(schema.nowPlaying).where(eq(schema.nowPlaying.userId, user.id)))[0]!.progressMs!;
|
||||
|
||||
await ago(10_000); // we'd expect ~40s now; Plex still says 33s
|
||||
await applyPollResult(user.id, 'plex', playing(33_000));
|
||||
expect(await stored()).toBeGreaterThanOrEqual(40_000);
|
||||
|
||||
await ago(0);
|
||||
await applyPollResult(user.id, 'plex', playing(5_000)); // rewound to near the start
|
||||
expect(await stored()).toBe(5_000);
|
||||
|
||||
await applyPollResult(user.id, 'plex', playing(90_000)); // skipped ahead
|
||||
expect(await stored()).toBe(90_000);
|
||||
});
|
||||
|
||||
it('takes phone-reported positions as they are', async () => {
|
||||
const { user } = await createUser(app(), 'alice');
|
||||
await applyPollResult(user.id, 'android_media_session', playing(30_000));
|
||||
await applyPollResult(user.id, 'android_media_session', playing(25_000));
|
||||
const [np] = await db.select().from(schema.nowPlaying).where(eq(schema.nowPlaying.userId, user.id));
|
||||
expect(np!.progressMs).toBe(25_000);
|
||||
});
|
||||
|
||||
it("doesn't send anything extra for sources without a position", async () => {
|
||||
const { user } = await createUser(app(), 'alice');
|
||||
await applyPollResult(user.id, 'lastfm', playing(null));
|
||||
|
||||
Reference in New Issue
Block a user