Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(web): add Player.js and minimal Slack embed mode
Richie McIlroy99fbd2766c4d
diff --git a/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsx b/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsxindex 45f2e1762..ce3296431 100644--- a/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsx+++ b/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsx@@ -27,6 +27,7 @@ import {parseVTT,type TranscriptEntry,} from "@/app/s/[videoId]/_components/utils/transcript-utils";+import { usePlayerJsReceiver } from "./use-player-js-receiver";declare global {interface Window {@@ -57,6 +58,7 @@ export const EmbedVideo = forwardRef<chapters?: { title: string; start: number }[];ownerName?: string | null;autoplay?: boolean;+ minimal?: boolean;viewerSettings?: ViewerSettings | null;showPlaybackStatusBadge?: boolean;}@@ -68,7 +70,8 @@ export const EmbedVideo = forwardRef<comments: _comments,chapters = [],ownerName,- autoplay: _autoplay = false,+ autoplay = false,+ minimal = false,viewerSettings,showPlaybackStatusBadge = false,},@@ -76,6 +79,7 @@ export const EmbedVideo = forwardRef<) => {const videoRef = useRef<HTMLVideoElement>(null);useImperativeHandle(ref, () => videoRef.current as HTMLVideoElement);+ usePlayerJsReceiver(videoRef);const [transcriptData, setTranscriptData] = useState<TranscriptEntry[]>([]);const [longestDuration, setLongestDuration] = useState<number>(@@ -247,6 +251,7 @@ export const EmbedVideo = forwardRef<chaptersSrc={chaptersDisabled ? "" : chaptersUrl || ""}captionsSrc={captionsDisabled ? "" : subtitleUrl || ""}videoRef={videoRef}+ autoplay={autoplay}enableCrossOrigin={enableCrossOrigin}hasActiveUpload={data.hasActiveUpload}/>@@ -260,80 +265,83 @@ export const EmbedVideo = forwardRef<chaptersSrc={chaptersDisabled ? "" : chaptersUrl || ""}captionsSrc={captionsDisabled ? "" : subtitleUrl || ""}videoRef={videoRef}+ autoplay={autoplay}hasActiveUpload={data.hasActiveUpload}isLiveSegments={isSegmentsSource}/>)}</div>- <AnimatePresence>- {!isPlaying && (- <div className="absolute top-3 left-3 z-10 space-y-2">- <motion.div- initial={{ opacity: 0, y: 10 }}- animate={{ opacity: 1, y: 0 }}- exit={{ opacity: 0, y: 10 }}- transition={{ duration: 0.3, delay: 0.2 }}- className="z-10 bg-black/50 backdrop-blur-md rounded-lg sm:rounded-xl px-2 py-1.5 sm:px-4 sm:py-3 border border-white/10 shadow-2xl"- >- <div className="flex gap-2 items-center sm:gap-3">- {ownerName && (- <Avatar- name={ownerName}- className="hidden flex-shrink-0 xs:flex xs:size-10"- letterClass="xs:text-base font-medium"- />- )}- <div className="flex-1 min-w-0">- <a- href={`/s/${data.id}`}- target="_blank"- rel="noopener noreferrer"- className="block"- onClick={(e) => e.stopPropagation()}- >- <h1 className="text-xs max-w-[175px] xs:max-w-[300px] sm:max-w-[400px] font-semibold md:max-w-[500px] leading-tight text-white truncate transition-all duration-200 cursor-pointer sm:text-xl md:text-2xl hover:underline">- {data.name}- </h1>- </a>- <div className="flex items-center gap-1 sm:gap-2 mt-0.5 sm:mt-1">- {ownerName && (- <p className="text-xs font-medium text-gray-300 truncate sm:text-sm">- {ownerName}- </p>- )}- {ownerName && longestDuration > 0 && (- <>- <span className="text-xs text-gray-400">•</span>- <p className="text-xs text-gray-300 sm:text-sm">- {formatTime(longestDuration)}+ {!minimal && (+ <AnimatePresence>+ {!isPlaying && (+ <div className="absolute top-3 left-3 z-10 space-y-2">+ <motion.div+ initial={{ opacity: 0, y: 10 }}+ animate={{ opacity: 1, y: 0 }}+ exit={{ opacity: 0, y: 10 }}+ transition={{ duration: 0.3, delay: 0.2 }}+ className="z-10 bg-black/50 backdrop-blur-md rounded-lg sm:rounded-xl px-2 py-1.5 sm:px-4 sm:py-3 border border-white/10 shadow-2xl"+ >+ <div className="flex gap-2 items-center sm:gap-3">+ {ownerName && (+ <Avatar+ name={ownerName}+ className="hidden flex-shrink-0 xs:flex xs:size-10"+ letterClass="xs:text-base font-medium"+ />+ )}+ <div className="flex-1 min-w-0">+ <a+ href={`/s/${data.id}`}+ target="_blank"+ rel="noopener noreferrer"+ className="block"+ onClick={(e) => e.stopPropagation()}+ >+ <h1 className="text-xs max-w-[175px] xs:max-w-[300px] sm:max-w-[400px] font-semibold md:max-w-[500px] leading-tight text-white truncate transition-all duration-200 cursor-pointer sm:text-xl md:text-2xl hover:underline">+ {data.name}+ </h1>+ </a>+ <div className="flex items-center gap-1 sm:gap-2 mt-0.5 sm:mt-1">+ {ownerName && (+ <p className="text-xs font-medium text-gray-300 truncate sm:text-sm">+ {ownerName}</p>- </>- )}+ )}+ {ownerName && longestDuration > 0 && (+ <>+ <span className="text-xs text-gray-400">•</span>+ <p className="text-xs text-gray-300 sm:text-sm">+ {formatTime(longestDuration)}+ </p>+ </>+ )}+ </div></div></div>- </div>- </motion.div>- <motion.button- initial={{ opacity: 0, y: 10 }}- animate={{ opacity: 1, y: 0 }}- exit={{ opacity: 0, y: 10 }}- transition={{ duration: 0.3, delay: 0.1 }}- onClick={(e) => {- e.stopPropagation();- window.open("https://cap.so", "_blank");- }}- className="hidden z-10 gap-2 items-center px-3 py-2 text-sm rounded-full border backdrop-blur-sm transition-colors duration-200 sm:flex border-white/10 w-fit text-white/80 hover:text-white bg-black/50"- aria-label="Powered by Cap"- >- <span className="text-xs md:text-sm text-white/80">- Powered by- </span>- <Logo className="w-auto h-4" white={true} />- </motion.button>- </div>- )}- </AnimatePresence>+ </motion.div>+ <motion.button+ initial={{ opacity: 0, y: 10 }}+ animate={{ opacity: 1, y: 0 }}+ exit={{ opacity: 0, y: 10 }}+ transition={{ duration: 0.3, delay: 0.1 }}+ onClick={(e) => {+ e.stopPropagation();+ window.open("https://cap.so", "_blank");+ }}+ className="hidden z-10 gap-2 items-center px-3 py-2 text-sm rounded-full border backdrop-blur-sm transition-colors duration-200 sm:flex border-white/10 w-fit text-white/80 hover:text-white bg-black/50"+ aria-label="Powered by Cap"+ >+ <span className="text-xs md:text-sm text-white/80">+ Powered by+ </span>+ <Logo className="w-auto h-4" white={true} />+ </motion.button>+ </div>+ )}+ </AnimatePresence>+ )}</>);},diff --git a/apps/web/app/embed/[videoId]/page.tsx b/apps/web/app/embed/[videoId]/page.tsxindex 1aee3c782..e6bb947e8 100644--- a/apps/web/app/embed/[videoId]/page.tsx+++ b/apps/web/app/embed/[videoId]/page.tsx@@ -25,6 +25,7 @@ import type { Metadata } from "next";import Link from "next/link";import { notFound } from "next/navigation";import * as EffectRuntime from "@/lib/server";+import { buildShareVideoMetadata } from "@/lib/share-video-metadata";import { transcribeVideo } from "@/lib/transcribe";import { isAiGenerationEnabled } from "@/utils/flags";import { EmbedVideo } from "./_components/EmbedVideo";@@ -41,54 +42,12 @@ export async function generateMetadata(Option.match({onNone: () => notFound(),onSome: ([video]) => ({- title: `${video.name} | Cap Recording`,- description: "Watch this video on Cap",- openGraph: {- images: [- {- url: new URL(- `/api/video/og?videoId=${videoId}`,- buildEnv.NEXT_PUBLIC_WEB_URL,- ).toString(),- width: 1200,- height: 630,- },- ],- videos: [- {- url: new URL(- `/api/playlist?userId=${video.ownerId}&videoId=${video.id}`,- buildEnv.NEXT_PUBLIC_WEB_URL,- ).toString(),- width: 1280,- height: 720,- type: "video/mp4",- },- ],- },- twitter: {- card: "player",- title: `${video.name} | Cap Recording`,- description: "Watch this video on Cap",- images: [- new URL(- `/api/video/og?videoId=${videoId}`,- buildEnv.NEXT_PUBLIC_WEB_URL,- ).toString(),- ],- players: {- playerUrl: new URL(- `/embed/${videoId}`,- buildEnv.NEXT_PUBLIC_WEB_URL,- ).toString(),- streamUrl: new URL(- `/api/playlist?userId=${video.ownerId}&videoId=${video.id}`,- buildEnv.NEXT_PUBLIC_WEB_URL,- ).toString(),- width: 1280,- height: 720,- },- },+ ...buildShareVideoMetadata({+ videoId,+ name: video.name,+ sourceType: video.source.type,+ webUrl: buildEnv.NEXT_PUBLIC_WEB_URL,+ }),robots: "index, follow",}),}),@@ -132,6 +91,7 @@ export default async function EmbedVideoPage(const searchParams = await props.searchParams;const videoId = params.videoId as Video.VideoId;const autoplay = searchParams.autoplay === "true";+ const minimal = searchParams.slack === "true";return Effect.gen(function* () {const videosPolicy = yield* VideosPolicy;@@ -193,10 +153,21 @@ export default async function EmbedVideoPage(Effect.succeed({ needsPassword: true } as const),),Effect.map((data) => (- <div key={videoId} className="min-h-screen bg-black">+ <div+ key={videoId}+ className={+ minimal+ ? "h-screen overflow-hidden bg-black"+ : "min-h-screen bg-black"+ }+ ><PasswordOverlay isOpen={data.needsPassword} videoId={videoId} />{!data.needsPassword && (- <EmbedContent video={data.video} autoplay={autoplay} />+ <EmbedContent+ video={data.video}+ autoplay={autoplay}+ minimal={minimal}+ />)}</div>)),@@ -212,6 +183,7 @@ export default async function EmbedVideoPage(async function EmbedContent({video,autoplay,+ minimal,}: {video: Omit<typeof videos.$inferSelect, "password"> & {sharedOrganization: { organizationId: Organisation.OrganisationId } | null;@@ -219,6 +191,7 @@ async function EmbedContent({orgSettings?: (typeof organizations.$inferSelect)["settings"] | null;};autoplay: boolean;+ minimal: boolean;}) {const user = await getCurrentUser();const sharedSpaces = await db()@@ -324,6 +297,7 @@ async function EmbedContent({}ownerName={videoOwner[0]?.name || null}autoplay={autoplay}+ minimal={minimal}viewerSettings={rules.settings}showPlaybackStatusBadge={user?.id === video.ownerId}/>