Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(web): let share links start with captions off Resolve ?captions=off server-side in the share page and seed the player's caption toggle from it instead of always starting on.

ManthanNimodiyab0616a41d398
diff --git a/apps/web/app/s/[videoId]/Share.tsx b/apps/web/app/s/[videoId]/Share.tsx
index 92cf33f03..70cb174d8 100644
--- a/apps/web/app/s/[videoId]/Share.tsx
+++ b/apps/web/app/s/[videoId]/Share.tsx
@@ -206,6 +206,8 @@ interface ShareProps {
transcriptionGenerationAvailable: boolean;
/** Server-resolved `?view=` so the first paint already has the right layout. */
initialView?: ShareView;
+ /** Server-resolved `?captions=off` so the player never flashes captions on before hiding them. */
+ captionsInitiallyOff?: boolean;
canRecordMedia?: boolean;
viewerSignedIn?: boolean;
/**
@@ -333,6 +335,7 @@ export const Share = ({
aiGenerationAvailable,
transcriptionGenerationAvailable,
initialView = "classic",
+ captionsInitiallyOff = false,
canRecordMedia = false,
viewerSignedIn = false,
header,
@@ -966,6 +969,7 @@ export const Share = ({
comments={comments}
areChaptersDisabled={areChaptersDisabled}
areCaptionsDisabled={areCaptionsDisabled}
+ captionsInitiallyOff={captionsInitiallyOff}
// The deck under the video owns seeking, the clock and
// comments in timeline view; duplicating them inside the
// video reads as two players. Fullscreen hides the deck,
diff --git a/apps/web/app/s/[videoId]/_components/CapVideoPlayer.tsx b/apps/web/app/s/[videoId]/_components/CapVideoPlayer.tsx
index 90f4d4a90..cfafffdc5 100644
--- a/apps/web/app/s/[videoId]/_components/CapVideoPlayer.tsx
+++ b/apps/web/app/s/[videoId]/_components/CapVideoPlayer.tsx
@@ -100,6 +100,8 @@ interface Props {
chaptersSrc: string;
captionsSrc: string;
disableCaptions?: boolean;
+ /** Server-resolved `?captions=off`; seeds the caption toggle instead of always starting on. */
+ captionsInitiallyOff?: boolean;
videoRef: React.RefObject<HTMLVideoElement | null>;
mediaPlayerClassName?: string;
autoplay?: boolean;
@@ -149,6 +151,7 @@ export function CapVideoPlayer({
chaptersSrc,
captionsSrc,
disableCaptions,
+ captionsInitiallyOff = false,
videoRef,
mediaPlayerClassName,
autoplay = false,
@@ -180,7 +183,7 @@ export function CapVideoPlayer({
const [currentCue, setCurrentCue] = useState<string>("");
const [controlsVisible, setControlsVisible] = useState(false);
const [mainControlsVisible, setMainControlsVisible] = useState(false);
- const [toggleCaptions, setToggleCaptions] = useState(true);
+ const [toggleCaptions, setToggleCaptions] = useState(!captionsInitiallyOff);
const [showPlayButton, setShowPlayButton] = useState(false);
const [videoLoaded, setVideoLoaded] = useState(false);
const [hasPlayedOnce, setHasPlayedOnce] = useState(false);
diff --git a/apps/web/app/s/[videoId]/_components/HLSVideoPlayer.tsx b/apps/web/app/s/[videoId]/_components/HLSVideoPlayer.tsx
index 0e143a4af..d7fa6b36e 100644
--- a/apps/web/app/s/[videoId]/_components/HLSVideoPlayer.tsx
+++ b/apps/web/app/s/[videoId]/_components/HLSVideoPlayer.tsx
@@ -99,6 +99,8 @@ interface Props {
videoRef: React.RefObject<HTMLVideoElement | null>;
mediaPlayerClassName?: string;
disableCaptions?: boolean;
+ /** Server-resolved `?captions=off`; seeds the caption toggle instead of always starting on. */
+ captionsInitiallyOff?: boolean;
autoplay?: boolean;
hasActiveUpload?: boolean;
isLiveSegments?: boolean;
@@ -138,6 +140,7 @@ export function HLSVideoPlayer({
allowSegmentProbeDuringUpload = false,
onSourceComplete,
disableCaptions,
+ captionsInitiallyOff = false,
enhancedAudioUrl: _enhancedAudioUrl,
enhancedAudioStatus: _enhancedAudioStatus,
captionLanguage,
@@ -155,7 +158,7 @@ export function HLSVideoPlayer({
const hlsInstance = useRef<Hls | null>(null);
const [currentCue, setCurrentCue] = useState<string>("");
const [controlsVisible, setControlsVisible] = useState(false);
- const [toggleCaptions, setToggleCaptions] = useState(true);
+ const [toggleCaptions, setToggleCaptions] = useState(!captionsInitiallyOff);
const [showPlayButton, setShowPlayButton] = useState(false);
const [videoLoaded, setVideoLoaded] = useState(false);
const [hlsInitFailed, setHlsInitFailed] = useState(false);
diff --git a/apps/web/app/s/[videoId]/_components/ShareVideo.tsx b/apps/web/app/s/[videoId]/_components/ShareVideo.tsx
index 06eee253f..9aff60293 100644
--- a/apps/web/app/s/[videoId]/_components/ShareVideo.tsx
+++ b/apps/web/app/s/[videoId]/_components/ShareVideo.tsx
@@ -84,6 +84,8 @@ export const ShareVideo = forwardRef<
chapters?: { title: string; start: number }[];
areChaptersDisabled?: boolean;
areCaptionsDisabled?: boolean;
+ /** Server-resolved `?captions=off`; seeds the player's caption toggle. */
+ captionsInitiallyOff?: boolean;
areCommentStampsDisabled?: boolean;
areReactionStampsDisabled?: boolean;
/** Timeline view scrubs on the deck below the video, not in it. */
@@ -107,6 +109,7 @@ export const ShareVideo = forwardRef<
comments,
chapters = NO_CHAPTERS,
areCaptionsDisabled,
+ captionsInitiallyOff = false,
areChaptersDisabled,
areCommentStampsDisabled,
areReactionStampsDisabled,
@@ -553,6 +556,7 @@ export const ShareVideo = forwardRef<
defaultPlaybackSpeed={defaultPlaybackSpeed}
showPlaybackStatusBadge={showPlaybackStatusBadge}
disableCaptions={areCaptionsDisabled ?? false}
+ captionsInitiallyOff={captionsInitiallyOff}
disableCommentStamps={areCommentStampsDisabled ?? false}
disableReactionStamps={areReactionStampsDisabled ?? false}
externalTimeline={externalTimeline}
@@ -589,6 +593,7 @@ export const ShareVideo = forwardRef<
externalTimeline={externalTimeline}
controlsPortalEl={controlsPortalEl}
disableCaptions={areCaptionsDisabled ?? false}
+ captionsInitiallyOff={captionsInitiallyOff}
chaptersSrc={areChaptersDisabled ? "" : chaptersUrl || ""}
captionsSrc={areCaptionsDisabled ? "" : subtitleUrl || ""}
videoRef={videoRef}
diff --git a/apps/web/app/s/[videoId]/page.tsx b/apps/web/app/s/[videoId]/page.tsx
index 0b1d2685d..ed5442a1e 100644
--- a/apps/web/app/s/[videoId]/page.tsx
+++ b/apps/web/app/s/[videoId]/page.tsx
@@ -905,6 +905,8 @@ async function AuthorizedContent({
"timeline" && !video.isScreenshot
? ("timeline" as const)
: ("classic" as const);
+ const captionsInitiallyOff =
+ optionFromTOrFirst(searchParams.captions).pipe(Option.getOrNull) === "off";
// Recording media comments rides on the VIDEO OWNER's Pro plan; the
// upload/create paths re-check server-side via canUseMediaComments.
const canRecordMedia = Boolean(user) && videoWithOrganizationInfo.owner.isPro;
@@ -957,6 +959,7 @@ async function AuthorizedContent({
viewerId={user?.id ?? null}
viewerSignedIn={user !== null}
initialView={initialShareView}
+ captionsInitiallyOff={captionsInitiallyOff}
canRecordMedia={canRecordMedia}
isEditProcessing={isEditProcessing}
recordingStopped={recordingStopped}