bandwidth savings configs

This commit is contained in:
legop3
2026-07-14 17:04:08 -04:00
parent 1c401ff90a
commit 0d6b4d68de
21 changed files with 424 additions and 39 deletions
+10 -1
View File
@@ -9,6 +9,9 @@ export function useDriverVideoModePolicy(roverId) {
const turnQueues = useSessionSelector((state) => state.session?.turnQueues ?? {});
const socketId = useSessionSelector((state) => state.session?.socketId || null);
const activeDrivers = useSessionSelector((state) => state.session?.activeDrivers ?? {});
const nonTurnVideoPolicy = useSessionSelector(
(state) => state.session?.bandwidthSavings?.nonTurnVideo || 'snapshots',
);
const isTurnsMode = mode === 'turns';
/*
This policy only switches preview/full video around a multi-second turn
@@ -43,7 +46,13 @@ export function useDriverVideoModePolicy(roverId) {
});
return unique.size;
}, [users]);
const shouldUsePreviewByLoad = isTurnsMode && totalDrivers > totalRovers;
/*
The server sends the bandwidth policy because the same rule is enforced in
video authorization. The hook only mirrors that policy so the UI avoids
requesting live video when snapshots are the intended non-turn experience.
*/
const shouldUsePreviewByLoad =
nonTurnVideoPolicy === 'snapshots' && isTurnsMode && totalDrivers > totalRovers;
const isPreSwitchWindow =
isTurnsMode && isNextDriver && msUntilTurn != null && msUntilTurn <= 5000 && msUntilTurn > 0;
const showNotTurnNotice = isTurnsMode && !isActiveDriver;
+11 -1
View File
@@ -6,6 +6,7 @@ import { useSession } from '../context/SessionContext.jsx';
export function useSpectatorMode() {
const { session, setRole, subscribeAll, connected } = useSession();
const [ready, setReady] = useState(false);
const canUseSpectatorAccess = session?.bandwidthSavings?.canUseExternalSpectatorAccess !== false;
useEffect(() => {
let cancelled = false;
@@ -14,6 +15,15 @@ export function useSpectatorMode() {
setReady(false);
return;
}
if (!canUseSpectatorAccess) {
/*
The server will reject the role change too, but stopping here prevents
a blocked external spectator from retrying on every session sync while
the page is intentionally waiting for an admin grant or config change.
*/
setReady(false);
return;
}
try {
if (session?.role !== 'spectator') {
await setRole('spectator');
@@ -33,7 +43,7 @@ export function useSpectatorMode() {
return () => {
cancelled = true;
};
}, [connected, session?.mode, session?.role, setRole, subscribeAll]);
}, [canUseSpectatorAccess, connected, session?.mode, session?.role, setRole, subscribeAll]);
return ready;
}