feat(streamer): react views ported from prototype with sse hooks
This commit is contained in:
parent
870a41a2f7
commit
e0d93b03ae
9 changed files with 672 additions and 0 deletions
10
streamer/src/views/shared/useElapsed.ts
Normal file
10
streamer/src/views/shared/useElapsed.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import { useEffect, useState } from "react";
|
||||
|
||||
export function useElapsed(startedAt: number, duration: number): number {
|
||||
const [now, setNow] = useState(() => Date.now() / 1000);
|
||||
useEffect(() => {
|
||||
const t = setInterval(() => setNow(Date.now() / 1000), 200);
|
||||
return () => clearInterval(t);
|
||||
}, []);
|
||||
return Math.min(duration, Math.max(0, now - startedAt));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue