Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
perf(web): make the transcript feel instant at share-page land
Richie McIlroyaa43f4782f53
diff --git a/apps/web/hooks/use-live-transcript.ts b/apps/web/hooks/use-live-transcript.tsindex 1d8bcac99..de689aae2 100644--- a/apps/web/hooks/use-live-transcript.ts+++ b/apps/web/hooks/use-live-transcript.ts@@ -15,6 +15,9 @@ export type LiveTranscriptData =/** The server said nothing will ever appear for us — stop polling. */| { kind: "stopped" };+/** No content yet — the viewer just landed, likely right after recording+ * stop; poll fast so the transcript appears the moment the tail chunk lands. */+const PENDING_POLL_INTERVAL = 2000;/** Live transcription is still appending; poll often enough to feel live. */const ACTIVE_POLL_INTERVAL = 5000;/** Live transcription finished; the canonical transcript supersedes it@@ -47,10 +50,12 @@ export const useLiveTranscript = (videoId: Video.VideoId, enabled: boolean) => {refetchInterval: (query) => {const data = query.state.data;if (data?.kind === "stopped") return false;- if (data?.kind === "ready" && data.state !== "active") {- return SETTLED_POLL_INTERVAL;+ if (data?.kind === "ready") {+ return data.state === "active"+ ? ACTIVE_POLL_INTERVAL+ : SETTLED_POLL_INTERVAL;}- return ACTIVE_POLL_INTERVAL;+ return PENDING_POLL_INTERVAL;},refetchIntervalInBackground: false,staleTime: 0,diff --git a/apps/web/lib/live-transcribe-core.ts b/apps/web/lib/live-transcribe-core.tsindex fb2e65440..fa59a3f9b 100644--- a/apps/web/lib/live-transcribe-core.ts+++ b/apps/web/lib/live-transcribe-core.ts@@ -15,18 +15,20 @@ import { planSegmentsAudioExtraction } from "@/lib/segments-audio";*/export const LIVE_TRANSCRIBE = {- /** Chunk window while the recording is young — favors low latency. */- INITIAL_CHUNK_SECONDS: 15,- /** Chunk window after GROW_AFTER_CHUNKS — favors fewer, cheaper calls. */- MAX_CHUNK_SECONDS: 30,- GROW_AFTER_CHUNKS: 6,+ /** First chunk fires fast so a transcript exists almost immediately. */+ INITIAL_CHUNK_SECONDS: 5,+ /** Steady-state window. Small on purpose: the untranscribed tail at stop+ * averages half this, and that tail is all that stands between "stop" and+ * a complete transcript on the share page. */+ MAX_CHUNK_SECONDS: 10,+ GROW_AFTER_CHUNKS: 2,/** Catch-up bound: one chunk never covers more audio than this. */MAX_CHUNK_TAKE_SECONDS: 60,/** Hard cost cap: stop live-transcribing after this much audio; the* canonical post-stop transcription covers the full recording anyway. */MAX_TRANSCRIBED_SECONDS: 60 * 60,- /** Hard backstop on chunk count (MAX_TRANSCRIBED / INITIAL implies ~240). */- MAX_CHUNKS: 300,+ /** Hard backstop on chunk count (1h at 10s windows = 360). */+ MAX_CHUNKS: 420,POLL_INTERVAL_MS: 3_000,/** One waiting step holds its invocation at most this long. */MAX_POLL_MS_PER_STEP: 120_000,