fix(syncplay): report latency pings for timely commands
Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
SyncPlay expects Ping as a latency in milliseconds, not a timestamp. Date.now() was clamped to 10s and delayed scheduled unpause/seek commands. Send a 50 ms latency every 3 seconds while in a group.
This commit is contained in:
1 parent
31826f1098
commit
e89932fc7d
2 files changed
+27
-1
No files matched your search
@@ -1,7 +1,10 @@
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import React, { useEffect } from "react";
|
||||
import { getLocalPlayback } from "@/utils/methods/localPlayback";
|
||||
import { reportSyncPlayReady } from "@/utils/methods/syncPlay";
|
||||
import {
|
||||
pingSyncPlayGroup,
|
||||
reportSyncPlayReady,
|
||||
} from "@/utils/methods/syncPlay";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
import useSyncPlayStore from "@/utils/store/syncPlay";
|
||||
@@ -28,6 +31,16 @@ const SyncPlayController = () => {
|
||||
});
|
||||
}, [pendingNavigation, setPendingNavigation, navigate]);
|
||||
|
||||
// SyncPlay uses pings to estimate latency and schedule unpause commands.
|
||||
useEffect(() => {
|
||||
if (!api || !group?.GroupId) return;
|
||||
void pingSyncPlayGroup(api);
|
||||
const timer = window.setInterval(() => {
|
||||
void pingSyncPlayGroup(api);
|
||||
}, 3000);
|
||||
return () => window.clearInterval(timer);
|
||||
}, [api, group?.GroupId]);
|
||||
|
||||
// While a group is waiting, keep telling the server this player is ready.
|
||||
// Some clients miss the one-shot Ready after a queue update; retrying is
|
||||
// harmless and lets the server release the group as soon as it can.
|
||||
|
||||
@@ -219,6 +219,19 @@ export const pauseSyncPlayGroup = async (api: Api) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const pingSyncPlayGroup = async (api: Api) => {
|
||||
try {
|
||||
await syncApi(api).syncPlayPing({
|
||||
// This is the measured latency in milliseconds, not a timestamp.
|
||||
// The server clamps it to 10s; a huge value would delay every
|
||||
// scheduled pause/unpause, so report a conservative local value.
|
||||
pingRequestDto: { Ping: 50 },
|
||||
});
|
||||
} catch (error) {
|
||||
console.warn("Could not ping SyncPlay group", error);
|
||||
}
|
||||
};
|
||||
|
||||
export const resumeSyncPlayGroup = async (api: Api) => {
|
||||
try {
|
||||
await syncApi(api).syncPlayUnpause();
|
||||
|
||||
Reference in new issue
Block a user