Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
Revert
Richie McIlroy7f2e69f00421
diff --git a/apps/web/app/api/playlist/route.ts b/apps/web/app/api/playlist/route.tsindex a4077db65..6ed96cb94 100644--- a/apps/web/app/api/playlist/route.ts+++ b/apps/web/app/api/playlist/route.ts@@ -85,72 +85,11 @@ export async function GET(request: NextRequest) {if (!bucket || video.awsBucket === clientEnv.NEXT_PUBLIC_CAP_AWS_BUCKET) {if (video.source.type === "desktopMP4") {- if (videoType === "mp4") {- // Add specific headers for MP4 videos to enable embedding- const playlistUrl = await getSignedUrl(- s3Client,- new GetObjectCommand({- Bucket,- Key: `${userId}/${videoId}/result.mp4`,- }),- { expiresIn: 3600 }- );-- // Set very permissive CORS headers to ensure cross-origin access works- const corsHeaders = {- "Access-Control-Allow-Origin": "*",- "Access-Control-Allow-Methods": "GET, HEAD, OPTIONS",- "Access-Control-Allow-Headers": "Content-Type, Authorization, Range, X-Requested-With",- "Access-Control-Expose-Headers": "Content-Length, Content-Range, Accept-Ranges",- "Content-Type": "video/mp4",- "X-Content-Type-Options": "nosniff",- "Access-Control-Max-Age": "86400",- ...CACHE_CONTROL_HEADERS,- };-- // Always proxy the content to avoid CORS issues with S3- try {- // Proxy the S3 content through our API to avoid CORS issues- const s3Response = await fetch(playlistUrl);-- if (!s3Response.ok) {- console.error(`S3 responded with ${s3Response.status}: ${s3Response.statusText}`);- throw new Error(`S3 error: ${s3Response.status}`);- }-- const data = await s3Response.arrayBuffer();-- return new Response(data, {- status: 200,- headers: corsHeaders- });- } catch (error) {- console.error("Error proxying S3 content:", error);- // Fall back to redirect if proxying fails- return new Response(null, {- status: 302,- headers: {- ...corsHeaders,- Location: playlistUrl,- },- });- }- }-- const playlistUrl = await getSignedUrl(- s3Client,- new GetObjectCommand({- Bucket,- Key: `${userId}/${videoId}/result.mp4`,- }),- { expiresIn: 3600 }- );-return new Response(null, {status: 302,headers: {...getHeaders(origin),- Location: playlistUrl,+ Location: `${S3_BUCKET_URL}/${userId}/${videoId}/result.mp4`,...CACHE_CONTROL_HEADERS,},});diff --git a/apps/web/app/s/[videoId]/_components/MP4VideoPlayer.tsx b/apps/web/app/s/[videoId]/_components/MP4VideoPlayer.tsxindex 863823faf..bdf8ffd9a 100644--- a/apps/web/app/s/[videoId]/_components/MP4VideoPlayer.tsx+++ b/apps/web/app/s/[videoId]/_components/MP4VideoPlayer.tsx@@ -7,7 +7,6 @@ import {useRef,useState,} from "react";-import { clientEnv } from "@cap/env";interface MP4VideoPlayerProps {videoSrc: string;@@ -23,34 +22,9 @@ export const MP4VideoPlayer = memo(const [isLoaded, setIsLoaded] = useState(false);const [currentSrc, setCurrentSrc] = useState(videoSrc);const lastAttemptTime = useRef<number>(Date.now());- const [thumbnailSrc, setThumbnailSrc] = useState<string | undefined>(- undefined- );useImperativeHandle(ref, () => videoRef.current as HTMLVideoElement);- // Extract userId and videoId from the URL- const userId = videoSrc.split("userId=")[1]?.split("&")[0];- const videoId = videoSrc.split("videoId=")[1]?.split("&")[0];-- // Fetch the thumbnail- useEffect(() => {- if (userId && videoId) {- fetch(- `${clientEnv.NEXT_PUBLIC_WEB_URL}/api/thumbnail?userId=${userId}&videoId=${videoId}`- )- .then((response) => response.json())- .then((data) => {- if (data.screen) {- setThumbnailSrc(data.screen);- }- })- .catch((error) => {- console.error("Error fetching thumbnail:", error);- });- }- }, [userId, videoId]);-const fetchNewUrl = useCallback(async () => {try {// Add timestamp to prevent caching@@ -59,19 +33,23 @@ export const MP4VideoPlayer = memo(? `${videoSrc}&_t=${timestamp}`: `${videoSrc}?_t=${timestamp}`;- // With the updated API, we can now use the original URL directly- // Our API proxies the content rather than redirecting- setCurrentSrc(urlWithTimestamp);- return urlWithTimestamp;+ const response = await fetch(urlWithTimestamp, { method: "HEAD" });++ if (response.redirected) {+ // If the API redirected us, use the redirected URL+ setCurrentSrc(response.url);+ return response.url;+ } else {+ // If no redirect (which is unusual for desktopMP4), just use the original URL+ return urlWithTimestamp;+ }} catch (error) {- console.error("Error updating video URL:", error);- // Return the original URL with timestamp if anything fails+ console.error("Error fetching new video URL:", error);+ // Return the original URL with timestamp if fetch failsconst timestamp = new Date().getTime();- const fallbackUrl = videoSrc.includes("?")+ return videoSrc.includes("?")? `${videoSrc}&_t=${timestamp}`: `${videoSrc}?_t=${timestamp}`;- setCurrentSrc(fallbackUrl);- return fallbackUrl;}}, [videoSrc]);@@ -251,8 +229,6 @@ export const MP4VideoPlayer = memo(playsInlinecontrols={false}muted- crossOrigin="anonymous"- poster={thumbnailSrc}><source src={currentSrc} type="video/mp4" /></video>diff --git a/apps/web/app/s/[videoId]/_components/ShareVideo.tsx b/apps/web/app/s/[videoId]/_components/ShareVideo.tsxindex 3a08d5ce9..ebcc5c6a5 100644--- a/apps/web/app/s/[videoId]/_components/ShareVideo.tsx+++ b/apps/web/app/s/[videoId]/_components/ShareVideo.tsx@@ -221,20 +221,13 @@ export const ShareVideo = forwardRef<if (videoRef.current) {setLongestDuration(videoRef.current.duration);setVideoMetadataLoaded(true);-- // If we have the metadata, we should be able to display the poster frame- // even if the video isn't fully playable yet- setTimeout(() => {- // Set a timeout to reduce flicker between black screen and poster- setIsLoading(false);- }, 100);+ // Don't set isLoading to false here}};const onCanPlay = () => {setVideoMetadataLoaded(true);setVideoReadyToPlay(true);- setIsLoading(false); // Ensure loading is false once playable// If the video is already playing (user clicked play before it was ready),// ensure it actually starts playing now@@ -251,6 +244,11 @@ export const ShareVideo = forwardRef<videoRef.current.currentTime = currentPosition;}}++ // Set a small delay before removing the loading state to ensure smooth transition+ setTimeout(() => {+ setIsLoading(false);+ }, 100);};const videoElement = videoRef.current;@@ -268,7 +266,7 @@ export const ShareVideo = forwardRef<videoElement.removeEventListener("canplay", onCanPlay);}};- }, [isPlaying]);+ }, []);const handlePlayPauseClick = async () => {const videoElement = videoRef.current;@@ -1054,14 +1052,14 @@ export const ShareVideo = forwardRef<className="overflow-hidden relative w-full h-full rounded-lg shadow-lg group"><div- className={`absolute inset-0 flex items-center justify-center z-10 bg-black/50 transition-opacity duration-300 ${+ className={`absolute inset-0 flex items-center justify-center z-10 bg-black transition-opacity duration-300 ${isLoading ? "opacity-100" : "opacity-0 pointer-events-none"}`}><LogoSpinner className="w-8 h-auto animate-spin sm:w-10" /></div><div className="relative w-full h-full">- <div className="absolute inset-0">+ <div className="absolute inset-0 bg-black">{data.source.type === "desktopMP4" ? (<MP4VideoPlayer ref={videoRef} videoSrc={videoSrc} />) : (diff --git a/apps/web/app/s/[videoId]/page.tsx b/apps/web/app/s/[videoId]/page.tsxindex c2471fc93..744e9224e 100644--- a/apps/web/app/s/[videoId]/page.tsx+++ b/apps/web/app/s/[videoId]/page.tsx@@ -81,15 +81,6 @@ export async function generateMetadata(};}- // Get thumbnail URL- const thumbnailUrl = `${clientEnv.NEXT_PUBLIC_WEB_URL}/api/video/og?videoId=${videoId}`;-- // Get direct MP4 URL- const videoUrl = `${clientEnv.NEXT_PUBLIC_WEB_URL}/api/playlist?userId=${video.ownerId}&videoId=${video.id}&videoType=mp4`;-- // Full page URL for embedding- const pageUrl = `${clientEnv.NEXT_PUBLIC_WEB_URL}/s/${videoId}`;-console.log("[generateMetadata] Returning public metadata for video:",video.name@@ -98,58 +89,10 @@ export async function generateMetadata(title: video.name + " | Cap Recording",description: "Watch this video on Cap",openGraph: {- title: video.name,- description: "Watch this video on Cap",- url: pageUrl,- images: [thumbnailUrl],- type: "video.other",- videos: [- {- url: videoUrl,- width: 1280,- height: 720,- type: "video/mp4",- },- ],- },- twitter: {- card: "player",- site: "@cap_hq",- title: video.name,- description: "Watch this video on Cap",- images: [thumbnailUrl],- players: [- {- playerUrl: pageUrl,- streamUrl: videoUrl,- width: 1280,- height: 720,- },+ images: [+ `${clientEnv.NEXT_PUBLIC_WEB_URL}/api/video/og?videoId=${videoId}`,],},- other: {- "video:duration": Math.floor(video?.metadata?.duration || 0).toString(),- "og:video:duration": Math.floor(- video?.metadata?.duration || 0- ).toString(),- "og:video:url": videoUrl,- "og:video:secure_url": videoUrl,- "og:video:type": "video/mp4",- "og:video:width": "1280",- "og:video:height": "720",- },- metadataBase: new URL(clientEnv.NEXT_PUBLIC_WEB_URL),- alternates: {- canonical: `/s/${videoId}`,- },- icons: {- icon: "/favicon.ico",- },- viewport: {- width: "device-width",- initialScale: 1,- },- assets: [thumbnailUrl],};}