Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(web): add share player URL helper

Richie McIlroya63bbfaf5f30
diff --git a/apps/web/__tests__/unit/share-player-url.test.ts b/apps/web/__tests__/unit/share-player-url.test.ts
new file mode 100644
index 000000000..82331a506
--- /dev/null
+++ b/apps/web/__tests__/unit/share-player-url.test.ts
@@ -0,0 +1,21 @@
+import { beforeEach, describe, expect, it, vi } from "vitest";
+
+vi.mock("@cap/env", () => ({
+ buildEnv: {
+ NEXT_PUBLIC_WEB_URL: "https://cap.so",
+ },
+}));
+
+import { getSharePlayerUrl } from "@/lib/share-player-url";
+
+describe("getSharePlayerUrl", () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ });
+
+ it("advertises the dedicated embed player for shared links", () => {
+ expect(getSharePlayerUrl("mahyriybqar15xs")).toBe(
+ "https://cap.so/embed/mahyriybqar15xs",
+ );
+ });
+});
diff --git a/apps/web/app/s/[videoId]/page.tsx b/apps/web/app/s/[videoId]/page.tsx
index 91ae379c8..e4572e0f3 100644
--- a/apps/web/app/s/[videoId]/page.tsx
+++ b/apps/web/app/s/[videoId]/page.tsx
@@ -53,6 +53,7 @@ import { resolveDefaultPlaybackSpeed } from "@/lib/playback-speed";
import * as EffectRuntime from "@/lib/server";
import { runPromise } from "@/lib/server";
import { getSharePageBranding } from "@/lib/share-branding";
+import { getSharePlayerUrl } from "@/lib/share-player-url";
import {
isSocialCrawlerUserAgent,
SOCIAL_REFERRER_DOMAINS,
@@ -295,10 +296,7 @@ export async function generateMetadata(
},
],
players: {
- playerUrl: new URL(
- `/s/${videoId}`,
- buildEnv.NEXT_PUBLIC_WEB_URL,
- ).toString(),
+ playerUrl: getSharePlayerUrl(videoId),
streamUrl: playlistUrl,
width: 1280,
height: 720,
diff --git a/apps/web/lib/share-player-url.ts b/apps/web/lib/share-player-url.ts
new file mode 100644
index 000000000..0a7b363ad
--- /dev/null
+++ b/apps/web/lib/share-player-url.ts
@@ -0,0 +1,4 @@
+import { buildEnv } from "@cap/env";
+
+export const getSharePlayerUrl = (videoId: string) =>
+ new URL(`/embed/${videoId}`, buildEnv.NEXT_PUBLIC_WEB_URL).toString();