Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: /share/ page video fixes and improvements

Richie McIlroyb14f8fe28494
diff --git a/apps/desktop/next.config.mjs b/apps/desktop/next.config.mjs
index 4e1d83586..354ca33b8 100644
--- a/apps/desktop/next.config.mjs
+++ b/apps/desktop/next.config.mjs
@@ -2,6 +2,14 @@
import("dotenv").then(({ config }) => config({ path: "../../.env" }));
+import fs from "fs";
+import path from "path";
+
+const packageJson = JSON.parse(
+ fs.readFileSync(path.resolve("./package.json"), "utf8")
+);
+const { version } = packageJson;
+
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
@@ -16,6 +24,9 @@ const nextConfig = {
experimental: {
optimizePackageImports: ["@cap/ui", "@cap/utils"],
},
+ env: {
+ appVersion: version,
+ },
};
export default nextConfig;
diff --git a/apps/desktop/src/components/icons/Logo.tsx b/apps/desktop/src/components/icons/Logo.tsx
index 23224dafe..396b09e36 100644
--- a/apps/desktop/src/components/icons/Logo.tsx
+++ b/apps/desktop/src/components/icons/Logo.tsx
@@ -1,78 +1,83 @@
export const Logo = ({ className }: { className: string }) => {
return (
- <svg
- xmlns="http://www.w3.org/2000/svg"
- className={className}
- fill="none"
- viewBox="0 0 719 269"
- >
- <path
- fill="#0A486B"
- d="M474.954 156.466c-3.122 16.278-10.217 29.23-21.286 38.856-10.927 9.484-25.118 14.226-42.572 14.226-14.333 0-26.892-3.397-37.677-10.192-10.643-6.936-18.873-16.349-24.692-28.24-5.818-11.89-8.727-25.267-8.727-40.13 0-14.863 2.838-28.31 8.514-40.342 5.819-12.032 14.12-21.445 24.905-28.24C384.204 55.468 396.763 52 411.096 52c16.603 0 30.368 4.53 41.295 13.589 10.927 9.059 18.164 21.304 21.712 36.733l-27.885 1.486c-2.129-8.776-6.244-15.641-12.346-20.596-6.102-5.096-13.765-7.644-22.989-7.644-9.65 0-17.739 2.407-24.266 7.22-6.386 4.812-11.14 11.465-14.262 19.959-3.122 8.351-4.683 17.764-4.683 28.239 0 10.475 1.561 19.818 4.683 28.028 3.122 8.21 7.876 14.792 14.262 19.746 6.527 4.813 14.616 7.219 24.266 7.219 9.65 0 17.526-2.76 23.628-8.28 6.243-5.662 10.359-13.236 12.346-22.72l28.097 1.487zM486.826 127.801c2.271-11.607 7.734-20.596 16.391-26.965 8.656-6.512 19.796-9.768 33.419-9.768 16.177 0 28.452 4.106 36.825 12.316 8.372 8.21 12.559 20.171 12.559 35.883v39.281c0 2.973.567 5.096 1.703 6.37 1.277 1.132 3.051 1.698 5.321 1.698h4.257v19.535l-6.598.212h-.852c-3.831.142-7.734-.142-11.707-.849-3.832-.708-7.237-2.336-10.217-4.884-2.981-2.548-4.683-6.441-5.109-11.678-2.838 5.804-7.45 10.546-13.836 14.226-6.386 3.68-14.191 5.521-23.415 5.521-11.636 0-21.357-2.902-29.162-8.706-7.663-5.945-11.494-13.73-11.494-23.356 0-7.078 1.631-12.811 4.895-17.199 3.406-4.388 8.089-7.856 14.049-10.404 6.102-2.548 14.049-4.742 23.841-6.582l31.716-6.37c-.142-8.635-2.058-15.004-5.747-19.109-3.69-4.247-9.366-6.37-17.029-6.37-5.96 0-10.927 1.628-14.9 4.883-3.832 3.114-6.457 7.715-7.876 13.802l-27.034-1.487zm25.331 47.987c0 4.105 1.703 7.502 5.108 10.191 3.548 2.548 8.586 3.822 15.114 3.822 5.25 0 9.933-1.274 14.048-3.822 4.258-2.547 7.522-6.369 9.792-11.465 2.413-5.238 3.619-11.537 3.619-18.898v-1.061l-21.712 3.822-3.832.637c-5.25.991-9.366 1.981-12.346 2.972-2.838.991-5.179 2.619-7.024 4.884-1.845 2.123-2.767 5.096-2.767 8.918zM611.079 93.616h24.905l.851 23.569-2.128-2.76c2.838-7.503 7.308-13.236 13.41-17.199 6.244-4.105 13.765-6.158 22.563-6.158 10.502 0 19.371 2.62 26.608 7.857 7.237 5.237 12.63 12.315 16.178 21.233 3.689 8.776 5.534 18.684 5.534 29.726 0 11.041-1.845 21.02-5.534 29.938-3.548 8.776-8.941 15.783-16.178 21.02-7.237 5.238-16.106 7.857-26.608 7.857-5.818 0-11.139-.92-15.964-2.761-4.683-1.84-8.728-4.529-12.133-8.068-3.264-3.539-5.818-7.927-7.663-13.165l2.554-2.123V238h-26.395V93.616zm24.266 56.268c0 6.794.994 13.022 2.98 18.684 2.129 5.521 5.322 9.98 9.579 13.377 4.257 3.397 9.437 5.096 15.539 5.096 9.224 0 16.178-3.539 20.861-10.616 4.824-7.078 7.237-15.925 7.237-26.541 0-10.475-2.413-19.322-7.237-26.542-4.683-7.219-11.637-10.828-20.861-10.828-6.102 0-11.282 1.769-15.539 5.308-4.257 3.397-7.45 7.927-9.579 13.589-1.986 5.521-2.98 11.678-2.98 18.473z"
- ></path>
- <path
- fill="url(#paint0_linear_0_1)"
- d="M218.623 0H50C22.386 0 0 22.386 0 50v168.623c0 27.614 22.386 50 50 50h168.623c27.614 0 50-22.386 50-50V50c0-27.614-22.386-50-50-50z"
- ></path>
- <path
- fill="url(#paint1_radial_0_1)"
- d="M134.646 240.418c58.415 0 105.77-47.355 105.77-105.77s-47.355-105.77-105.77-105.77-105.77 47.355-105.77 105.77 47.355 105.77 105.77 105.77z"
- ></path>
- <path
- fill="url(#paint2_linear_0_1)"
- d="M134.983 224.972c49.699 0 89.988-40.289 89.988-89.988 0-49.7-40.289-89.989-89.988-89.989-49.7 0-89.989 40.29-89.989 89.989 0 49.699 40.29 89.988 89.989 89.988z"
- ></path>
- <path
- fill="url(#paint3_radial_0_1)"
- d="M134.983 202.81c37.46 0 67.828-30.368 67.828-67.828 0-37.46-30.368-67.827-67.828-67.827-37.46 0-67.827 30.367-67.827 67.827 0 37.46 30.367 67.828 67.827 67.828z"
- ></path>
- <defs>
- <linearGradient
- id="paint0_linear_0_1"
- x1="134.311"
- x2="134.311"
- y1="0"
- y2="268.623"
- gradientUnits="userSpaceOnUse"
- >
- <stop stopColor="#A8DBF8"></stop>
- <stop offset="1" stopColor="#BCCBFF"></stop>
- </linearGradient>
- <radialGradient
- id="paint1_radial_0_1"
- cx="0"
- cy="0"
- r="1"
- gradientTransform="rotate(107.38 31.314 98.475) scale(149.225)"
- gradientUnits="userSpaceOnUse"
- >
- <stop offset="0.063" stopColor="#84D3FF"></stop>
- <stop offset="0.411" stopColor="#17ABFE"></stop>
- <stop offset="0.906" stopColor="#0770D1"></stop>
- </radialGradient>
- <linearGradient
- id="paint2_linear_0_1"
- x1="134.983"
- x2="134.983"
- y1="44.995"
- y2="224.972"
- gradientUnits="userSpaceOnUse"
- >
- <stop stopColor="#BBE8FF"></stop>
- <stop offset="1" stopColor="#018FEF"></stop>
- </linearGradient>
- <radialGradient
- id="paint3_radial_0_1"
- cx="0"
- cy="0"
- r="1"
- gradientTransform="rotate(98.584 14.543 129.964) scale(68.5955)"
- gradientUnits="userSpaceOnUse"
- >
- <stop stopColor="#7EC3FF"></stop>
- <stop offset="1" stopColor="#EAF5FF"></stop>
- </radialGradient>
- </defs>
- </svg>
+ <div className="flex items-center space-x-1">
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ className={className}
+ fill="none"
+ viewBox="0 0 719 269"
+ >
+ <path
+ fill="#0A486B"
+ d="M474.954 156.466c-3.122 16.278-10.217 29.23-21.286 38.856-10.927 9.484-25.118 14.226-42.572 14.226-14.333 0-26.892-3.397-37.677-10.192-10.643-6.936-18.873-16.349-24.692-28.24-5.818-11.89-8.727-25.267-8.727-40.13 0-14.863 2.838-28.31 8.514-40.342 5.819-12.032 14.12-21.445 24.905-28.24C384.204 55.468 396.763 52 411.096 52c16.603 0 30.368 4.53 41.295 13.589 10.927 9.059 18.164 21.304 21.712 36.733l-27.885 1.486c-2.129-8.776-6.244-15.641-12.346-20.596-6.102-5.096-13.765-7.644-22.989-7.644-9.65 0-17.739 2.407-24.266 7.22-6.386 4.812-11.14 11.465-14.262 19.959-3.122 8.351-4.683 17.764-4.683 28.239 0 10.475 1.561 19.818 4.683 28.028 3.122 8.21 7.876 14.792 14.262 19.746 6.527 4.813 14.616 7.219 24.266 7.219 9.65 0 17.526-2.76 23.628-8.28 6.243-5.662 10.359-13.236 12.346-22.72l28.097 1.487zM486.826 127.801c2.271-11.607 7.734-20.596 16.391-26.965 8.656-6.512 19.796-9.768 33.419-9.768 16.177 0 28.452 4.106 36.825 12.316 8.372 8.21 12.559 20.171 12.559 35.883v39.281c0 2.973.567 5.096 1.703 6.37 1.277 1.132 3.051 1.698 5.321 1.698h4.257v19.535l-6.598.212h-.852c-3.831.142-7.734-.142-11.707-.849-3.832-.708-7.237-2.336-10.217-4.884-2.981-2.548-4.683-6.441-5.109-11.678-2.838 5.804-7.45 10.546-13.836 14.226-6.386 3.68-14.191 5.521-23.415 5.521-11.636 0-21.357-2.902-29.162-8.706-7.663-5.945-11.494-13.73-11.494-23.356 0-7.078 1.631-12.811 4.895-17.199 3.406-4.388 8.089-7.856 14.049-10.404 6.102-2.548 14.049-4.742 23.841-6.582l31.716-6.37c-.142-8.635-2.058-15.004-5.747-19.109-3.69-4.247-9.366-6.37-17.029-6.37-5.96 0-10.927 1.628-14.9 4.883-3.832 3.114-6.457 7.715-7.876 13.802l-27.034-1.487zm25.331 47.987c0 4.105 1.703 7.502 5.108 10.191 3.548 2.548 8.586 3.822 15.114 3.822 5.25 0 9.933-1.274 14.048-3.822 4.258-2.547 7.522-6.369 9.792-11.465 2.413-5.238 3.619-11.537 3.619-18.898v-1.061l-21.712 3.822-3.832.637c-5.25.991-9.366 1.981-12.346 2.972-2.838.991-5.179 2.619-7.024 4.884-1.845 2.123-2.767 5.096-2.767 8.918zM611.079 93.616h24.905l.851 23.569-2.128-2.76c2.838-7.503 7.308-13.236 13.41-17.199 6.244-4.105 13.765-6.158 22.563-6.158 10.502 0 19.371 2.62 26.608 7.857 7.237 5.237 12.63 12.315 16.178 21.233 3.689 8.776 5.534 18.684 5.534 29.726 0 11.041-1.845 21.02-5.534 29.938-3.548 8.776-8.941 15.783-16.178 21.02-7.237 5.238-16.106 7.857-26.608 7.857-5.818 0-11.139-.92-15.964-2.761-4.683-1.84-8.728-4.529-12.133-8.068-3.264-3.539-5.818-7.927-7.663-13.165l2.554-2.123V238h-26.395V93.616zm24.266 56.268c0 6.794.994 13.022 2.98 18.684 2.129 5.521 5.322 9.98 9.579 13.377 4.257 3.397 9.437 5.096 15.539 5.096 9.224 0 16.178-3.539 20.861-10.616 4.824-7.078 7.237-15.925 7.237-26.541 0-10.475-2.413-19.322-7.237-26.542-4.683-7.219-11.637-10.828-20.861-10.828-6.102 0-11.282 1.769-15.539 5.308-4.257 3.397-7.45 7.927-9.579 13.589-1.986 5.521-2.98 11.678-2.98 18.473z"
+ ></path>
+ <path
+ fill="url(#paint0_linear_0_1)"
+ d="M218.623 0H50C22.386 0 0 22.386 0 50v168.623c0 27.614 22.386 50 50 50h168.623c27.614 0 50-22.386 50-50V50c0-27.614-22.386-50-50-50z"
+ ></path>
+ <path
+ fill="url(#paint1_radial_0_1)"
+ d="M134.646 240.418c58.415 0 105.77-47.355 105.77-105.77s-47.355-105.77-105.77-105.77-105.77 47.355-105.77 105.77 47.355 105.77 105.77 105.77z"
+ ></path>
+ <path
+ fill="url(#paint2_linear_0_1)"
+ d="M134.983 224.972c49.699 0 89.988-40.289 89.988-89.988 0-49.7-40.289-89.989-89.988-89.989-49.7 0-89.989 40.29-89.989 89.989 0 49.699 40.29 89.988 89.989 89.988z"
+ ></path>
+ <path
+ fill="url(#paint3_radial_0_1)"
+ d="M134.983 202.81c37.46 0 67.828-30.368 67.828-67.828 0-37.46-30.368-67.827-67.828-67.827-37.46 0-67.827 30.367-67.827 67.827 0 37.46 30.367 67.828 67.827 67.828z"
+ ></path>
+ <defs>
+ <linearGradient
+ id="paint0_linear_0_1"
+ x1="134.311"
+ x2="134.311"
+ y1="0"
+ y2="268.623"
+ gradientUnits="userSpaceOnUse"
+ >
+ <stop stopColor="#A8DBF8"></stop>
+ <stop offset="1" stopColor="#BCCBFF"></stop>
+ </linearGradient>
+ <radialGradient
+ id="paint1_radial_0_1"
+ cx="0"
+ cy="0"
+ r="1"
+ gradientTransform="rotate(107.38 31.314 98.475) scale(149.225)"
+ gradientUnits="userSpaceOnUse"
+ >
+ <stop offset="0.063" stopColor="#84D3FF"></stop>
+ <stop offset="0.411" stopColor="#17ABFE"></stop>
+ <stop offset="0.906" stopColor="#0770D1"></stop>
+ </radialGradient>
+ <linearGradient
+ id="paint2_linear_0_1"
+ x1="134.983"
+ x2="134.983"
+ y1="44.995"
+ y2="224.972"
+ gradientUnits="userSpaceOnUse"
+ >
+ <stop stopColor="#BBE8FF"></stop>
+ <stop offset="1" stopColor="#018FEF"></stop>
+ </linearGradient>
+ <radialGradient
+ id="paint3_radial_0_1"
+ cx="0"
+ cy="0"
+ r="1"
+ gradientTransform="rotate(98.584 14.543 129.964) scale(68.5955)"
+ gradientUnits="userSpaceOnUse"
+ >
+ <stop stopColor="#7EC3FF"></stop>
+ <stop offset="1" stopColor="#EAF5FF"></stop>
+ </radialGradient>
+ </defs>
+ </svg>
+ <span className="text-[10px] font-medium text-gray-500">
+ v{process.env.appVersion}
+ </span>
+ </div>
);
};
diff --git a/apps/desktop/src/components/windows/inner/Countdown.tsx b/apps/desktop/src/components/windows/inner/Countdown.tsx
index fccc7601d..9c2e427af 100644
--- a/apps/desktop/src/components/windows/inner/Countdown.tsx
+++ b/apps/desktop/src/components/windows/inner/Countdown.tsx
@@ -27,7 +27,7 @@ export const Countdown: React.FC<CountdownOverlayProps> = ({
return (
<div
- className="absolute inset-0 z-50 flex items-center justify-center"
+ className="absolute inset-0 z-50 flex items-center justify-center rounded-[16px]"
style={{
backgroundColor: "rgba(0, 0, 0, 0.75)",
}}
diff --git a/apps/desktop/src/components/windows/inner/Recorder.tsx b/apps/desktop/src/components/windows/inner/Recorder.tsx
index 4c353f0a8..88911d1df 100644
--- a/apps/desktop/src/components/windows/inner/Recorder.tsx
+++ b/apps/desktop/src/components/windows/inner/Recorder.tsx
@@ -140,19 +140,18 @@ export const Recorder = () => {
};
const handleStartAllRecordings = async () => {
- setCountdownActive(true);
-
try {
const videoData = await prepareVideoData();
- console.log("videoData:");
- console.log(videoData);
if (videoData) {
const stream = await navigator.mediaDevices.getUserMedia({
audio: { deviceId: selectedAudioDevice?.deviceId },
video: { deviceId: selectedVideoDevice?.deviceId },
});
- await startMediaRecording(stream);
- await startDualRecording(videoData);
+ setCountdownActive(true);
+ await Promise.all([
+ startMediaRecording(stream),
+ startDualRecording(videoData),
+ ]);
} else {
throw new Error("Failed to prepare video data.");
}
@@ -168,6 +167,8 @@ export const Recorder = () => {
try {
console.log("Stopping recordings...");
+ await new Promise((resolve) => setTimeout(resolve, 3000));
+
await stopMediaRecording();
await invoke("stop_all_recordings");
diff --git a/apps/desktop/src/utils/recording/useMediaRecorder.ts b/apps/desktop/src/utils/recording/useMediaRecorder.ts
index b5c668e77..b7e03f125 100644
--- a/apps/desktop/src/utils/recording/useMediaRecorder.ts
+++ b/apps/desktop/src/utils/recording/useMediaRecorder.ts
@@ -136,6 +136,12 @@ export const useMediaRecorder = () => {
"aac",
"-strict",
"experimental",
+ "-b:a",
+ "128k",
+ "-ac",
+ "2",
+ "-ar",
+ "44100",
"-f",
"mpegts",
outputFileName,
@@ -207,7 +213,6 @@ export const useMediaRecorder = () => {
) {
mediaRecorder.current.stop();
isRecording.current = false;
- // clearInterval(requestDataInterval);
}
console.log("Recording stopped");
};
diff --git a/apps/web/app/globals.css b/apps/web/app/globals.css
index 8c20454e6..45601b9ac 100644
--- a/apps/web/app/globals.css
+++ b/apps/web/app/globals.css
@@ -290,8 +290,3 @@ ul {
slot:not(.dashboard-layout slot) {
display: block;
}
-
-.aspect-video slot {
- width: 100%;
- height: 100%;
-}
diff --git a/apps/web/app/share/[videoId]/Share.tsx b/apps/web/app/share/[videoId]/Share.tsx
index e59e2778b..def552e2f 100644
--- a/apps/web/app/share/[videoId]/Share.tsx
+++ b/apps/web/app/share/[videoId]/Share.tsx
@@ -1,50 +1,28 @@
"use client";
+import moment from "moment";
import { ShareHeader } from "./_components/ShareHeader";
+import { ShareVideo } from "./_components/ShareVideo";
import { videos } from "@cap/database/schema";
-import { VideoPlayer } from "./_components/VideoPlayer";
-import { useState, useCallback } from "react";
-import { PlayCircle, PauseCircle } from "lucide-react";
-
-export const Share = ({ data }: { data: typeof videos.$inferSelect }) => {
- const [isPlaying, setIsPlaying] = useState(false);
-
- const handlePlayPause = useCallback(
- (playing: boolean | ((prevState: boolean) => boolean)) => {
- setIsPlaying(playing);
- },
- []
- );
-
+import { userSelectProps } from "@cap/database/auth/session";
+// million-ignore
+export const Share = ({
+ data,
+ user,
+}: {
+ data: typeof videos.$inferSelect;
+ user: typeof userSelectProps | null;
+}) => {
return (
- <div className="wrapper py-6">
- <div className="space-y-8">
- <ShareHeader title={data.name} createdAt={data.createdAt} />
- <div className="aspect-video relative bg-black flex items-center justify-center rounded-lg group overflow-hidden">
- <div className="video-player w-[175px] h-[175px] absolute bottom-4 right-12 overflow-hidden rounded-full z-10 shadow-[0px 0px 180px rgba(255, 255, 255, 0.18)]">
- <VideoPlayer
- isPlaying={isPlaying}
- onPlayPause={handlePlayPause}
- src={`${process.env.NEXT_PUBLIC_URL}/api/playlist?userId=${data.ownerId}&videoId=${data.id}&videoType=video`}
- />
- </div>
- <div className="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 z-10">
- <button
- className="hidden group-hover:block w-32 h-32 z-10 relative cursor-pointer"
- onClick={() => handlePlayPause(!isPlaying)}
- >
- {isPlaying ? (
- <PauseCircle className="w-full h-auto text-white" />
- ) : (
- <PlayCircle className="w-full h-auto text-white" />
- )}
- </button>
- </div>
- <VideoPlayer
- isPlaying={isPlaying}
- onPlayPause={handlePlayPause}
- src={`${process.env.NEXT_PUBLIC_URL}/api/playlist?userId=${data.ownerId}&videoId=${data.id}&videoType=screen`}
- />
+ <div className="wrapper py-5">
+ <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>
</div>
</div>
diff --git a/apps/web/app/share/[videoId]/_components/ShareHeader.tsx b/apps/web/app/share/[videoId]/_components/ShareHeader.tsx
index d62a58dc9..4ced0ab83 100644
--- a/apps/web/app/share/[videoId]/_components/ShareHeader.tsx
+++ b/apps/web/app/share/[videoId]/_components/ShareHeader.tsx
@@ -1,19 +1,16 @@
-import { LogoBadge } from "@cap/ui";
-import moment from "moment";
+import { Logo } from "@cap/ui";
+import { videos } from "@cap/database/schema";
-export const ShareHeader = ({
- title,
- createdAt,
-}: {
- title: string;
- createdAt: Date;
-}) => {
+export const ShareHeader = ({ data }: { data: typeof videos.$inferSelect }) => {
return (
- <div className="flex items-center space-x-5">
- <LogoBadge className="w-8 h-auto" />
+ <div>
<div>
- <h1 className="text-2xl">{title}</h1>
- <p className="text-gray-400">{moment(createdAt).fromNow()}</p>
+ <div className="flex items-center space-x-1">
+ <Logo className="w-[75px] h-auto" />
+ <span className="text-[9px] font-medium text-gray-400">
+ v{process.env.appVersion}
+ </span>
+ </div>
</div>
</div>
);
diff --git a/apps/web/app/share/[videoId]/_components/ShareVideo.tsx b/apps/web/app/share/[videoId]/_components/ShareVideo.tsx
index a7676a124..c149a0110 100644
--- a/apps/web/app/share/[videoId]/_components/ShareVideo.tsx
+++ b/apps/web/app/share/[videoId]/_components/ShareVideo.tsx
@@ -1,18 +1,205 @@
-import moment from "moment";
+import { videos } from "@cap/database/schema";
+import { VideoPlayer } from "./VideoPlayer";
+import { useState, useCallback, useMemo, useEffect, useRef } from "react";
+import { Play, Pause, Maximize, VolumeX } from "lucide-react";
+import { LogoBadge } from "@cap/ui";
-interface ShareVideoProps {
- title: string;
- created: string;
-}
+const formatTime = (time: number) => {
+ const minutes = Math.floor(time / 60);
+ const seconds = Math.floor(time % 60);
+ return `${minutes.toString().padStart(2, "0")}:${seconds
+ .toString()
+ .padStart(2, "0")}`;
+};
+
+export const ShareVideo = ({ data }: { data: typeof videos.$inferSelect }) => {
+ const video1Ref = useRef<HTMLVideoElement>(null);
+ const video2Ref = useRef<HTMLVideoElement>(null);
+ const [isPlaying, setIsPlaying] = useState(false);
+ const [currentTime, setCurrentTime] = useState(0);
+ const [isLoading, setIsLoading] = useState(true);
+ const [duration1, setDuration1] = useState(0);
+ const [duration2, setDuration2] = useState(0);
+ const [longestDuration, setLongestDuration] = useState(0);
+
+ useEffect(() => {
+ const handleLoadedMetadata = () => {
+ const loadedDuration1 = video1Ref.current?.duration || 0;
+ const loadedDuration2 = video2Ref.current?.duration || 0;
+ setDuration1(loadedDuration1);
+ setDuration2(loadedDuration2);
+ setLongestDuration(Math.max(loadedDuration1, loadedDuration2));
+
+ if (loadedDuration1 > 0 && loadedDuration2 > 0) {
+ setIsLoading(false); // Set loading to false once both videos' metadata are loaded
+ }
+ };
+
+ const handleTimeUpdate = () => {
+ if (video1Ref.current) {
+ setCurrentTime(video1Ref.current.currentTime);
+ }
+ };
+
+ const videos = [video1Ref.current, video2Ref.current].filter(Boolean);
+ videos.forEach((video) => {
+ video?.addEventListener("loadedmetadata", handleLoadedMetadata);
+ video?.addEventListener("timeupdate", handleTimeUpdate);
+ });
+
+ return () => {
+ videos.forEach((video) => {
+ video?.removeEventListener("loadedmetadata", handleLoadedMetadata);
+ video?.removeEventListener("timeupdate", handleTimeUpdate);
+ });
+ };
+ }, []);
+
+ const handlePlayPauseClick = () => setIsPlaying(!isPlaying);
+
+ const watchedPercentage =
+ longestDuration > 0 ? (currentTime / longestDuration) * 100 : 0;
+
+ const handlePlay = () => {
+ video1Ref.current?.play();
+ video2Ref.current?.play();
+ };
+
+ useEffect(() => {
+ if (!isLoading && isPlaying) {
+ video1Ref.current?.play();
+ video2Ref.current?.play();
+ } else {
+ video1Ref.current?.pause();
+ video2Ref.current?.pause();
+ }
+ }, [isLoading, isPlaying]);
+
+ //Play on load
+ useEffect(() => {
+ if (!isLoading) {
+ handlePlay();
+ }
+ }, [isLoading]);
-export const ShareVideo = ({ data }: { data: ShareVideoProps }) => {
+ const CapSpinner = () => {
+ return (
+ <div>
+ <LogoBadge className="w-10 h-auto animate-spin opacity-50" />
+ </div>
+ );
+ };
return (
- <div>
- <div className="w-full aspect-video mx-auto bg-gray-100 rounded-xl mb-4"></div>
- <h1 className="text-2xl">{data.title}</h1>
- <p className="text-base text-gray-500">
- {moment(data.created).fromNow()}
- </p>
+ <div
+ className="relative flex h-full w-full overflow-hidden shadow-lg rounded-lg group"
+ id="player"
+ >
+ {isLoading && (
+ <div className="absolute top-0 left-0 flex items-center justify-center w-full h-full z-10">
+ <CapSpinner />
+ </div>
+ )}
+ {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`}
+ >
+ <button
+ aria-label="Play video"
+ className=" inline-flex items-center text-sm font-medium transition ease-in-out duration-150 text-white border border-transparent hover:opacity-50 px-2 py-2 justify-center rounded-lg"
+ tabIndex={0}
+ type="button"
+ onClick={() => handlePlayPauseClick()}
+ >
+ {isPlaying ? (
+ <Pause className="w-auto h-14" />
+ ) : (
+ <Play className="w-auto h-14" />
+ )}
+ </button>
+ </div>
+ )}
+ <div className="w-[175px] h-[175px] absolute bottom-4 right-12 overflow-hidden rounded-full z-10 shadow-lg">
+ <VideoPlayer
+ ref={video1Ref}
+ src={`${process.env.NEXT_PUBLIC_URL}/api/playlist?userId=${data.ownerId}&videoId=${data.id}&videoType=video`}
+ />
+ </div>
+ <div
+ className="relative block w-full h-full rounded-lg bg-black"
+ style={{ paddingBottom: "min(806px, 56.25%)" }}
+ >
+ <VideoPlayer
+ ref={video2Ref}
+ src={`${process.env.NEXT_PUBLIC_URL}/api/playlist?userId=${data.ownerId}&videoId=${data.id}&videoType=screen`}
+ />
+ </div>
+ <div className="absolute bottom-0 z-20 w-full text-white bg-black bg-opacity-50 opacity-0 group-hover:opacity-100 transition-all">
+ <div
+ id="seek"
+ className="absolute left-0 right-0 block h-4 mx-4 -mt-2 group"
+ >
+ <div className="absolute top-1.5 w-full h-1 bg-white bg-opacity-50 rounded-full cursor-pointer" />
+ <div
+ className="absolute top-1.5 h-1 bg-white rounded-full cursor-pointer transition-all duration-300"
+ style={{ width: `${watchedPercentage}%` }}
+ />
+ <div
+ className="absolute top-1.5 z-10 -mt-1.5 -ml-2 w-4 h-4 bg-white rounded-full border border-white cursor-pointer focus:ring-2 focus:ring-indigo-600 focus:ring-opacity-80 focus:outline-none transition-all duration-300"
+ tabIndex={0}
+ style={{ left: `${watchedPercentage}%` }}
+ />
+ </div>
+ <div className="flex items-center justify-between px-4 py-2">
+ <div className="flex items-center space-x-3">
+ <div>
+ <span className="inline-flex">
+ <button
+ aria-label="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={() => handlePlayPauseClick()}
+ >
+ {isPlaying ? (
+ <Pause className="w-auto h-6" />
+ ) : (
+ <Play className="w-auto h-6" />
+ )}
+ </button>
+ </span>
+ </div>
+ <div className="text-sm text-white font-medium select-none tabular text-clip overflow-hidden whitespace-nowrap space-x-0.5">
+ {formatTime(currentTime)} - {formatTime(longestDuration)}
+ </div>
+ </div>
+ <div className="flex justify-end space-x-2">
+ <div className="flex items-center justify-end space-x-2">
+ <span className="inline-flex">
+ <button
+ aria-label="Mute 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"
+ data-state="closed"
+ >
+ <VolumeX className="w-auto h-6" />
+ </button>
+ </span>
+ <span className="inline-flex">
+ <button
+ aria-label="Go fullscreen"
+ 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"
+ data-state="closed"
+ >
+ <Maximize className="w-auto h-6" />
+ </button>
+ </span>
+ </div>
+ </div>
+ </div>
+ </div>
</div>
);
};
diff --git a/apps/web/app/share/[videoId]/_components/VideoPlayer.tsx b/apps/web/app/share/[videoId]/_components/VideoPlayer.tsx
index a0d3756e3..23cbfbcb7 100644
--- a/apps/web/app/share/[videoId]/_components/VideoPlayer.tsx
+++ b/apps/web/app/share/[videoId]/_components/VideoPlayer.tsx
@@ -1,61 +1,42 @@
-import { useEffect, useRef, useState } from "react";
+import React, { forwardRef, useEffect } from "react";
import Hls from "hls.js";
-export function VideoPlayer({
- src,
- isPlaying: isPlayingProp,
- onPlayPause,
-}: {
+interface VideoPlayerProps {
src: string;
- isPlaying: boolean;
- onPlayPause: (isPlaying: boolean) => void;
-}) {
- const videoRef = useRef<HTMLVideoElement | null>(null);
- const [isPlaying, setIsPlaying] = useState(isPlayingProp);
-
- useEffect(() => {
- const video = videoRef.current;
- if (!video) return;
-
- if (Hls.isSupported()) {
- const hls = new Hls();
- hls.loadSource(src);
- hls.attachMedia(video);
- }
-
- const handlePlay = () => setIsPlaying(true);
- const handlePause = () => setIsPlaying(false);
- video.addEventListener("play", handlePlay);
- video.addEventListener("pause", handlePause);
-
- // Cleanup
- return () => {
- video.removeEventListener("play", handlePlay);
- video.removeEventListener("pause", handlePause);
- };
- }, [src]);
-
- useEffect(() => {
- setIsPlaying(isPlayingProp);
- }, [isPlayingProp]);
-
- useEffect(() => {
- onPlayPause(isPlaying);
- }, [isPlaying, onPlayPause]);
-
- useEffect(() => {
- const video = videoRef.current;
- if (video) {
- isPlaying ? video.play() : video.pause();
- }
- }, [isPlaying]);
-
- return (
- <video
- className="w-full h-full object-cover"
- ref={videoRef}
- src={src}
- preload="auto"
- />
- );
}
+
+export const VideoPlayer = forwardRef<HTMLVideoElement, VideoPlayerProps>(
+ ({ src }, ref) => {
+ useEffect(() => {
+ if (!ref || typeof ref === "function") return;
+ const video = ref.current;
+
+ if (Hls.isSupported()) {
+ const hls = new Hls();
+ hls.loadSource(src);
+ if (video) {
+ hls.attachMedia(video);
+ }
+ return () => {
+ if (video) {
+ hls.destroy();
+ }
+ };
+ } else if (video && video.canPlayType("application/vnd.apple.mpegurl")) {
+ video.src = src;
+ }
+ }, [src, ref]);
+
+ return (
+ <video
+ ref={ref}
+ className="absolute top-0 left-0 rounded-lg w-full h-full object-cover"
+ preload="auto"
+ playsInline
+ controls={false} // Controls handled by parent
+ />
+ );
+ }
+);
+
+export default VideoPlayer;
diff --git a/apps/web/app/share/[videoId]/page.tsx b/apps/web/app/share/[videoId]/page.tsx
index a41d5dfe3..d99b6c030 100644
--- a/apps/web/app/share/[videoId]/page.tsx
+++ b/apps/web/app/share/[videoId]/page.tsx
@@ -3,6 +3,7 @@ import { Share } from "./Share";
import { db } from "@cap/database";
import { eq } from "drizzle-orm";
import { videos } from "@cap/database/schema";
+import { getCurrentUser, userSelectProps } from "@cap/database/auth/session";
type Props = {
params: { [key: string]: string | string[] | undefined };
@@ -11,6 +12,7 @@ type Props = {
export default async function ShareVideoPage(props: Props) {
const params = props.params;
const videoId = params.videoId as string;
+ const user = (await getCurrentUser()) as typeof userSelectProps | null;
const query = await db.select().from(videos).where(eq(videos.id, videoId));
@@ -20,5 +22,5 @@ export default async function ShareVideoPage(props: Props) {
const video = query[0];
- return <Share data={video} />;
+ return <Share data={video} user={user} />;
}
diff --git a/apps/web/next.config.mjs b/apps/web/next.config.mjs
index 51e210f15..af6ed9cb2 100644
--- a/apps/web/next.config.mjs
+++ b/apps/web/next.config.mjs
@@ -4,6 +4,14 @@ import million from "million/compiler";
import("dotenv").then(({ config }) => config({ path: "../../.env" }));
+import fs from "fs";
+import path from "path";
+
+const packageJson = JSON.parse(
+ fs.readFileSync(path.resolve("./package.json"), "utf8")
+);
+const { version } = packageJson;
+
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
@@ -74,6 +82,9 @@ const nextConfig = {
},
];
},
+ env: {
+ appVersion: version,
+ },
};
const millionConfig = {
diff --git a/apps/web/package.json b/apps/web/package.json
index af9110a66..aa25a57d8 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -27,6 +27,7 @@
"dotenv": "^16.3.1",
"drizzle-orm": "^0.29.3",
"hls.js": "^1.5.3",
+ "lodash": "^4.17.21",
"lucide-react": "^0.294.0",
"million": "^2.6.4",
"moment": "^2.30.1",
diff --git a/packages/database/auth/session.ts b/packages/database/auth/session.ts
index 820a32f44..3ba6e6e35 100644
--- a/packages/database/auth/session.ts
+++ b/packages/database/auth/session.ts
@@ -10,6 +10,14 @@ export const getSession = async () => {
return session;
};
+export const userSelectProps = {
+ userId: users.id,
+ email: users.email,
+ name: users.name,
+ image: users.image,
+ createdAt: users.created_at,
+};
+
export const getCurrentUser = async () => {
const session = await getServerSession(authOptions);
@@ -18,13 +26,7 @@ export const getCurrentUser = async () => {
}
const [currentUser] = await db
- .select({
- userId: users.id,
- email: users.email,
- name: users.name,
- image: users.image,
- createdAt: users.created_at,
- })
+ .select(userSelectProps)
.from(users)
.where(eq(users.id, session?.user.id));
diff --git a/packages/utils/src/helpers.ts b/packages/utils/src/helpers.ts
index 71ed62e4a..1be60f078 100644
--- a/packages/utils/src/helpers.ts
+++ b/packages/utils/src/helpers.ts
@@ -15,3 +15,18 @@ export const uuidFormat = (uuid: string) => {
export const CAP_LOGO_URL =
"https://raw.githubusercontent.com/CapSoftware/cap/main/app-icon.png";
+
+export function debounce(
+ func: (...args: any[]) => void,
+ wait: number | undefined
+) {
+ let timeout: number | undefined;
+ return function executedFunction(...args: any[]) {
+ const later = () => {
+ clearTimeout(timeout);
+ func(...args);
+ };
+ clearTimeout(timeout);
+ timeout = setTimeout(later, wait);
+ };
+}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 16e1adf99..680a44953 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -159,6 +159,9 @@ importers:
hls.js:
specifier: ^1.5.3
version: 1.5.3
+ lodash:
+ specifier: ^4.17.21
+ version: 4.17.21
lucide-react:
specifier: ^0.294.0
version: 0.294.0([email protected])
@@ -7323,7 +7326,6 @@ packages:
resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==}
- dev: true
resolution: {integrity: sha512-dSkNGuI7iG3mfvDzUuYZyvk5dD9ocYCYzNU6CYDE6+Xqd+gwme6Z00NS3dUh8mq/73HaEtT7m6W+yUPtU6BZnQ==}