From 289ac4958d2cd0012bd427c0aa676a801e44a014 Mon Sep 17 00:00:00 2001 From: 1xDed Date: Fri, 27 Nov 2026 14:55:54 +0300 Subject: [PATCH] fix: refresh the remote session position before transfer The bar polls every 5s; re-read the session at transfer time so a recent seek or progress update is used. Remove the temporary dev test harness. --- src/utils/methods/transferPlayback.ts | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/utils/methods/transferPlayback.ts b/src/utils/methods/transferPlayback.ts index bf0bc12..5aad17a 100644 --- a/src/utils/methods/transferPlayback.ts +++ b/src/utils/methods/transferPlayback.ts @@ -30,17 +30,33 @@ export const transferSessionToLocal = async ( userId: string | undefined, session: SessionInfoDto, ): Promise<"audio" | "video" | "none"> => { - const item = session.NowPlayingItem; - if (!api || !userId || !item?.Id || !session.Id) { + if (!api || !userId || !session.Id) { return "none"; } - const positionTicks = session.PlayState?.PositionTicks ?? 0; + // The bar/dialog polls sessions every few seconds; refresh the target so a + // seek made in the meantime is reflected in the transfer position. + let currentSession = session; + try { + const fresh = (await getSessionApi(api).getSessions()).data.find( + (entry) => entry.Id === session.Id, + ); + if (fresh) currentSession = fresh; + } catch (error) { + console.warn("Could not refresh the remote session", error); + } + + const item = currentSession.NowPlayingItem; + if (!item?.Id) { + return "none"; + } + + const positionTicks = currentSession.PlayState?.PositionTicks ?? 0; // Rebuild the remote queue when the server reports it. let queue: BaseItemDto[] = [item]; let queueIndex = 0; - const queueIds = (session.NowPlayingQueue ?? []) + const queueIds = (currentSession.NowPlayingQueue ?? []) .map((queueItem) => queueItem.Id) .filter((id): id is string => Boolean(id)); if (queueIds.length > 0) { @@ -107,7 +123,7 @@ export const transferSessionToLocal = async ( // Transfer, not cast: the remote device should stop. try { await getSessionApi(api).sendPlaystateCommand({ - sessionId: session.Id, + sessionId: currentSession.Id, command: "Stop", controllingUserId: userId, });