Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

wip: Bento script + Recording page

Richie McIlroy88dd30e06202
diff --git a/apps/web/app/api/upload/new/route.ts b/apps/web/app/api/upload/new/route.ts
index ae9b71493..b041b9b0c 100644
--- a/apps/web/app/api/upload/new/route.ts
+++ b/apps/web/app/api/upload/new/route.ts
@@ -9,9 +9,11 @@ export async function POST(request: NextRequest) {
const formData = await request.formData();
const filename = formData.get("filename");
const videoId = formData.get("videoId");
- const blobData = formData.get("blobData");
-
- console.log("filename:", filename);
+ const blobData = formData.get("blobData") as Blob;
+ const duration = formData.get("duration");
+ const resolution = formData.get("resolution");
+ const videoCodec = formData.get("videoCodec");
+ const audioCodec = formData.get("audioCodec");
if (!user || !awsRegion || !awsBucket || !filename || !blobData) {
console.error("Missing required data in /api/upload/new/route.ts");
@@ -24,15 +26,19 @@ export async function POST(request: NextRequest) {
});
}
- const fullFilepath = `${user.userId}/${videoId}/${filename}`;
+ const fullFilepath = `${user.id}/${videoId}/${filename}`;
- const upload = await uploadToS3(
- fullFilepath,
+ const upload = await uploadToS3({
+ filename: fullFilepath,
+ userId: user.id,
blobData,
- user.userId,
+ duration: duration as string,
+ resolution: resolution as string,
+ videoCodec: videoCodec as string,
+ audioCodec: audioCodec as string,
awsBucket,
- awsRegion
- );
+ awsRegion,
+ });
if (!upload) {
console.error("Upload failed");
diff --git a/apps/web/app/api/webhooks/stripe/route.ts b/apps/web/app/api/webhooks/stripe/route.ts
index 9957fa127..ab13c28e9 100644
--- a/apps/web/app/api/webhooks/stripe/route.ts
+++ b/apps/web/app/api/webhooks/stripe/route.ts
@@ -1,265 +1,265 @@
-import prisma from "@/lib/prisma";
-import { stripe } from "@/lib/stripe";
-import { redis } from "@/lib/upstash";
-import { db } from "@cap/database";
-import { users } from "@cap/database/schema";
-import { FREE_PLAN, getPlanFromPriceId, log } from "@dub/utils";
-import { eq } from "drizzle-orm";
-import { sendEmail } from "emails";
-import UpgradeEmail from "emails/upgrade-email";
-import { NextResponse } from "next/server";
-import Stripe from "stripe";
+// import prisma from "@/lib/prisma";
+// import { stripe } from "@/lib/stripe";
+// import { redis } from "@/lib/upstash";
+// import { db } from "@cap/database";
+// import { users } from "@cap/database/schema";
+// import { FREE_PLAN, getPlanFromPriceId, log } from "@dub/utils";
+// import { eq } from "drizzle-orm";
+// import { sendEmail } from "emails";
+// import UpgradeEmail from "emails/upgrade-email";
+// import { NextResponse } from "next/server";
+// import Stripe from "stripe";
-const relevantEvents = new Set([
- "checkout.session.completed",
- "customer.subscription.updated",
- "customer.subscription.deleted",
-]);
+// const relevantEvents = new Set([
+// "checkout.session.completed",
+// "customer.subscription.updated",
+// "customer.subscription.deleted",
+// ]);
-// POST /api/callback/stripe – listen to Stripe webhooks
-export const POST = async (req: Request) => {
- const buf = await req.text();
- const sig = req.headers.get("Stripe-Signature") as string;
- const webhookSecret = process.env.STRIPE_WEBHOOK_SECRET;
- let event: Stripe.Event;
- try {
- if (!sig || !webhookSecret) return;
- event = stripe.webhooks.constructEvent(buf, sig, webhookSecret);
- } catch (err: any) {
- console.log(`❌ Error message: ${err.message}`);
- return new Response(`Webhook Error: ${err.message}`, {
- status: 400,
- });
- }
- if (relevantEvents.has(event.type)) {
- try {
- if (event.type === "checkout.session.completed") {
- const checkoutSession = event.data.object as Stripe.Checkout.Session;
+// // POST /api/callback/stripe – listen to Stripe webhooks
+// export const POST = async (req: Request) => {
+// const buf = await req.text();
+// const sig = req.headers.get("Stripe-Signature") as string;
+// const webhookSecret = process.env.STRIPE_WEBHOOK_SECRET;
+// let event: Stripe.Event;
+// try {
+// if (!sig || !webhookSecret) return;
+// event = stripe.webhooks.constructEvent(buf, sig, webhookSecret);
+// } catch (err: any) {
+// console.log(`❌ Error message: ${err.message}`);
+// return new Response(`Webhook Error: ${err.message}`, {
+// status: 400,
+// });
+// }
+// if (relevantEvents.has(event.type)) {
+// try {
+// if (event.type === "checkout.session.completed") {
+// const checkoutSession = event.data.object as Stripe.Checkout.Session;
- if (
- checkoutSession.client_reference_id === null ||
- checkoutSession.customer === null
- ) {
- await log({
- message: "Missing items in Stripe webhook callback",
- type: "errors",
- });
- return;
- }
+// if (
+// checkoutSession.client_reference_id === null ||
+// checkoutSession.customer === null
+// ) {
+// await log({
+// message: "Missing items in Stripe webhook callback",
+// type: "errors",
+// });
+// return;
+// }
- const subscription = await stripe.subscriptions.retrieve(
- checkoutSession.subscription as string
- );
- const priceId = subscription.items.data[0].price.id;
+// const subscription = await stripe.subscriptions.retrieve(
+// checkoutSession.subscription as string
+// );
+// const priceId = subscription.items.data[0].price.id;
- const plan = getPlanFromPriceId(priceId);
+// const plan = getPlanFromPriceId(priceId);
- if (!plan) {
- await log({
- message: `Invalid price ID in checkout.session.completed event: ${priceId}`,
- type: "errors",
- });
- return;
- }
+// if (!plan) {
+// await log({
+// message: `Invalid price ID in checkout.session.completed event: ${priceId}`,
+// type: "errors",
+// });
+// return;
+// }
- const stripeId = checkoutSession.customer.toString();
+// const stripeId = checkoutSession.customer.toString();
- // when the workspace subscribes to a plan, set their stripe customer ID
- // in the database for easy identification in future webhook events
- // also update the billingCycleStart to today's date
+// // when the workspace subscribes to a plan, set their stripe customer ID
+// // in the database for easy identification in future webhook events
+// // also update the billingCycleStart to today's date
- let referenceId;
- let isSpaceCustomer = false;
- if (checkoutSession.metadata?.space_id) {
- isSpaceCustomer = true;
- referenceId = checkoutSession.metadata?.space_id;
- } else {
- referenceId = checkoutSession.client_reference_id;
- }
+// let referenceId;
+// let isSpaceCustomer = false;
+// if (checkoutSession.metadata?.space_id) {
+// isSpaceCustomer = true;
+// referenceId = checkoutSession.metadata?.space_id;
+// } else {
+// referenceId = checkoutSession.client_reference_id;
+// }
- if (isSpaceCustomer === false) {
- await db
- .update(users)
- .set({
- stripeCustomerId: stripeId,
- stripeSubscriptionId: subscription.id,
- stripeSubscriptionStatus: subscription.status,
- stripeSubscriptionPriceId: priceId,
- })
- .where(eq(users.id, referenceId));
- } else {
- }
+// if (isSpaceCustomer === false) {
+// await db
+// .update(users)
+// .set({
+// stripeCustomerId: stripeId,
+// stripeSubscriptionId: subscription.id,
+// stripeSubscriptionStatus: subscription.status,
+// stripeSubscriptionPriceId: priceId,
+// })
+// .where(eq(users.id, referenceId));
+// } else {
+// }
- sendEmail({
- email: users.email
- subject: `Thank you for upgrading to Cap Pro!`,
- react: UpgradeEmail({
- name: user.name,
- email: user.email as string,
- plan: plan.name,
- }),
- marketing: true,
- });
- }
+// sendEmail({
+// email: users.email
+// subject: `Thank you for upgrading to Cap Pro!`,
+// react: UpgradeEmail({
+// name: user.name,
+// email: user.email as string,
+// plan: plan.name,
+// }),
+// marketing: true,
+// });
+// }
- // for subscription updates
- if (event.type === "customer.subscription.updated") {
- const subscriptionUpdated = event.data.object as Stripe.Subscription;
- const priceId = subscriptionUpdated.items.data[0].price.id;
+// // for subscription updates
+// if (event.type === "customer.subscription.updated") {
+// const subscriptionUpdated = event.data.object as Stripe.Subscription;
+// const priceId = subscriptionUpdated.items.data[0].price.id;
- const plan = getPlanFromPriceId(priceId);
+// const plan = getPlanFromPriceId(priceId);
- if (!plan) {
- await log({
- message: `Invalid price ID in customer.subscription.updated event: ${priceId}`,
- type: "errors",
- });
- return;
- }
+// if (!plan) {
+// await log({
+// message: `Invalid price ID in customer.subscription.updated event: ${priceId}`,
+// type: "errors",
+// });
+// return;
+// }
- const stripeId = subscriptionUpdated.customer.toString();
+// const stripeId = subscriptionUpdated.customer.toString();
- const workspace = await prisma.project.findUnique({
- where: {
- stripeId,
- },
- });
+// const workspace = await prisma.project.findUnique({
+// where: {
+// stripeId,
+// },
+// });
- if (!workspace) {
- await log({
- message:
- "Workspace with Stripe ID *`" +
- stripeId +
- "`* not found in Stripe webhook `customer.subscription.updated` callback",
- type: "errors",
- });
- return NextResponse.json({ received: true });
- }
+// if (!workspace) {
+// await log({
+// message:
+// "Workspace with Stripe ID *`" +
+// stripeId +
+// "`* not found in Stripe webhook `customer.subscription.updated` callback",
+// type: "errors",
+// });
+// return NextResponse.json({ received: true });
+// }
- const newPlan = plan.name.toLowerCase();
+// const newPlan = plan.name.toLowerCase();
- // If a workspace upgrades/downgrades their subscription, update their usage limit in the database.
- if (workspace.plan !== newPlan) {
- await prisma.project.update({
- where: {
- stripeId,
- },
- data: {
- plan: newPlan,
- usageLimit: plan.limits.clicks!,
- linksLimit: plan.limits.links!,
- domainsLimit: plan.limits.domains!,
- tagsLimit: plan.limits.tags!,
- usersLimit: plan.limits.users!,
- },
- });
- }
- }
+// // If a workspace upgrades/downgrades their subscription, update their usage limit in the database.
+// if (workspace.plan !== newPlan) {
+// await prisma.project.update({
+// where: {
+// stripeId,
+// },
+// data: {
+// plan: newPlan,
+// usageLimit: plan.limits.clicks!,
+// linksLimit: plan.limits.links!,
+// domainsLimit: plan.limits.domains!,
+// tagsLimit: plan.limits.tags!,
+// usersLimit: plan.limits.users!,
+// },
+// });
+// }
+// }
- // If workspace cancels their subscription
- if (event.type === "customer.subscription.deleted") {
- const subscriptionDeleted = event.data.object as Stripe.Subscription;
+// // If workspace cancels their subscription
+// if (event.type === "customer.subscription.deleted") {
+// const subscriptionDeleted = event.data.object as Stripe.Subscription;
- const stripeId = subscriptionDeleted.customer.toString();
+// const stripeId = subscriptionDeleted.customer.toString();
- // If a workspace deletes their subscription, reset their usage limit in the database to 1000.
- // Also remove the root domain redirect for all their domains from Redis.
- const workspace = await prisma.project.findUnique({
- where: {
- stripeId,
- },
- select: {
- id: true,
- slug: true,
- domains: true,
- users: {
- select: {
- user: {
- select: {
- email: true,
- },
- },
- },
- },
- },
- });
+// // If a workspace deletes their subscription, reset their usage limit in the database to 1000.
+// // Also remove the root domain redirect for all their domains from Redis.
+// const workspace = await prisma.project.findUnique({
+// where: {
+// stripeId,
+// },
+// select: {
+// id: true,
+// slug: true,
+// domains: true,
+// users: {
+// select: {
+// user: {
+// select: {
+// email: true,
+// },
+// },
+// },
+// },
+// },
+// });
- if (!workspace) {
- await log({
- message:
- "Workspace with Stripe ID *`" +
- stripeId +
- "`* not found in Stripe webhook `customer.subscription.deleted` callback",
- type: "errors",
- });
- return NextResponse.json({ received: true });
- }
+// if (!workspace) {
+// await log({
+// message:
+// "Workspace with Stripe ID *`" +
+// stripeId +
+// "`* not found in Stripe webhook `customer.subscription.deleted` callback",
+// type: "errors",
+// });
+// return NextResponse.json({ received: true });
+// }
- const workspaceUsers = workspace.users.map(
- ({ user }) => user.email as string
- );
+// const workspaceUsers = workspace.users.map(
+// ({ user }) => user.email as string
+// );
- const pipeline = redis.pipeline();
- // remove root domain redirect for all domains
- workspace.domains.forEach((domain) => {
- pipeline.hset(domain.slug.toLowerCase(), {
- _root: {
- id: domain.id,
- projectId: workspace.id,
- },
- });
- });
+// const pipeline = redis.pipeline();
+// // remove root domain redirect for all domains
+// workspace.domains.forEach((domain) => {
+// pipeline.hset(domain.slug.toLowerCase(), {
+// _root: {
+// id: domain.id,
+// projectId: workspace.id,
+// },
+// });
+// });
- await Promise.allSettled([
- prisma.project.update({
- where: {
- stripeId,
- },
- data: {
- plan: "free",
- usageLimit: FREE_PLAN.limits.clicks!,
- linksLimit: FREE_PLAN.limits.links!,
- domainsLimit: FREE_PLAN.limits.domains!,
- tagsLimit: FREE_PLAN.limits.tags!,
- usersLimit: FREE_PLAN.limits.users!,
- },
- }),
- pipeline.exec(),
- log({
- message:
- ":cry: Workspace *`" +
- workspace.slug +
- "`* deleted their subscription",
- type: "cron",
- mention: true,
- }),
- workspaceUsers.map((email) =>
- sendEmail({
- email,
- subject: "Feedback on your Dub.co experience?",
- text: "Hey!\n\nI noticed you recently cancelled your Dub.co subscription – we're sorry to see you go!\n\nI'd love to hear your feedback on your experience with Dub – what could we have done better?\n\nThanks!\n\nSteven Tey\nFounder, Dub.co",
- })
- ),
- ]);
- }
- } catch (error) {
- await log({
- message: `Stripe webook failed. Error: ${error.message}`,
- type: "errors",
- });
- return new Response(
- 'Webhook error: "Webhook handler failed. View logs."',
- {
- status: 400,
- }
- );
- }
- } else {
- return new Response(`🤷‍♀️ Unhandled event type: ${event.type}`, {
- status: 400,
- });
- }
+// await Promise.allSettled([
+// prisma.project.update({
+// where: {
+// stripeId,
+// },
+// data: {
+// plan: "free",
+// usageLimit: FREE_PLAN.limits.clicks!,
+// linksLimit: FREE_PLAN.limits.links!,
+// domainsLimit: FREE_PLAN.limits.domains!,
+// tagsLimit: FREE_PLAN.limits.tags!,
+// usersLimit: FREE_PLAN.limits.users!,
+// },
+// }),
+// pipeline.exec(),
+// log({
+// message:
+// ":cry: Workspace *`" +
+// workspace.slug +
+// "`* deleted their subscription",
+// type: "cron",
+// mention: true,
+// }),
+// workspaceUsers.map((email) =>
+// sendEmail({
+// email,
+// from: "[email protected]",
+// subject: "Feedback on your Dub.co experience?",
+// text: "Hey!\n\nI noticed you recently cancelled your Dub.co subscription – we're sorry to see you go!\n\nI'd love to hear your feedback on your experience with Dub – what could we have done better?\n\nThanks!\n\nSteven Tey\nFounder, Dub.co",
+// })
+// ),
+// ]);
+// }
+// } catch (error) {
+// await log({
+// message: `Stripe webook failed. Error: ${error.message}`,
+// type: "errors",
+// });
+// return new Response(
+// 'Webhook error: "Webhook handler failed. View logs."',
+// {
+// status: 400,
+// }
+// );
+// }
+// } else {
+// return new Response(`🤷‍♀️ Unhandled event type: ${event.type}`, {
+// status: 400,
+// });
+// }
- return NextResponse.json({ received: true });
-};
+// return NextResponse.json({ received: true });
+// };
diff --git a/apps/web/app/dashboard/_components/AdminNavbar/AdminNavItems.tsx b/apps/web/app/dashboard/_components/AdminNavbar/AdminNavItems.tsx
index 519f6f632..c2e41295a 100644
--- a/apps/web/app/dashboard/_components/AdminNavbar/AdminNavItems.tsx
+++ b/apps/web/app/dashboard/_components/AdminNavbar/AdminNavItems.tsx
@@ -94,7 +94,7 @@ export const AdminNavItems = () => {
{spaceData !== null &&
spaceData?.map((space) => (
<CommandItem
- key={space.name}
+ key={space.name + "-space"}
// onSelect={async () => {
// await handleActiveSpace(space.id);
// router.refresh();
@@ -129,7 +129,7 @@ export const AdminNavItems = () => {
<Link
passHref
prefetch={false}
- key={item.name}
+ key={item.name + "-main"}
href={item.href}
className={classNames(
pathname.includes(item.href)
@@ -150,7 +150,7 @@ export const AdminNavItems = () => {
<Link
passHref
prefetch={false}
- key={subItem.name}
+ key={subItem.name + "-sub"}
href={subItem.href}
className={classNames(
pathname === subItem.href
diff --git a/apps/web/app/globals.css b/apps/web/app/globals.css
index af503b801..50dccbd3f 100644
--- a/apps/web/app/globals.css
+++ b/apps/web/app/globals.css
@@ -348,3 +348,19 @@ slot:not(.dashboard-layout slot) {
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000),
var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
}
+
+.resize-handle {
+ display: none;
+}
+
+.rnd:hover .resize-handle {
+ display: block;
+}
+
+.crosshair {
+ display: none;
+}
+
+body.react-draggable-transparent-selection .crosshair {
+ display: block;
+}
diff --git a/apps/web/app/layout.tsx b/apps/web/app/layout.tsx
index 677085d68..0420be0a7 100644
--- a/apps/web/app/layout.tsx
+++ b/apps/web/app/layout.tsx
@@ -4,6 +4,7 @@ import { Navbar } from "@/components/Navbar";
import { Footer } from "@/components/Footer";
import type { Metadata } from "next";
import { getCurrentUser } from "@cap/database/auth/session";
+import { BentoScript } from "@/components/BentoScript";
export const metadata: Metadata = {
title:
@@ -65,6 +66,7 @@ export default async function RootLayout({
data-domain="cap.so"
src="https://plausible.io/js/script.js"
></script>
+ <BentoScript user={user} />
</body>
</html>
);
diff --git a/apps/web/app/record/Record.tsx b/apps/web/app/record/Record.tsx
index fced39fd5..3d1f31da9 100644
--- a/apps/web/app/record/Record.tsx
+++ b/apps/web/app/record/Record.tsx
@@ -1,8 +1,25 @@
"use client";
+//
+// WARNING!!
+// WARNING!!
+// WARNING!!
+// WARNING!!
+//
+// This code is currently quite horrific.
+// It is a work in progress and will be refactored.
+// Pls do not judge me.
+// Shipping > perfection.
+//
+//
+//
+//
+//
+//
+
import { useState, useEffect, useRef } from "react";
import { users } from "@cap/database/schema";
-import { Mic, Video, Monitor } from "lucide-react";
+import { Mic, Video, Monitor, ArrowLeft } from "lucide-react";
import { Rnd } from "react-rnd";
import {
Button,
@@ -11,9 +28,12 @@ import {
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
+ LogoSpinner,
} from "@cap/ui";
import { ActionButton } from "./_components/ActionButton";
import toast from "react-hot-toast";
+import { FFmpeg } from "@ffmpeg/ffmpeg";
+import { fetchFile } from "@ffmpeg/util";
// million-ignore
export const Record = ({
@@ -21,6 +41,8 @@ export const Record = ({
}: {
user: typeof users.$inferSelect | null;
}) => {
+ const ffmpegRef = useRef(new FFmpeg());
+ const [isLoading, setIsLoading] = useState(true);
const [startingRecording, setStartingRecording] = useState(false);
const [stoppingRecording, setStoppingRecording] = useState(false);
const [isRecording, setIsRecording] = useState(false);
@@ -36,23 +58,87 @@ export const Record = ({
useState("Microphone");
const [selectedVideoDeviceLabel, setSelectedVideoDeviceLabel] =
useState("Webcam");
-
- const [showAudioOptions, setShowAudioOptions] = useState(false);
- const [showVideoOptions, setShowVideoOptions] = useState(false);
const [screenStream, setScreenStream] = useState<MediaStream | null>(null);
const [videoStream, setVideoStream] = useState<MediaStream | null>(null);
- const [combinedStream, setCombinedStream] = useState<MediaStream | null>(
+ const videoSegmentsRef = useRef<Blob[]>([]);
+ const [videoRecorder, setVideoRecorder] = useState<MediaRecorder | null>(
null
);
- const [mediaRecorder, setMediaRecorder] = useState<MediaRecorder | null>(
- null
- );
- const [recordedBlobs, setRecordedBlobs] = useState<Blob[]>([]);
+ const totalSegments = useRef(0);
+
const screenPreviewRef = useRef<HTMLVideoElement>(null);
const webcamPreviewRef = useRef<HTMLVideoElement>(null);
+ const [aspectRatio, setAspectRatio] = useState(1.7777777778);
+ const [webcamStyleSettings, setWebcamStyleSettings] = useState({
+ x: 16,
+ y: 16,
+ width: 180,
+ height: 180,
+ });
+ const [screenStyleSettings, setScreenStyleSettings] = useState({
+ x: 0,
+ y: 0,
+ width: "100%" as any,
+ height: "100%" as any,
+ });
+
+ const [isCenteredHorizontally, setIsCenteredHorizontally] = useState(false);
+ const [isCenteredVertically, setIsCenteredVertically] = useState(false);
+
+ const defaultRndHandeStyles = {
+ topLeft: {
+ width: "16px",
+ height: "16px",
+ borderRadius: "50%",
+ backgroundColor: "white",
+ border: "2px solid #ddd",
+ zIndex: 999,
+ boxShadow: "0 2px 4px rgba(0, 0, 0, 0.1)",
+ },
+ topRight: {
+ width: "16px",
+ height: "16px",
+ borderRadius: "50%",
+ backgroundColor: "white",
+ border: "2px solid #ddd",
+ zIndex: 999,
+ boxShadow: "0 2px 4px rgba(0, 0, 0, 0.1)",
+ },
+ bottomLeft: {
+ width: "16px",
+ height: "16px",
+ borderRadius: "50%",
+ backgroundColor: "white",
+ border: "2px solid #ddd",
+ zIndex: 999,
+ boxShadow: "0 2px 4px rgba(0, 0, 0, 0.1)",
+ },
+ bottomRight: {
+ width: "16px",
+ height: "16px",
+ borderRadius: "50%",
+ backgroundColor: "white",
+ border: "2px solid #ddd",
+ zIndex: 999,
+ boxShadow: "0 2px 4px rgba(0, 0, 0, 0.1)",
+ },
+ };
+
+ useEffect(() => {
+ const loadFFmpeg = async () => {
+ setIsLoading(true);
+ const ffmpeg = ffmpegRef.current;
- const buttonStyles =
- "w-full h-full flex flex-col items-center justify-center text-center space-y-1 py-2 pl-5 pr-7 group-hover:bg-gray-300 rounded-xl";
+ console.log("Loading FFmpeg");
+
+ await ffmpeg.load();
+ setIsLoading(false);
+
+ console.log("FFmpeg loaded");
+ };
+
+ loadFFmpeg();
+ }, []);
const getDevices = async () => {
try {
@@ -76,7 +162,7 @@ export const Record = ({
try {
const displayMediaOptions = {
video: {
- displaySurface: "browser",
+ displaySurface: "window",
},
audio: false,
surfaceSwitching: "exclude",
@@ -87,21 +173,77 @@ export const Record = ({
const stream = await navigator.mediaDevices.getDisplayMedia(
displayMediaOptions
);
- setScreenStream(stream);
+ const videoElement = document.createElement("video");
+ videoElement.srcObject = stream;
+
+ return new Promise((resolve) => {
+ videoElement.onloadedmetadata = () => {
+ const { videoWidth, videoHeight } = videoElement;
+ const aspectRatio = videoWidth / videoHeight;
+ setAspectRatio(aspectRatio);
+ setScreenStream(stream);
+ console.log("videoWidth", videoWidth);
+ console.log("videoHeight", videoHeight);
+ console.log("aspectRatio", aspectRatio);
+ setScreenStyleSettings({
+ x: 0,
+ y: 0,
+ width: "100%",
+ height: "100%",
+ });
+ startVideoCapture(selectedVideoDevice, "small");
+ resolve({ width: videoWidth, height: videoHeight });
+ };
+ });
} catch (error) {
console.error("Error capturing screen:", error);
}
};
- const startVideoCapture = async (deviceId?: string) => {
+ const startVideoCapture = async (
+ deviceId?: string,
+ placement?: "small" | "large"
+ ) => {
try {
const constraints: MediaStreamConstraints = {
video: deviceId ? { deviceId } : true,
audio: selectedAudioDevice ? { deviceId: selectedAudioDevice } : false,
};
+ console.log("Video constraints:", constraints);
+
const stream = await navigator.mediaDevices.getUserMedia(constraints);
setVideoStream(stream);
+
+ const videoContainer = document.querySelector(
+ ".video-container"
+ ) as HTMLElement;
+
+ if (videoContainer === null) {
+ console.error("Video container dimensions not found");
+ return;
+ }
+
+ const videoContainerWidth = videoContainer.clientWidth;
+ const videoContainerHeight = videoContainer.clientHeight;
+
+ if (placement === "large") {
+ setWebcamStyleSettings({
+ x: (videoContainerWidth - videoContainerWidth / 2) / 2,
+ y: (videoContainerHeight - videoContainerWidth / 2) / 2,
+ width: videoContainerWidth / 2,
+ height: videoContainerWidth / 2,
+ });
+ } else if (placement === "small") {
+ const webcamWidth = 180;
+
+ setWebcamStyleSettings({
+ x: 16,
+ y: videoContainer.clientHeight - 16 - webcamWidth,
+ width: webcamWidth,
+ height: webcamWidth,
+ });
+ }
} catch (error) {
console.error("Error capturing video:", error);
}
@@ -122,6 +264,34 @@ export const Record = ({
};
const startRecording = async () => {
+ const res = await fetch(
+ `${process.env.NEXT_PUBLIC_URL}/api/desktop/video/create`,
+ {
+ method: "GET",
+ credentials: "include",
+ cache: "no-store",
+ }
+ );
+
+ if (res.status === 401) {
+ console.error("Unauthorized");
+ toast.error("Unauthorized - please sign in again.");
+ return;
+ }
+
+ const videoCreateData = await res.json();
+
+ if (
+ !videoCreateData.id ||
+ !videoCreateData.user_id ||
+ !videoCreateData.aws_region ||
+ !videoCreateData.aws_bucket
+ ) {
+ console.error("No data received");
+ toast.error("No data received - please try again later.");
+ return;
+ }
+
if (screenStream && videoStream) {
setStartingRecording(true);
@@ -129,69 +299,103 @@ export const Record = ({
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d");
- const screenSize = screenStream.getVideoTracks()[0].getSettings();
- canvas.width = screenSize.width ?? 1280;
- canvas.height = screenSize.height ?? 720;
+ // Get the video container element
+ const videoContainer = document.querySelector(
+ ".video-container"
+ ) as HTMLElement;
+
+ // Set the minimum width to 1000 pixels
+ const minWidth = 1000;
+
+ // Calculate the aspect ratio of the video container
+ const aspectRatio =
+ videoContainer.clientWidth / videoContainer.clientHeight;
+
+ // Set the canvas width to the minimum width or the video container width, whichever is larger
+ canvas.width = Math.max(minWidth, videoContainer.clientWidth);
+
+ // Calculate the canvas height based on the width and aspect ratio
+ canvas.height = canvas.width / aspectRatio;
let animationFrameId: number;
const drawCanvas = () => {
if (ctx) {
- ctx.drawImage(
- document.getElementById("screenPreview") as HTMLVideoElement,
- 0,
- 0,
- canvas.width,
- canvas.height
- );
+ // Clear the canvas
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
+
+ // Get the current position and size of the screen preview
+ const screenPreview = document.getElementById(
+ "screenPreview"
+ ) as HTMLVideoElement;
+ const screenRect = screenPreview.getBoundingClientRect();
+ const containerRect = document
+ .querySelector(".video-container")
+ ?.getBoundingClientRect();
+
+ if (containerRect) {
+ const screenX = screenRect.left - containerRect.left;
+ const screenY = screenRect.top - containerRect.top;
+ const screenWidth = screenRect.width;
+ const screenHeight = screenRect.height;
+
+ // Draw the screen preview on the canvas based on its position and size
+ ctx.drawImage(
+ screenPreview,
+ screenX,
+ screenY,
+ screenWidth,
+ screenHeight
+ );
+ }
// Get the current position and size of the webcam preview
const webcamPreview = document.getElementById(
"webcamPreview"
) as HTMLVideoElement;
const webcamRect = webcamPreview.getBoundingClientRect();
- const containerRect = document
- .querySelector(".aspect-w-16.aspect-h-9")
- ?.getBoundingClientRect();
if (containerRect) {
- const scaleX = canvas.width / containerRect.width;
- const scaleY = canvas.height / containerRect.height;
-
- const camWidth = webcamRect.width * scaleX;
- const camHeight = webcamRect.height * scaleY;
- const camX = (webcamRect.left - containerRect.left) * scaleX;
- const camY = (webcamRect.top - containerRect.top) * scaleY;
-
- // Calculate the aspect ratio of the original webcam video
- const videoWidth = webcamPreview.videoWidth;
- const videoHeight = webcamPreview.videoHeight;
- const aspectRatio = videoWidth / videoHeight;
-
- // Adjust the webcam preview size to maintain the aspect ratio
- let newWidth = camWidth;
- let newHeight = camWidth / aspectRatio;
- if (newHeight > camHeight) {
- newWidth = camHeight * aspectRatio;
- newHeight = camHeight;
+ const camX = webcamRect.left - containerRect.left;
+ const camY = webcamRect.top - containerRect.top;
+ const camWidth = webcamRect.width;
+ const camHeight = webcamRect.height;
+
+ // Calculate the aspect ratio of the webcam video
+ const videoAspectRatio =
+ webcamPreview.videoWidth / webcamPreview.videoHeight;
+
+ // Calculate the new dimensions to maintain the aspect ratio
+ let newCamWidth = camWidth;
+ let newCamHeight = camHeight;
+ if (camWidth / camHeight > videoAspectRatio) {
+ newCamWidth = camHeight * videoAspectRatio;
+ } else {
+ newCamHeight = camWidth / videoAspectRatio;
}
- // Calculate the position to center the adjusted webcam preview
- const centerX = camX + (camWidth - newWidth) / 2;
- const centerY = camY + (camHeight - newHeight) / 2;
+ // Calculate the offset to center the webcam video
+ const offsetX = (camWidth - newCamWidth) / 2;
+ const offsetY = (camHeight - newCamHeight) / 2;
// Set the position and size of the circular webcam preview on the canvas
ctx.save();
ctx.beginPath();
ctx.arc(
- centerX + newWidth / 2,
- centerY + newHeight / 2,
- Math.min(newWidth, newHeight) / 2,
+ camX + camWidth / 2,
+ camY + camHeight / 2,
+ Math.min(newCamWidth, newCamHeight) / 2,
0,
2 * Math.PI
);
ctx.clip();
- ctx.drawImage(webcamPreview, centerX, centerY, newWidth, newHeight);
+ ctx.drawImage(
+ webcamPreview,
+ camX + offsetX,
+ camY + offsetY,
+ newCamWidth,
+ newCamHeight
+ );
ctx.restore();
}
@@ -200,8 +404,13 @@ export const Record = ({
};
drawCanvas();
-
const canvasStream = canvas.captureStream(30);
+ if (canvasStream.getVideoTracks().length === 0) {
+ console.error("Canvas stream has no video tracks");
+ setStartingRecording(false);
+ return;
+ }
+
canvasStream
.getVideoTracks()
.forEach((track) => combinedStream.addTrack(track));
@@ -210,39 +419,288 @@ export const Record = ({
.getAudioTracks()
.forEach((track) => combinedStream.addTrack(track));
- setCombinedStream(combinedStream);
+ const videoRecorderOptions = {
+ mimeType: 'video/webm; codecs="h264"',
+ };
- const options = { mimeType: "video/webm; codecs=vp9,opus" };
- const mediaRecorder = new MediaRecorder(combinedStream, options);
- const recordedChunks: Blob[] = [];
+ if (!MediaRecorder.isTypeSupported(videoRecorderOptions.mimeType)) {
+ console.error("Video MIME type not supported");
+ setStartingRecording(false);
+ return;
+ }
- mediaRecorder.ondataavailable = function (event) {
- if (event.data.size > 0) recordedChunks.push(event.data);
- };
+ const videoRecorder = new MediaRecorder(
+ combinedStream,
+ videoRecorderOptions
+ );
- mediaRecorder.onstop = () => {
- cancelAnimationFrame(animationFrameId);
- const recordedBlob = new Blob(recordedChunks, { type: "video/webm" });
- console.log("Recorded Blob:", recordedBlob);
- setRecordedBlobs([recordedBlob]);
+ const videoBitsPerSecond = videoRecorder.videoBitsPerSecond;
+
+ const videoTracks = canvasStream.getVideoTracks();
+ const frameRate = videoTracks[0].getSettings().frameRate || 30;
+
+ const resolution = `${canvas.width}x${canvas.height}`;
+
+ videoRecorder.ondataavailable = async (event) => {
+ if (event.data.size > 0) {
+ videoSegmentsRef.current.push(event.data);
+ console.log("Video segment pushed:", event.data);
+
+ await muxSegment({
+ videoId: videoCreateData.id,
+ bandwidth: videoBitsPerSecond,
+ framerate: frameRate,
+ resolution,
+ });
+ }
};
- mediaRecorder.start();
+ videoRecorder.start(3000);
+
+ setVideoRecorder(videoRecorder);
+
setIsRecording(true);
setStartingRecording(false);
- setMediaRecorder(mediaRecorder);
} else {
toast.error("No source selected for recording");
}
};
+ const muxSegment = async ({
+ videoId,
+ bandwidth,
+ framerate,
+ resolution,
+ }: {
+ videoId: string;
+ bandwidth: number;
+ framerate: number;
+ resolution: string;
+ }) => {
+ if (ffmpegRef.current && videoSegmentsRef.current.length > 0) {
+ console.log("Muxing segment");
+
+ const videoSegment = videoSegmentsRef.current.shift();
+
+ if (videoSegment) {
+ const videoFile = await fetchFile(URL.createObjectURL(videoSegment));
+
+ ffmpegRef.current.writeFile("video_segment.webm", videoFile);
+
+ await ffmpegRef.current.exec([
+ "-i",
+ "video_segment.webm",
+ "-c:v",
+ "copy",
+ "-f",
+ "mpegts",
+ "video_segment.ts",
+ ]);
+
+ await ffmpegRef.current.exec([
+ "-i",
+ "video_segment.webm",
+ "-vn",
+ "-c:a",
+ "aac",
+ "-b:a",
+ "128k",
+ "audio_segment.aac",
+ ]);
+
+ const videoData = await ffmpegRef.current.readFile("video_segment.ts");
+ const audioData = await ffmpegRef.current.readFile("audio_segment.aac");
+
+ const segmentIndex = String(totalSegments.current).padStart(3, "0");
+ const videoSegmentFilename = `video/video_recording_${segmentIndex}.ts`;
+ const audioSegmentFilename = `audio/audio_recording_${segmentIndex}.aac`;
+
+ console.log("Uploading segment:", videoSegmentFilename);
+ console.log("Uploading segment:", audioSegmentFilename);
+
+ await uploadSegment({
+ file: videoData,
+ filename: videoSegmentFilename,
+ videoId: videoId,
+ duration: 3,
+ resolution,
+ bandwidth,
+ videoCodec: "vp9",
+ });
+
+ await uploadSegment({
+ file: audioData,
+ filename: audioSegmentFilename,
+ videoId: videoId,
+ duration: 3,
+ audioCodec: "aac",
+ });
+
+ totalSegments.current++;
+ }
+ }
+ };
+
+ const uploadSegment = async ({
+ file,
+ filename,
+ videoId,
+ duration = 3,
+ resolution,
+ bandwidth,
+ videoCodec,
+ audioCodec,
+ }: {
+ file: Uint8Array | string;
+ filename: string;
+ videoId: string;
+ duration?: number;
+ resolution?: string;
+ bandwidth?: number;
+ videoCodec?: string;
+ audioCodec?: string;
+ }) => {
+ const formData = new FormData();
+ formData.append("filename", filename);
+ formData.append("videoId", videoId);
+ formData.append("blobData", new Blob([file], { type: "video/mp2t" }));
+ formData.append("duration", String(duration));
+ formData.append("resolution", resolution || "");
+ formData.append("bandwidth", String(bandwidth || 0));
+ formData.append("videoCodec", videoCodec || "");
+ formData.append("audioCodec", audioCodec || "");
+
+ await fetch(`${process.env.NEXT_PUBLIC_URL}/api/upload/new`, {
+ method: "POST",
+ body: formData,
+ });
+ };
+
const stopRecording = () => {
setStoppingRecording(true);
- if (mediaRecorder && mediaRecorder.state === "recording") {
- mediaRecorder.stop();
- setIsRecording(false);
- setStoppingRecording(false);
+ if (videoRecorder) {
+ videoRecorder.stop();
+ }
+
+ setIsRecording(false);
+ setStoppingRecording(false);
+ };
+
+ const handleRndDragStop = (
+ e: any,
+ d: any,
+ previewType: "webcam" | "screen"
+ ) => {
+ const videoContainer = document.querySelector(".video-container");
+ const preview = document.getElementById(
+ previewType === "webcam" ? "webcamPreview" : "screenPreview"
+ );
+
+ if (videoContainer && preview) {
+ const containerRect = videoContainer.getBoundingClientRect();
+ const previewRect = preview.getBoundingClientRect();
+
+ const containerCenterX = containerRect.left + containerRect.width / 2;
+ const containerCenterY = containerRect.top + containerRect.height / 2;
+
+ const previewCenterX = previewRect.left + previewRect.width / 2;
+ const previewCenterY = previewRect.top + previewRect.height / 2;
+
+ const thresholdX = 15;
+ const thresholdY = 15;
+
+ const videoContainerWidth = videoContainer.clientWidth;
+ const videoContainerHeight = videoContainer.clientHeight;
+
+ if (Math.abs(previewCenterX - containerCenterX) <= thresholdX) {
+ if (previewType === "webcam") {
+ setWebcamStyleSettings((prevSettings) => ({
+ ...prevSettings,
+ x: (videoContainerWidth - prevSettings.width) / 2,
+ }));
+ } else if (previewType === "screen") {
+ setScreenStyleSettings((prevSettings) => ({
+ ...prevSettings,
+ x: (videoContainerWidth - prevSettings.width) / 2,
+ }));
+ }
+ } else {
+ if (previewType === "webcam") {
+ setWebcamStyleSettings((prevSettings) => ({
+ ...prevSettings,
+ x: d.x,
+ }));
+ } else if (previewType === "screen") {
+ setScreenStyleSettings((prevSettings) => ({
+ ...prevSettings,
+ x: d.x,
+ }));
+ }
+ }
+
+ if (Math.abs(previewCenterY - containerCenterY) <= thresholdY) {
+ if (previewType === "webcam") {
+ setWebcamStyleSettings((prevSettings) => ({
+ ...prevSettings,
+ y: (videoContainerHeight - prevSettings.height) / 2,
+ }));
+ } else if (previewType === "screen") {
+ setScreenStyleSettings((prevSettings) => ({
+ ...prevSettings,
+ y: (videoContainerHeight - prevSettings.height) / 2,
+ }));
+ }
+
+ setIsCenteredVertically(true);
+ } else {
+ if (previewType === "webcam") {
+ setWebcamStyleSettings((prevSettings) => ({
+ ...prevSettings,
+ y: d.y,
+ }));
+ } else if (previewType === "screen") {
+ setScreenStyleSettings((prevSettings) => ({
+ ...prevSettings,
+ y: d.y,
+ }));
+ }
+
+ setIsCenteredVertically(false);
+ }
+ }
+ };
+
+ const handleRndDrag = (e: any, d: any, previewType: "webcam" | "screen") => {
+ const videoContainer = document.querySelector(".video-container");
+ const preview = document.getElementById(
+ previewType === "webcam" ? "webcamPreview" : "screenPreview"
+ );
+
+ if (videoContainer && preview) {
+ const containerRect = videoContainer.getBoundingClientRect();
+ const previewRect = preview.getBoundingClientRect();
+
+ const containerCenterX = containerRect.left + containerRect.width / 2;
+ const containerCenterY = containerRect.top + containerRect.height / 2;
+
+ const previewCenterX = previewRect.left + previewRect.width / 2;
+ const previewCenterY = previewRect.top + previewRect.height / 2;
+
+ const thresholdX = 15;
+ const thresholdY = 15;
+
+ if (Math.abs(previewCenterY - containerCenterY) <= thresholdY) {
+ setIsCenteredVertically(true);
+ } else {
+ setIsCenteredVertically(false);
+ }
+
+ if (Math.abs(previewCenterX - containerCenterX) <= thresholdX) {
+ setIsCenteredHorizontally(true);
+ } else {
+ setIsCenteredHorizontally(false);
+ }
}
};
@@ -250,21 +708,6 @@ export const Record = ({
getDevices();
}, []);
- useEffect(() => {
- if (recordedBlobs.length > 0) {
- const recordedVideo = new Blob(recordedBlobs, { type: "video/webm" });
- const videoUrl = URL.createObjectURL(recordedVideo);
- const link = document.createElement("a");
- link.href = videoUrl;
- link.download = "recorded_video.webm";
- document.body.appendChild(link);
- link.click();
- document.body.removeChild(link);
- URL.revokeObjectURL(videoUrl);
- setRecordedBlobs([]);
- }
- }, [recordedBlobs]);
-
useEffect(() => {
const storedAudioDevice = localStorage.getItem("selectedAudioDevice");
const storedVideoDevice = localStorage.getItem("selectedVideoDevice");
@@ -275,7 +718,7 @@ export const Record = ({
}
if (storedVideoDevice) {
setSelectedVideoDevice(storedVideoDevice);
- startVideoCapture(storedVideoDevice);
+ startVideoCapture(storedVideoDevice, "large");
}
if (storedScreenStream === "true") {
startScreenCapture();
@@ -372,26 +815,184 @@ export const Record = ({
if (selectedVideoDeviceObj) {
setSelectedVideoDeviceLabel(selectedVideoDeviceObj.label);
}
- startVideoCapture(storedVideoDevice);
+ startVideoCapture(
+ storedVideoDevice,
+ screenStream === null ? "large" : "small"
+ );
}
if (storedScreenStream === "true") {
startScreenCapture();
}
}, [audioDevices, videoDevices]);
+ if (isLoading) {
+ return (
+ <div className="w-full h-screen flex items-center justify-center">
+ <LogoSpinner className="w-10 h-auto animate-spin" />
+ </div>
+ );
+ }
+
+ const screenHeight = window.innerHeight;
+ const topBar = document.querySelector(".top-bar");
+ const bottomBar = document.querySelector(".bottom-bar");
+ const topBarHeight = topBar ? topBar.clientHeight : 0;
+ const bottomBarHeight = bottomBar ? bottomBar.clientHeight : 0;
+ const screenWidth = window.innerWidth;
+ const maxWidth =
+ document.querySelector(".wrapper")?.clientWidth || screenWidth;
+ const calculatedHeight = maxWidth / aspectRatio;
+ const availableHeight = Math.min(
+ calculatedHeight,
+ (screenHeight - topBarHeight - bottomBarHeight) * 0.8
+ );
+
return (
- <div className="w-full h-screen bg-white flex flex-row-reverse">
- <div className="min-w-[500px] h-full flex items-center justify-center">
- <div className="w-full max-w-[290px] px-4 py-14 border-2 rounded-[15px] flex flex-col items-center justify-center bg-gradient-to-b from-white to-gray-200">
- <div className="flex items-center justify-between mb-4">
- <div>
- <Logo showVersion className="w-24 h-auto" />
+ <div className="w-full h-full min-h-screen h mx-auto flex items-center justify-center">
+ <div className={`max-w-[1280px] wrapper p-8 space-y-6`}>
+ <div className="top-bar flex justify-between">
+ <a href="/" className="flex items-center">
+ <ArrowLeft className="w-6 h-6 text-gray-600" />
+ </a>
+ <Button
+ {...(isRecording && { variant: "destructive" })}
+ onClick={() => {
+ if (isRecording) {
+ stopRecording();
+ } else {
+ startRecording();
+ }
+ }}
+ spinner={startingRecording || stoppingRecording}
+ >
+ {startingRecording
+ ? "Starting..."
+ : isRecording
+ ? stoppingRecording
+ ? currentStoppingMessage
+ : `Stop - ${recordingTime}`
+ : "Start Recording"}
+ </Button>
+ </div>
+ <div className="h-full flex-grow">
+ <div className="w-full h-full top-0 left-0 h-full flex flex-col items-center justify-center">
+ <div
+ style={{
+ aspectRatio: aspectRatio,
+ height: availableHeight,
+ maxWidth: "100%",
+ }}
+ className={`video-container bg-black relative w-auto mx-auto border-2 border-gray-200 rounded-xl overflow-hidden shadow-xl`}
+ >
+ {isCenteredHorizontally && (
+ <div
+ className="crosshair absolute top-0 left-1/2 transform -translate-x-1/2 w-0.5 h-full bg-red-500"
+ style={{ zIndex: 999 }}
+ ></div>
+ )}
+ {isCenteredVertically && (
+ <div
+ className="crosshair absolute top-1/2 left-0 transform -translate-y-1/2 w-full h-0.5 bg-red-500"
+ style={{ zIndex: 999 }}
+ ></div>
+ )}
+ {screenStream && (
+ <Rnd
+ position={{
+ x: screenStyleSettings.x,
+ y: screenStyleSettings.y,
+ }}
+ size={{
+ width: screenStyleSettings.width,
+ height: screenStyleSettings.height,
+ }}
+ bounds="parent"
+ className="absolute rnd group"
+ resizeHandleStyles={defaultRndHandeStyles}
+ resizeHandleClasses={{
+ bottomRight: "resize-handle",
+ bottomLeft: "resize-handle",
+ bottom: "resize-handle",
+ right: "resize-handle",
+ left: "resize-handle",
+ top: "resize-handle",
+ topLeft: "resize-handle",
+ topRight: "resize-handle",
+ }}
+ onDrag={(e, d) => handleRndDrag(e, d, "screen")}
+ onDragStop={(e, d) => handleRndDragStop(e, d, "screen")}
+ onResizeStop={(e, direction, ref, delta, position) => {
+ setScreenStyleSettings({
+ ...screenStyleSettings,
+ width: ref.offsetWidth,
+ height: ref.offsetHeight,
+ });
+ }}
+ >
+ <div className="w-full h-full group-hover:outline outline-2 outline-primary rounded-xl">
+ <video
+ id="screenPreview"
+ ref={screenPreviewRef}
+ autoPlay
+ muted
+ className="w-full h-full"
+ />
+ </div>
+ </Rnd>
+ )}
+ {videoStream && (
+ <Rnd
+ position={{
+ x: webcamStyleSettings.x,
+ y: webcamStyleSettings.y,
+ }}
+ size={{
+ width: webcamStyleSettings.width,
+ height: webcamStyleSettings.height,
+ }}
+ default={webcamStyleSettings}
+ bounds="parent"
+ className="absolute webcam-rnd rnd group"
+ lockAspectRatio={true}
+ resizeHandleStyles={defaultRndHandeStyles}
+ resizeHandleClasses={{
+ bottomRight: "resize-handle",
+ bottomLeft: "resize-handle",
+ bottom: "resize-handle",
+ right: "resize-handle",
+ left: "resize-handle",
+ top: "resize-handle",
+ topLeft: "resize-handle",
+ topRight: "resize-handle",
+ }}
+ onDrag={(e, d) => handleRndDrag(e, d, "webcam")}
+ onDragStop={(e, d) => handleRndDragStop(e, d, "webcam")}
+ onResizeStop={(e, direction, ref, delta, position) => {
+ setWebcamStyleSettings({
+ ...webcamStyleSettings,
+ width: ref.offsetWidth,
+ height: ref.offsetHeight,
+ });
+ }}
+ >
+ <div className="w-full h-full rounded-xl overflow-hidden group-hover:outline outline-2 outline-primary">
+ <video
+ id="webcamPreview"
+ ref={webcamPreviewRef}
+ autoPlay
+ muted
+ className="w-full h-full object-cover"
+ />
+ </div>
+ </Rnd>
+ )}
</div>
</div>
- <div className="space-y-4 mb-4 w-full">
- <div>
- <label className="text-sm font-medium">Display</label>
- <div className="flex items-center space-x-1">
+ </div>
+ <div>
+ <div className="bottom-bar space-y-4 mb-4 w-full">
+ <div className="space-x-3 flex items-center">
+ <div className="w-full">
<ActionButton
handler={() => {
screenStream ? stopScreenCapture() : startScreenCapture();
@@ -401,128 +1002,59 @@ export const Record = ({
active={true}
/>
</div>
- </div>
- <div>
- <label className="text-sm font-medium">Webcam / Video</label>
- <div className="space-y-2">
- <DropdownMenu>
- <DropdownMenuTrigger className="w-full">
- <ActionButton
- width="full"
- icon={<Video className="w-5 h-5" />}
- label={selectedVideoDeviceLabel}
- active={true}
- recordingOption={true}
- optionName="Video"
- />
- </DropdownMenuTrigger>
- <DropdownMenuContent className="w-56">
- {videoDevices.map((device) => (
- <DropdownMenuItem
- key={device.deviceId}
- onSelect={() => {
- setSelectedVideoDevice(device.deviceId);
- setSelectedVideoDeviceLabel(device.label);
- startVideoCapture(device.deviceId);
- }}
- >
- {device.label}
- </DropdownMenuItem>
- ))}
- </DropdownMenuContent>
- </DropdownMenu>
- <DropdownMenu>
- <DropdownMenuTrigger className="w-full">
- <ActionButton
- width="full"
- icon={<Mic className="w-5 h-5" />}
- label={selectedAudioDeviceLabel}
- active={true}
- recordingOption={true}
- optionName="Audio"
- />
- </DropdownMenuTrigger>
- <DropdownMenuContent className="w-56">
- {audioDevices.map((device) => (
- <DropdownMenuItem
- key={device.deviceId}
- onSelect={() => {
- setSelectedAudioDevice(device.deviceId);
- setSelectedAudioDeviceLabel(device.label);
- startVideoCapture(device.deviceId);
- }}
- >
- {device.label}
- </DropdownMenuItem>
- ))}
- </DropdownMenuContent>
- </DropdownMenu>
- </div>
- </div>
- </div>
- <div className="group flex flex-col items-center justify-center w-full">
- <Button
- {...(isRecording && { variant: "destructive" })}
- className="w-full flex mx-auto"
- onClick={() => {
- if (isRecording) {
- stopRecording();
- } else {
- startRecording();
- }
- }}
- spinner={startingRecording || stoppingRecording}
- >
- {startingRecording
- ? "Starting..."
- : isRecording
- ? stoppingRecording
- ? currentStoppingMessage
- : `Stop - ${recordingTime}`
- : "Start Recording"}
- </Button>
- </div>
- </div>
- </div>
-
- <div className="h-full flex-grow">
- <div className="w-full h-full top-0 left-0 h-full flex flex-col items-center justify-center p-8">
- <div className="w-full text-left mb-4">
- <span className="bg-white shadow-lg py-2 px-4 rounded-xl font-medium text-lg border-2">
- Recording preview
- </span>
- </div>
- <div className="bg-black relative w-full aspect-w-16 aspect-h-9 mx-auto border-2 border-gray-200 rounded-xl overflow-hidden shadow-xl">
- <video
- id="screenPreview"
- ref={screenPreviewRef}
- autoPlay
- muted
- className="w-full h-full object-contain"
- />
- {videoStream && (
- <Rnd
- default={{
- x: 18,
- y: 18,
- width: 160,
- height: 160,
- }}
- bounds="parent"
- className="absolute"
- lockAspectRatio={true}
- >
- <div className="w-full h-full rounded-full overflow-hidden">
- <video
- id="webcamPreview"
- ref={webcamPreviewRef}
- autoPlay
- muted
- className="w-full h-full object-cover rounded-full"
+ <DropdownMenu>
+ <DropdownMenuTrigger className="w-full">
+ <ActionButton
+ width="full"
+ icon={<Video className="w-5 h-5" />}
+ label={selectedVideoDeviceLabel}
+ active={true}
+ recordingOption={true}
+ optionName="Video"
/>
- </div>
- </Rnd>
- )}
+ </DropdownMenuTrigger>
+ <DropdownMenuContent className="w-56">
+ {videoDevices.map((device) => (
+ <DropdownMenuItem
+ key={device.deviceId}
+ onSelect={() => {
+ setSelectedVideoDevice(device.deviceId);
+ setSelectedVideoDeviceLabel(device.label);
+ startVideoCapture(device.deviceId);
+ }}
+ >
+ {device.label}
+ </DropdownMenuItem>
+ ))}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ <DropdownMenu>
+ <DropdownMenuTrigger className="w-full">
+ <ActionButton
+ width="full"
+ icon={<Mic className="w-5 h-5" />}
+ label={selectedAudioDeviceLabel}
+ active={true}
+ recordingOption={true}
+ optionName="Audio"
+ />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent className="w-56">
+ {audioDevices.map((device) => (
+ <DropdownMenuItem
+ key={device.deviceId}
+ onSelect={() => {
+ setSelectedAudioDevice(device.deviceId);
+ setSelectedAudioDeviceLabel(device.label);
+ startVideoCapture(device.deviceId);
+ }}
+ >
+ {device.label}
+ </DropdownMenuItem>
+ ))}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
</div>
</div>
</div>
diff --git a/apps/web/components/BentoScript.tsx b/apps/web/components/BentoScript.tsx
new file mode 100644
index 000000000..c2653f02c
--- /dev/null
+++ b/apps/web/components/BentoScript.tsx
@@ -0,0 +1,48 @@
+"use client";
+
+import { useEffect } from "react";
+import Script from "next/script";
+import { users } from "@cap/database/schema";
+import { Router } from "next/router";
+
+declare global {
+ interface Window {
+ bento?: any;
+ }
+}
+
+export function BentoScript({
+ user,
+}: {
+ user: typeof users.$inferSelect | null;
+}) {
+ useEffect(() => {
+ const handleRouteChange = () => {
+ console.log("route change");
+ setTimeout(() => {
+ if (window.bento !== undefined) {
+ if (user) {
+ window.bento.identify(user.email);
+ }
+ window.bento.view();
+ }
+ }, 0);
+ };
+
+ Router.events.on("routeChangeComplete", handleRouteChange);
+
+ return () => {
+ Router.events.off("routeChangeComplete", handleRouteChange);
+ };
+ }, []);
+
+ return (
+ <Script
+ id="bento-script"
+ src={
+ "https://fast.bentonow.com?site_uuid=7d5c45ace4c02e5587c4449b1f0efb5c"
+ }
+ strategy="afterInteractive"
+ />
+ );
+}
diff --git a/apps/web/components/Navbar.tsx b/apps/web/components/Navbar.tsx
index 53c6f937e..3d765fd5d 100644
--- a/apps/web/components/Navbar.tsx
+++ b/apps/web/components/Navbar.tsx
@@ -15,7 +15,6 @@ import {
import Link from "next/link";
import { useState } from "react";
import { Menu, X } from "lucide-react";
-import { classNames } from "../../../packages/utils/src/helpers";
export const Navbar = ({ auth }: { auth: boolean }) => {
const pathname = usePathname();
@@ -99,7 +98,7 @@ export const Navbar = ({ auth }: { auth: boolean }) => {
<NavigationMenuTrigger>Help</NavigationMenuTrigger>
<NavigationMenuContent>
<ul className="grid gap-3 p-6 md:w-[400px] lg:w-[500px] lg:grid-cols-[.75fr_1fr]">
- <ListItem href="/faqs" title="FAQs">
+ <ListItem href="/faq" title="FAQs">
Frequently asked questions about Cap.
</ListItem>
<ListItem href="mailto:[email protected]" title="Email support">
@@ -134,9 +133,9 @@ export const Navbar = ({ auth }: { auth: boolean }) => {
{showMobileMenu && (
<div className="fixed top-0 left-0 w-full h-full px-5 bg-white z-[100000] overflow-auto">
<div className="bg-gradient-to-b from-white to-[rgba(255,255,255,0.3)] pt-5 pb-12 sticky top-0 flex items-center justify-between">
- <a href="/">
+ <Link href="/">
<Logo className="w-20 sm:w-24 h-auto" />
- </a>
+ </Link>
<button onClick={() => setShowMobileMenu(!showMobileMenu)}>
<X className="w-[28px] h-[28px]" />
</button>
diff --git a/apps/web/package.json b/apps/web/package.json
index f825fdc5f..43b3751d6 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -3,7 +3,7 @@
"version": "0.2.1",
"private": true,
"scripts": {
- "dev": "next dev --turbo",
+ "dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
diff --git a/apps/web/utils/video/upload/helpers.ts b/apps/web/utils/video/upload/helpers.ts
index aa7ea27e4..0fcfc3764 100644
--- a/apps/web/utils/video/upload/helpers.ts
+++ b/apps/web/utils/video/upload/helpers.ts
@@ -1,10 +1,24 @@
-export async function uploadToS3(
- filename: string,
- blobData: string | Blob,
- userId: string,
- awsBucket: string,
- awsRegion: string
-) {
+export async function uploadToS3({
+ filename,
+ blobData,
+ userId,
+ duration,
+ resolution,
+ videoCodec,
+ audioCodec,
+ awsBucket,
+ awsRegion,
+}: {
+ filename: string;
+ blobData: Blob;
+ userId: string;
+ duration?: string;
+ resolution?: string;
+ videoCodec?: string;
+ audioCodec?: string;
+ awsBucket: string;
+ awsRegion: string;
+}) {
const response = await fetch(
`${process.env.NEXT_PUBLIC_URL}/api/upload/signed`,
{
@@ -15,6 +29,10 @@ export async function uploadToS3(
body: JSON.stringify({
userId: userId,
fileKey: filename,
+ duration: duration,
+ resolution: resolution,
+ videoCodec: videoCodec,
+ audioCodec: audioCodec,
awsBucket: awsBucket,
awsRegion: awsRegion,
}),
@@ -27,7 +45,6 @@ export async function uploadToS3(
Object.entries(presignedPostData.fields).forEach(([key, value]) => {
formData.append(key, value as string);
});
- // Append the file (blobData) to the formData
formData.append("file", blobData);
// Execute the upload using the presigned URL
@@ -40,6 +57,5 @@ export async function uploadToS3(
return false;
}
- // Optionally return the S3 URL or any other info you need
return true;
}