feat(rerun): retain live playback and recover isolated viewer resources

This commit is contained in:
DCCONSTRUCTIONS
2026-11-04 00:42:54 +03:00
parent 669ada973f
commit 7a3c3c00b3
28 changed files with 1414 additions and 262 deletions
@@ -0,0 +1,21 @@
import {useEffect,useRef,useState} from 'react';
import type {LiveRerunViewer} from './rerunHost';
import {emptyLivePlayback,liveRerunPlayback} from './liveRerunPlayback';
export function useLiveRerunPlayback(viewer:LiveRerunViewer|null,acquisition:string){
const controller=useRef<ReturnType<typeof liveRerunPlayback>|null>(null);
const [state,setState]=useState(emptyLivePlayback);
useEffect(()=>{
setState(emptyLivePlayback);
if(!viewer)return;
const current=liveRerunPlayback(viewer);controller.current=current;
const poll=()=>{try{setState(current.read());}catch{/* Native recording may be between frames. */}};
poll();const timer=setInterval(poll,250);
return()=>{clearInterval(timer);if(controller.current===current)controller.current=null;};
},[viewer,acquisition]);
const update=(action:(value:NonNullable<typeof controller.current>)=>typeof state)=>{
const current=controller.current;if(!current)return;
try{setState(action(current));}catch{/* Teardown does not own acquisition control. */}
};
return {state,seek:(time:number)=>update(c=>c.seek(time)),setPlaying:(playing:boolean)=>update(c=>c.setPlaying(playing)),jumpToLive:()=>update(c=>c.jumpToLive())};
}