Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

wip: Emoji reactions, fixed thumbnail colour

Richie McIlroyce125a042e07
diff --git a/apps/desktop/src-tauri/src/media.rs b/apps/desktop/src-tauri/src/media.rs
index bb9f1d90d..cf82f63c8 100644
--- a/apps/desktop/src-tauri/src/media.rs
+++ b/apps/desktop/src-tauri/src/media.rs
@@ -282,10 +282,17 @@ impl MediaRecorder {
if let Ok(frame) = capturer.frame() {
screenshot_captured = true;
let path = Path::new(&screenshot_file_path_owned);
+ let mut rgba_frame: Vec<u8> = vec![0; frame.len()];
+ for (i, chunk) in frame.chunks_exact(4).enumerate() {
+ rgba_frame[i * 4] = chunk[2];
+ rgba_frame[i * 4 + 1] = chunk[1];
+ rgba_frame[i * 4 + 2] = chunk[0];
+ rgba_frame[i * 4 + 3] = chunk[3];
+ }
let image: ImageBuffer<Rgba<u8>, Vec<u8>> = ImageBuffer::from_raw(
w.try_into().unwrap(),
adjusted_height.try_into().unwrap(),
- frame.to_vec()
+ rgba_frame
).expect("Failed to create image buffer");
image.save_with_format(&path, image::ImageFormat::Jpeg).expect("Failed to save screenshot");
diff --git a/apps/desktop/src-tauri/src/recording.rs b/apps/desktop/src-tauri/src/recording.rs
index dfcc8cdd0..2305b46de 100644
--- a/apps/desktop/src-tauri/src/recording.rs
+++ b/apps/desktop/src-tauri/src/recording.rs
@@ -197,6 +197,7 @@ async fn start_upload_loop(
upload_tasks.push(tokio::spawn(async move {
let filepath_str = screenshot_path_clone.to_str().unwrap_or_default().to_owned();
println!("Uploading screenshot for {}: {}", video_type_clone, filepath_str);
+ tokio::time::sleep(Duration::from_secs(1)).await;
upload_file(Some(options_clone), filepath_str, "screenshot".to_string()).await.map(|_| ())
}));
screenshot_uploaded = true;
diff --git a/apps/web/app/api/playlist/route.ts b/apps/web/app/api/playlist/route.ts
index dba74f298..9d8e704c9 100644
--- a/apps/web/app/api/playlist/route.ts
+++ b/apps/web/app/api/playlist/route.ts
@@ -18,8 +18,6 @@ const allowedOrigins = [
"cap.link",
];
-export const revalidate = 3500;
-
export async function OPTIONS(request: NextRequest) {
const origin = request.headers.get("origin") as string;
diff --git a/apps/web/app/dashboard/_components/AdminNavbar/AdminNavItems.tsx b/apps/web/app/dashboard/_components/AdminNavbar/AdminNavItems.tsx
index 2c695c321..0228fa724 100644
--- a/apps/web/app/dashboard/_components/AdminNavbar/AdminNavItems.tsx
+++ b/apps/web/app/dashboard/_components/AdminNavbar/AdminNavItems.tsx
@@ -44,8 +44,8 @@ export const AdminNavItems = () => {
const manageNavigation = [
{ name: "My Caps", href: `/dashboard/caps`, icon: Clapperboard },
- { name: "Notifications", href: `/dashboard/notifications`, icon: Bell },
- { name: "History", href: `/dashboard/history`, icon: History },
+ // { name: "Notifications", href: `/dashboard/notifications`, icon: Bell },
+ // { name: "History", href: `/dashboard/history`, icon: History },
{ name: "Settings", href: `/dashboard/settings`, icon: Settings },
];
@@ -116,7 +116,7 @@ export const AdminNavItems = () => {
href={item.href}
className={classNames(
pathname == item.href
- ? "bg-gradient-to-l from-tertiary to-tertiary-3 ring-4 ring-tertiary-3"
+ ? "bg-gradient-to-l from-tertiary-3 to-tertiary ring-4 ring-tertiary-2"
: "opacity-75 hover:opacity-100",
navItemClass
)}
diff --git a/apps/web/app/dashboard/caps/Caps.tsx b/apps/web/app/dashboard/caps/Caps.tsx
index 2660e88ea..9b5d3c8a7 100644
--- a/apps/web/app/dashboard/caps/Caps.tsx
+++ b/apps/web/app/dashboard/caps/Caps.tsx
@@ -3,8 +3,11 @@ import { Button } from "@cap/ui";
import { videos } from "@cap/database/schema";
import moment from "moment";
import { VideoThumbnail } from "@/components/VideoThumbnail";
+import { useRouter } from "next/navigation";
export const Caps = ({ data }: { data: (typeof videos.$inferSelect)[] }) => {
+ const { push } = useRouter();
+
return (
<div className="py-12">
{data.length === 0 ? (
@@ -23,8 +26,15 @@ export const Caps = ({ data }: { data: (typeof videos.$inferSelect)[] }) => {
<p className="text-xl max-w-md">
Craft your narrative with a Capโ€”get projects done quicker.
</p>
- <Button size="default" className="mt-8" variant="default">
- Record a Cap
+ <Button
+ onClick={() => {
+ push("/download");
+ }}
+ size="default"
+ className="mt-8 relative"
+ variant="default"
+ >
+ Download Cap
</Button>
</div>
</div>
diff --git a/apps/web/app/share/[videoId]/Share.tsx b/apps/web/app/share/[videoId]/Share.tsx
index def552e2f..fcbb418fa 100644
--- a/apps/web/app/share/[videoId]/Share.tsx
+++ b/apps/web/app/share/[videoId]/Share.tsx
@@ -5,6 +5,7 @@ import { ShareHeader } from "./_components/ShareHeader";
import { ShareVideo } from "./_components/ShareVideo";
import { videos } from "@cap/database/schema";
import { userSelectProps } from "@cap/database/auth/session";
+import { Toolbar } from "./_components/Toolbar";
// million-ignore
export const Share = ({
data,
@@ -18,11 +19,16 @@ export const Share = ({
<div className="space-y-6">
<ShareHeader data={data} />
<ShareVideo data={data} />
- <div>
- <h1 className="text-2xl">{data.name}</h1>
- <p className="text-gray-400">
- about {moment(data.createdAt).fromNow()}
- </p>
+ <div className="flex items-center justify-between">
+ <div>
+ <h1 className="text-2xl">{data.name}</h1>
+ <p className="text-gray-400">
+ about {moment(data.createdAt).fromNow()}
+ </p>
+ </div>
+ <div className="flex">
+ <Toolbar />
+ </div>
</div>
</div>
</div>
diff --git a/apps/web/app/share/[videoId]/_components/ShareVideo.tsx b/apps/web/app/share/[videoId]/_components/ShareVideo.tsx
index d1e82c434..8b0b8fc46 100644
--- a/apps/web/app/share/[videoId]/_components/ShareVideo.tsx
+++ b/apps/web/app/share/[videoId]/_components/ShareVideo.tsx
@@ -13,13 +13,36 @@ const formatTime = (time: number) => {
};
export const ShareVideo = ({ data }: { data: typeof videos.$inferSelect }) => {
- const video2Ref = useRef<HTMLVideoElement>(null);
+ const videoRef = useRef<HTMLVideoElement>(null);
const [isPlaying, setIsPlaying] = useState(false);
const [currentTime, setCurrentTime] = useState(0);
const [isLoading, setIsLoading] = useState(true);
const [longestDuration, setLongestDuration] = useState(0);
const [seeking, setSeeking] = useState(false);
const [videoMetadataLoaded, setVideoMetadataLoaded] = useState(false);
+ const [overlayVisible, setOverlayVisible] = useState(true);
+ const overlayTimeoutRef = useRef<NodeJS.Timeout | null>(null);
+
+ useEffect(() => {
+ const handleMouseMove = () => {
+ setOverlayVisible(true);
+ if (overlayTimeoutRef.current) {
+ clearTimeout(overlayTimeoutRef.current);
+ }
+ overlayTimeoutRef.current = setTimeout(() => {
+ setOverlayVisible(false);
+ }, 1000);
+ };
+
+ window.addEventListener("mousemove", handleMouseMove);
+
+ return () => {
+ window.removeEventListener("mousemove", handleMouseMove);
+ if (overlayTimeoutRef.current) {
+ clearTimeout(overlayTimeoutRef.current);
+ }
+ };
+ }, []);
useEffect(() => {
if (videoMetadataLoaded) {
@@ -32,12 +55,12 @@ export const ShareVideo = ({ data }: { data: typeof videos.$inferSelect }) => {
const onVideoLoadedMetadata = () => {
console.log("Video metadata loaded");
setVideoMetadataLoaded(true);
- if (video2Ref.current) {
- setLongestDuration(video2Ref.current.duration);
+ if (videoRef.current) {
+ setLongestDuration(videoRef.current.duration);
}
};
- const videoElement = video2Ref.current;
+ const videoElement = videoRef.current;
videoElement?.addEventListener("loadedmetadata", onVideoLoadedMetadata);
@@ -52,7 +75,7 @@ export const ShareVideo = ({ data }: { data: typeof videos.$inferSelect }) => {
const handlePlayPauseClick = async () => {
setIsPlaying(!isPlaying);
- const videoElement = video2Ref.current;
+ const videoElement = videoRef.current;
if (!videoElement) return;
@@ -69,14 +92,14 @@ export const ShareVideo = ({ data }: { data: typeof videos.$inferSelect }) => {
};
const applyTimeToVideos = (time: number) => {
- if (video2Ref.current) video2Ref.current.currentTime = time;
+ if (videoRef.current) videoRef.current.currentTime = time;
setCurrentTime(time);
};
// Update useEffect for playback synchronization
useEffect(() => {
const syncPlayback = () => {
- const videoElement = video2Ref.current;
+ const videoElement = videoRef.current;
if (!isPlaying || isLoading || !videoElement) return;
@@ -101,13 +124,13 @@ export const ShareVideo = ({ data }: { data: typeof videos.$inferSelect }) => {
// Add a useEffect for seeking behavior
useEffect(() => {
const handleSeeking = () => {
- if (seeking && video2Ref.current) {
+ if (seeking && videoRef.current) {
// Optional: add throttling here to reduce frequency of seek updates
- setCurrentTime(video2Ref.current.currentTime);
+ setCurrentTime(videoRef.current.currentTime);
}
};
- const videoElement = video2Ref.current;
+ const videoElement = videoRef.current;
videoElement?.addEventListener("seeking", handleSeeking);
@@ -123,6 +146,10 @@ export const ShareVideo = ({ data }: { data: typeof videos.$inferSelect }) => {
return relativePosition * longestDuration;
};
+ const handleSeekMouseDown = () => {
+ setSeeking(true);
+ };
+
// Changes specifically in handleSeekMouseMove, handleSeekMouseUp to use applyTimeToVideos directly
const handleSeekMouseUp = (event: any) => {
// Similar change as handleSeekMouseMove, no need for isPlaying check here
@@ -132,14 +159,21 @@ export const ShareVideo = ({ data }: { data: typeof videos.$inferSelect }) => {
const seekTo = calculateNewTime(event, seekBar);
applyTimeToVideos(seekTo);
if (isPlaying) {
- video2Ref.current?.play();
+ videoRef.current?.play();
}
};
+ const handleSeekMouseMove = (event: any) => {
+ if (!seeking) return;
+ const seekBar = event.currentTarget;
+ const seekTo = calculateNewTime(event, seekBar);
+ applyTimeToVideos(seekTo); // This will just update the current time in state but not the video currentTime because that should happen on mouse up to avoid too many updates.
+ };
+
const handleMuteClick = () => {
- if (video2Ref.current) {
+ if (videoRef.current) {
console.log("Mute clicked");
- video2Ref.current.muted = video2Ref.current.muted ? false : true;
+ videoRef.current.muted = videoRef.current.muted ? false : true;
}
};
@@ -163,16 +197,16 @@ export const ShareVideo = ({ data }: { data: typeof videos.$inferSelect }) => {
useEffect(() => {
if (isPlaying) {
- video2Ref.current?.play();
+ videoRef.current?.play();
} else {
- video2Ref.current?.pause();
+ videoRef.current?.pause();
}
}, [isPlaying]);
useEffect(() => {
const syncPlay = () => {
- if (video2Ref.current && !isLoading) {
- const playPromise2 = video2Ref.current.play();
+ if (videoRef.current && !isLoading) {
+ const playPromise2 = videoRef.current.play();
playPromise2.catch((e) => console.log("Play failed for video 2", e));
}
};
@@ -194,7 +228,9 @@ export const ShareVideo = ({ data }: { data: typeof videos.$inferSelect }) => {
)}
{isLoading === false && (
<div
- className={`absolute top-0 left-0 w-full h-full z-10 flex items-center justify-center bg-black bg-opacity-50 transition-all opacity-0 group-hover:opacity-100 z-20`}
+ className={`absolute top-0 left-0 w-full h-full z-10 flex items-center justify-center bg-black bg-opacity-50 transition-all opacity-0 ${
+ overlayVisible && "group-hover:opacity-100"
+ } z-20`}
>
<button
aria-label="Play video"
@@ -216,7 +252,7 @@ export const ShareVideo = ({ data }: { data: typeof videos.$inferSelect }) => {
style={{ paddingBottom: "min(806px, 56.25%)" }}
>
<VideoPlayer
- ref={video2Ref}
+ ref={videoRef}
videoSrc={`${process.env.NEXT_PUBLIC_URL}/api/playlist?userId=${data.ownerId}&videoId=${data.id}&videoType=video`}
audioSrc={`${process.env.NEXT_PUBLIC_URL}/api/playlist?userId=${data.ownerId}&videoId=${data.id}&videoType=audio`}
/>
@@ -225,6 +261,8 @@ export const ShareVideo = ({ data }: { data: typeof videos.$inferSelect }) => {
<div
id="seek"
className="drag-seek absolute left-0 right-0 block h-4 mx-4 -mt-2 group z-20 cursor-pointer"
+ onMouseDown={handleSeekMouseDown}
+ onMouseMove={handleSeekMouseMove}
onMouseUp={handleSeekMouseUp}
onMouseLeave={() => setSeeking(false)}
onTouchEnd={handleSeekMouseUp}
@@ -273,7 +311,7 @@ export const ShareVideo = ({ data }: { data: typeof videos.$inferSelect }) => {
type="button"
onClick={() => handleMuteClick()}
>
- {video2Ref?.current?.muted ? (
+ {videoRef?.current?.muted ? (
<VolumeX className="w-auto h-6" />
) : (
<Volume2 className="w-auto h-6" />
diff --git a/apps/web/app/share/[videoId]/_components/Toolbar.tsx b/apps/web/app/share/[videoId]/_components/Toolbar.tsx
new file mode 100644
index 000000000..b30fdfc84
--- /dev/null
+++ b/apps/web/app/share/[videoId]/_components/Toolbar.tsx
@@ -0,0 +1,105 @@
+"use client";
+import { useEffect, useRef, useState } from "react";
+
+export const Toolbar = () => {
+ const [currentEmoji, setCurrentEmoji] = useState<{
+ emoji: string;
+ id: number;
+ } | null>(null);
+ const clearEmojiTimeout = useRef<any>(null);
+
+ useEffect(() => {
+ return () => {
+ if (clearEmojiTimeout.current) {
+ clearTimeout(clearEmojiTimeout.current);
+ }
+ };
+ }, []);
+
+ const handleEmojiClick = async (emoji: string) => {
+ // Clear any existing timeout
+ if (clearEmojiTimeout.current) {
+ clearTimeout(clearEmojiTimeout.current);
+ }
+
+ // Set the current emoji with a unique identifier
+ setCurrentEmoji({ emoji, id: Date.now() });
+
+ // Remove the emoji after the animation duration
+ clearEmojiTimeout.current = setTimeout(() => {
+ setCurrentEmoji(null);
+ }, 3000); // Adjust this duration to match your animation
+
+ // Record the reaction in the database
+ // or do something else
+ };
+
+ const Emoji = ({ label, emoji }: { label: string; emoji: string }) => (
+ <div className="relative w-fit">
+ <button
+ className="font-emoji text-2xl leading-6 bg-transparent p-1 relative transition-bg-color duration-600 inline-flex justify-center items-center align-middle rounded-full ease-in-out hover:bg-gray-200 active:bg-gray-400 active:duration-0"
+ role="img"
+ aria-label={label ? label : ""}
+ aria-hidden={label ? "false" : "true"}
+ onClick={() => handleEmojiClick(emoji)}
+ >
+ {emoji}
+ {currentEmoji && currentEmoji.emoji === emoji && (
+ <span
+ key={currentEmoji.id}
+ className="font-emoji absolute -top-10 left-0 right-0 mx-auto animate-flyEmoji duration-3000"
+ >
+ {currentEmoji.emoji}
+ </span>
+ )}
+ </button>
+ </div>
+ );
+
+ return (
+ <>
+ <div className="bg-white border border-gray-300 rounded-full mx-auto mt-4 mb-4">
+ <div className="grid items-center justify-start">
+ <div className="p-2">
+ <div className="grid items-center justify-start grid-flow-col">
+ {REACTIONS.map((reaction) => (
+ <Emoji
+ key={reaction.emoji}
+ emoji={reaction.emoji}
+ label={reaction.label}
+ />
+ ))}
+ </div>
+ </div>
+ </div>
+ </div>
+ </>
+ );
+};
+
+const REACTIONS = [
+ {
+ emoji: "๐Ÿ˜‚",
+ label: "joy",
+ },
+ {
+ emoji: "๐Ÿ˜",
+ label: "love",
+ },
+ {
+ emoji: "๐Ÿ˜ฎ",
+ label: "wow",
+ },
+ {
+ emoji: "๐Ÿ™Œ",
+ label: "yay",
+ },
+ {
+ emoji: "๐Ÿ‘",
+ label: "up",
+ },
+ {
+ emoji: "๐Ÿ‘Ž",
+ label: "down",
+ },
+];
diff --git a/apps/web/app/share/[videoId]/_components/VideoPlayer.tsx b/apps/web/app/share/[videoId]/_components/VideoPlayer.tsx
index 95948ea4b..e24c64ac4 100644
--- a/apps/web/app/share/[videoId]/_components/VideoPlayer.tsx
+++ b/apps/web/app/share/[videoId]/_components/VideoPlayer.tsx
@@ -72,12 +72,18 @@ export const VideoPlayer = memo(
}
};
+ const seekListener = () => {
+ audio.currentTime = video.currentTime;
+ };
+
video.addEventListener("play", playListener);
video.addEventListener("pause", pauseListener);
+ video.addEventListener("seeked", seekListener);
return () => {
video.removeEventListener("play", playListener);
video.removeEventListener("pause", pauseListener);
+ video.removeEventListener("seeked", seekListener);
};
}, [audioSrc]);
diff --git a/apps/web/next.config.mjs b/apps/web/next.config.mjs
index 5d47e3b39..16617a59b 100644
--- a/apps/web/next.config.mjs
+++ b/apps/web/next.config.mjs
@@ -62,7 +62,7 @@ const nextConfig = {
const millionConfig = {
auto: {
rsc: true,
- skip: ["Parallax"],
+ skip: ["Parallax", "Toolbar"],
},
};