Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat: Transcription status client side check interval
Richie McIlroyf078b6cbb804
diff --git a/apps/web/app/s/[videoId]/_components/ShareVideo.tsx b/apps/web/app/s/[videoId]/_components/ShareVideo.tsxindex 912a4f52b..bfcf4e186 100644--- a/apps/web/app/s/[videoId]/_components/ShareVideo.tsx+++ b/apps/web/app/s/[videoId]/_components/ShareVideo.tsx@@ -13,6 +13,8 @@ import { LogoSpinner } from "@cap/ui";import { userSelectProps } from "@cap/database/auth/session";import { Tooltip } from "react-tooltip";import { fromVtt, Subtitle } from "subtitles-parser-vtt";+import { is } from "drizzle-orm";+import toast from "react-hot-toast";declare global {interface Window {@@ -47,6 +49,9 @@ export const ShareVideo = ({const [overlayVisible, setOverlayVisible] = useState(true);const [subtitles, setSubtitles] = useState<Subtitle[]>([]);const [subtitlesVisible, setSubtitlesVisible] = useState(true);+ const [isTranscriptionProcessing, setIsTranscriptionProcessing] =+ useState(false);+const [videoSpeed, setVideoSpeed] = useState(1);const overlayTimeoutRef = useRef<NodeJS.Timeout | null>(null);@@ -267,15 +272,35 @@ export const ShareVideo = ({};useEffect(() => {- if (data.transcriptionStatus !== "COMPLETE") return;-- fetch(`https://v.cap.so/${data.ownerId}/${data.id}/transcription.vtt`)- .then((response) => response.text())- .then((text) => {- const parsedSubtitles = fromVtt(text);- console.log("Parsed subtitles:", parsedSubtitles);- setSubtitles(parsedSubtitles);- });+ const fetchSubtitles = () => {+ fetch(`https://v.cap.so/${data.ownerId}/${data.id}/transcription.vtt`)+ .then((response) => response.text())+ .then((text) => {+ const parsedSubtitles = fromVtt(text);+ setSubtitles(parsedSubtitles);+ });+ };++ if (data.transcriptionStatus === "COMPLETE") {+ fetchSubtitles();+ } else {+ const intervalId = setInterval(() => {+ fetch(`/api/video/transcribe/status?videoId=${data.id}`)+ .then((response) => response.json())+ .then(({ transcriptionStatus }) => {+ if (transcriptionStatus === "PROCESSING") {+ setIsTranscriptionProcessing(true);+ } else if (transcriptionStatus === "COMPLETE") {+ fetchSubtitles();+ clearInterval(intervalId);+ } else if (transcriptionStatus === "FAILED") {+ clearInterval(intervalId);+ }+ });+ }, 1000);++ return () => clearInterval(intervalId);+ }}, [data]);const currentSubtitle = subtitles.find(@@ -439,7 +464,7 @@ export const ShareVideo = ({<div className="flex items-center justify-end space-x-2"><span className="inline-flex"><button- aria-label="Change video speed"+ aria-label={`Change video speed to ${videoSpeed}x`}className=" inline-flex min-w-[45px] items-center text-sm font-medium transition ease-in-out duration-150 focus:outline-none border text-slate-100 border-transparent hover:text-white focus:border-white hover:bg-slate-100 hover:bg-opacity-10 active:bg-slate-100 active:bg-opacity-10 px-2 py-2 justify-center rounded-lg"tabIndex={0}type="button"@@ -448,57 +473,96 @@ export const ShareVideo = ({{videoSpeed}x</button></span>- {data.transcriptionStatus === "COMPLETE" &&- subtitles.length > 0 && (- <span className="inline-flex">- <button- aria-label="Disable subtitles"- className=" inline-flex items-center text-sm font-medium transition ease-in-out duration-150 focus:outline-none border text-slate-100 border-transparent hover:text-white focus:border-white hover:bg-slate-100 hover:bg-opacity-10 active:bg-slate-100 active:bg-opacity-10 px-2 py-2 justify-center rounded-lg"- tabIndex={0}- type="button"- onClick={() => setSubtitlesVisible(!subtitlesVisible)}+ {isTranscriptionProcessing && subtitles.length === 0 && (+ <span className="inline-flex">+ <button+ aria-label={isPlaying ? "Pause video" : "Play video"}+ className=" inline-flex items-center text-sm font-medium transition ease-in-out duration-150 focus:outline-none border text-slate-100 border-transparent hover:text-white focus:border-white hover:bg-slate-100 hover:bg-opacity-10 active:bg-slate-100 active:bg-opacity-10 px-2 py-2 justify-center rounded-lg"+ tabIndex={0}+ type="button"+ onClick={() => {+ toast.error("Transcription is processing");+ }}+ >+ <svg+ xmlns="http://www.w3.org/2000/svg"+ className="w-6 h-6"+ viewBox="0 0 24 24">- {subtitlesVisible ? (- <svg- xmlns="http://www.w3.org/2000/svg"- fill="none"- stroke="currentColor"- strokeLinecap="round"- strokeLinejoin="round"- strokeWidth="2"- className="w-auto h-6"- viewBox="0 0 24 24"- >- <rect- width="18"- height="14"- x="3"- y="5"- rx="2"- ry="2"- ></rect>- <path d="M7 15h4m4 0h2M7 11h2m4 0h4"></path>- </svg>- ) : (- <svg- xmlns="http://www.w3.org/2000/svg"- fill="none"- stroke="currentColor"- strokeLinecap="round"- strokeLinejoin="round"- strokeWidth="2"- className="w-auto h-6"- viewBox="0 0 24 24"- >- <path d="M10.5 5H19a2 2 0 012 2v8.5M17 11h-.5M19 19H5a2 2 0 01-2-2V7a2 2 0 012-2M2 2l20 20M7 11h4M7 15h2.5"></path>- </svg>- )}- </button>- </span>- )}+ <style>+ {+ "@keyframes spinner_AtaB{to{transform:rotate(360deg)}}"+ }+ </style>+ <path+ fill="#FFF"+ d="M12 1a11 11 0 1 0 11 11A11 11 0 0 0 12 1Zm0 19a8 8 0 1 1 8-8 8 8 0 0 1-8 8Z"+ opacity={0.25}+ />+ <path+ fill="#FFF"+ d="M10.14 1.16a11 11 0 0 0-9 8.92A1.59 1.59 0 0 0 2.46 12a1.52 1.52 0 0 0 1.65-1.3 8 8 0 0 1 6.66-6.61A1.42 1.42 0 0 0 12 2.69a1.57 1.57 0 0 0-1.86-1.53Z"+ style={{+ transformOrigin: "center",+ animation: "spinner_AtaB .75s infinite linear",+ }}+ />+ </svg>+ </button>+ </span>+ )}+ {subtitles.length > 0 && (+ <span className="inline-flex">+ <button+ aria-label={+ subtitlesVisible ? "Hide subtitles" : "Show subtitles"+ }+ className=" inline-flex items-center text-sm font-medium transition ease-in-out duration-150 focus:outline-none border text-slate-100 border-transparent hover:text-white focus:border-white hover:bg-slate-100 hover:bg-opacity-10 active:bg-slate-100 active:bg-opacity-10 px-2 py-2 justify-center rounded-lg"+ tabIndex={0}+ type="button"+ onClick={() => setSubtitlesVisible(!subtitlesVisible)}+ >+ {subtitlesVisible ? (+ <svg+ xmlns="http://www.w3.org/2000/svg"+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="2"+ className="w-auto h-6"+ viewBox="0 0 24 24"+ >+ <rect+ width="18"+ height="14"+ x="3"+ y="5"+ rx="2"+ ry="2"+ ></rect>+ <path d="M7 15h4m4 0h2M7 11h2m4 0h4"></path>+ </svg>+ ) : (+ <svg+ xmlns="http://www.w3.org/2000/svg"+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="2"+ className="w-auto h-6"+ viewBox="0 0 24 24"+ >+ <path d="M10.5 5H19a2 2 0 012 2v8.5M17 11h-.5M19 19H5a2 2 0 01-2-2V7a2 2 0 012-2M2 2l20 20M7 11h4M7 15h2.5"></path>+ </svg>+ )}+ </button>+ </span>+ )}<span className="inline-flex"><button- aria-label="Mute video"+ aria-label={videoRef?.current?.muted ? "Unmute" : "Mute"}className=" inline-flex items-center text-sm font-medium transition ease-in-out duration-150 focus:outline-none border text-slate-100 border-transparent hover:text-white focus:border-white hover:bg-slate-100 hover:bg-opacity-10 active:bg-slate-100 active:bg-opacity-10 px-2 py-2 justify-center rounded-lg"tabIndex={0}type="button"