Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(web): add ScreenRecorderPanel replacing floating bar
Richie McIlroy8642356c217a
diff --git a/apps/web/app/s/[videoId]/_components/timeline/recording/ScreenRecorderFloatingBar.tsx b/apps/web/app/s/[videoId]/_components/timeline/recording/ScreenRecorderFloatingBar.tsxdeleted file mode 100644index e45eb1dab..000000000--- a/apps/web/app/s/[videoId]/_components/timeline/recording/ScreenRecorderFloatingBar.tsx+++ /dev/null@@ -1,137 +0,0 @@-"use client";--import { AnimatePresence, motion } from "motion/react";-import { useEffect, useState } from "react";-import { formatClock } from "../timeline-format";-import {- type CommentRecording,- useCommentRecorder,-} from "./useCommentRecorder";--/**- * Screen replies show the browser's picker immediately, then collapse to a- * small fixed bar so the author can switch tabs while recording. The browser's- * own "Stop sharing" also ends the recording.- */-export function ScreenRecorderFloatingBar({- timestamp,- onFinish,- onCancel,-}: {- timestamp: number;- onFinish: (recording: CommentRecording) => void;- onCancel: () => void;-}) {- const [started, setStarted] = useState(false);- const {- phase,- durationMs,- micMuted,- error,- startScreen,- toggleMic,- stop,- cancel,- } = useCommentRecorder({ onFinish, onPickerCancelled: onCancel });-- useEffect(() => {- if (!started) {- setStarted(true);- void startScreen();- }- }, [startScreen, started]);-- useEffect(() => {- if (error) {- const timer = setTimeout(onCancel, 2500);- return () => clearTimeout(timer);- }- }, [error, onCancel]);-- const handleCancel = () => {- cancel();- onCancel();- };-- return (- <AnimatePresence>- {(phase === "recording" || error) && (- <motion.div- key="screen-bar"- initial={{ opacity: 0, y: 16 }}- animate={{ opacity: 1, y: 0 }}- exit={{ opacity: 0, y: 12 }}- transition={{ type: "spring", stiffness: 420, damping: 34 }}- className="fixed bottom-6 left-1/2 z-[60] -translate-x-1/2"- >- <div className="flex items-center gap-3 rounded-full border border-gray-5 bg-white py-2 pr-2 pl-4 shadow-[0_8px_24px_rgba(18,22,31,0.12)]">- {error ? (- <span className="text-xs text-gray-11">{error}</span>- ) : (- <>- <span className="flex items-center gap-2">- <span className="relative flex size-2.5">- <span className="absolute inline-flex size-full animate-ping rounded-full bg-red-500 opacity-60" />- <span className="relative inline-flex size-2.5 rounded-full bg-red-500" />- </span>- <span className="font-mono text-xs tabular-nums text-gray-12">- {formatClock(durationMs / 1000)}- </span>- </span>- <span className="text-[11px] text-gray-9">- Recording reply at {formatClock(timestamp)}- </span>- <button- type="button"- onClick={toggleMic}- aria-label={- micMuted ? "Unmute microphone" : "Mute microphone"- }- aria-pressed={micMuted}- className={`flex size-8 items-center justify-center rounded-full ring-1 ring-gray-4 transition-colors ${- micMuted- ? "bg-gray-3 text-gray-9"- : "bg-gray-2 text-gray-12"- }`}- >- <svg- viewBox="0 0 16 16"- className="size-3.5"- fill="currentColor"- aria-hidden="true"- >- <path d="M8 1.5A2.25 2.25 0 0 0 5.75 3.75v3.5a2.25 2.25 0 0 0 4.5 0v-3.5A2.25 2.25 0 0 0 8 1.5Z" />- <path d="M3.75 6.75a.65.65 0 0 1 1.3 0v.5a2.95 2.95 0 0 0 5.9 0v-.5a.65.65 0 0 1 1.3 0v.5a4.25 4.25 0 0 1-3.6 4.2v1.55h1.6a.65.65 0 0 1 0 1.3h-4.5a.65.65 0 0 1 0-1.3h1.6v-1.55a4.25 4.25 0 0 1-3.6-4.2v-.5Z" />- {micMuted && (- <path- d="M2 2l12 12"- stroke="currentColor"- strokeWidth="1.4"- strokeLinecap="round"- />- )}- </svg>- </button>- <button- type="button"- onClick={handleCancel}- className="h-8 rounded-full px-3 text-xs text-gray-10 transition-colors hover:bg-gray-2 hover:text-gray-12"- >- Discard- </button>- <button- type="button"- onClick={stop}- className="flex h-8 items-center gap-1.5 rounded-full bg-gray-12 px-3.5 text-xs font-medium text-white transition-opacity hover:opacity-90"- >- <span className="inline-flex size-2 rounded-sm bg-red-400" />- Stop- </button>- </>- )}- </div>- </motion.div>- )}- </AnimatePresence>- );-}diff --git a/apps/web/app/s/[videoId]/_components/timeline/recording/ScreenRecorderPanel.tsx b/apps/web/app/s/[videoId]/_components/timeline/recording/ScreenRecorderPanel.tsxnew file mode 100644index 000000000..d1974fbda--- /dev/null+++ b/apps/web/app/s/[videoId]/_components/timeline/recording/ScreenRecorderPanel.tsx@@ -0,0 +1,200 @@+"use client";++import { formatClock } from "../timeline-format";+import { DevicePill } from "./DevicePill";+import { MicMuteButton } from "./MicMuteButton";+import { PauseResumeButton } from "./PauseResumeButton";+import { useCommentMediaDevices } from "./useCommentMediaDevices";+import {+ type CommentRecording,+ useCommentRecorder,+} from "./useCommentRecorder";++/**+ * The whole screen-reply flow in ONE card, same anatomy as the camera panel:+ * a setup stage (mic choice, what happens next), then the same card morphs+ * into the recording stage (timer, live mic switch, pause, stop) in place.+ * No separate floating bar — the card is the surface for the entire take.+ *+ * The share picker launches from the Next click itself, so there is no+ * auto-start effect and nothing for StrictMode to double-fire. Cancelling+ * the picker just returns to setup. One recorder instance spans both stages,+ * so the mute chosen during setup is simply the same state the recording+ * reads; the browser's own "Stop sharing" still ends the take normally.+ */+export function ScreenRecorderPanel({+ timestamp,+ onFinish,+ onCancel,+}: {+ timestamp: number;+ onFinish: (recording: CommentRecording) => void;+ onCancel: () => void;+}) {+ const devices = useCommentMediaDevices();+ const {+ phase,+ durationMs,+ micMuted,+ liveMicSwitchable,+ error,+ startScreen,+ switchMic,+ toggleMic,+ pause,+ resume,+ stop,+ cancel,+ } = useCommentRecorder({+ onFinish,+ // Picker dismissed: phase returns to idle and the setup stage is still+ // on screen — the natural "try again" spot, so no surface teardown.+ selectedCameraId: null,+ selectedMicId: devices.selectedMicId,+ onMicInUse: devices.adoptMic,+ onDevicesChanged: devices.refreshDevices,+ });++ const live = phase === "recording" || phase === "paused";+ const paused = phase === "paused";++ const handleCancel = () => {+ cancel();+ onCancel();+ };++ const handleMicSelect = (deviceId: string) => {+ devices.selectMic(deviceId);+ if (live) void switchMic(deviceId);+ };++ return (+ <div className="new-card-style flex w-80 flex-col gap-2 p-2.5">+ {live || phase === "processing" ? (+ <div className="flex items-center justify-center gap-2.5 rounded-xl bg-gray-3 px-5 py-4">+ <span className="relative flex size-2.5 shrink-0">+ {!paused && (+ <span className="absolute inline-flex size-full animate-ping rounded-full bg-red-500 opacity-60" />+ )}+ <span+ className={`relative inline-flex size-2.5 rounded-full ${+ paused ? "bg-gray-8" : "bg-red-500"+ }`}+ />+ </span>+ <span className="font-mono text-sm tabular-nums text-gray-12">+ {formatClock(durationMs / 1000)}+ </span>+ <span className="text-xs text-gray-10">+ {paused ? "Paused" : "Recording your screen"}+ </span>+ </div>+ ) : (+ <div className="flex flex-col items-center gap-2.5 rounded-xl bg-gray-3 px-5 py-5 text-center">+ <span className="grid size-9 place-items-center rounded-full bg-white text-gray-11 ring-1 ring-gray-5">+ <svg+ viewBox="0 0 16 16"+ className="size-4 fill-current"+ aria-hidden+ >+ <title>Screen</title>+ <path d="M2 4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V4Zm3.2 9.4h5.6a.6.6 0 1 1 0 1.2H5.2a.6.6 0 1 1 0-1.2Z" />+ </svg>+ </span>+ <p className="text-xs leading-relaxed text-gray-11">+ {error+ ? error+ : phase === "requesting"+ ? "Waiting for your browser's share picker…"+ : devices.mics.length > 0+ ? "Pick a microphone, then click Next. Your browser will ask which screen, window, or tab to share, and recording starts right away."+ : "Click Next and your browser will ask which screen, window, or tab to share. Recording starts right away."}+ </p>+ </div>+ )}++ {devices.mics.length > (live ? 1 : 0) && (+ <DevicePill+ kind="mic"+ devices={devices.mics}+ selectedId={devices.selectedMicId}+ onSelect={handleMicSelect}+ disabled={+ phase === "processing" ||+ (live && !liveMicSwitchable) ||+ (!live && micMuted)+ }+ title={+ live && !liveMicSwitchable+ ? "This recording has no microphone track"+ : !live && micMuted+ ? "Microphone is off for this recording"+ : undefined+ }+ className="w-full min-w-0"+ />+ )}++ <div className="flex items-center gap-1.5">+ {/* 0 = the viewer wasn't at a moment in the video; no stamp to show. */}+ {timestamp > 0 && (+ <span className="rounded-md bg-gray-2 px-1.5 py-0.5 font-mono text-[10px] tabular-nums text-gray-11 ring-1 ring-gray-4">+ {formatClock(timestamp)}+ </span>+ )}++ <MicMuteButton muted={micMuted} onToggle={toggleMic} shape="square" />++ {live && (+ <PauseResumeButton+ paused={paused}+ onToggle={paused ? resume : pause}+ shape="square"+ />+ )}++ <div className="flex-1" />++ {live || phase === "processing" ? (+ <>+ <button+ type="button"+ onClick={handleCancel}+ disabled={phase === "processing"}+ className="h-7 rounded-lg px-2.5 text-xs text-gray-10 transition-colors hover:bg-gray-2 hover:text-gray-12 disabled:opacity-40"+ >+ Discard+ </button>+ <button+ type="button"+ onClick={() => void stop()}+ disabled={phase === "processing"}+ className="flex h-7 items-center gap-1.5 rounded-lg bg-gray-12 px-3 text-xs font-medium text-white transition-opacity hover:opacity-90 disabled:opacity-40"+ >+ <span className="inline-flex size-2 rounded-sm bg-red-400" />+ Stop+ </button>+ </>+ ) : (+ <>+ <button+ type="button"+ onClick={handleCancel}+ className="h-7 rounded-lg px-2.5 text-xs text-gray-10 transition-colors hover:bg-gray-2 hover:text-gray-12"+ >+ Cancel+ </button>+ <button+ type="button"+ onClick={() => void startScreen()}+ disabled={phase === "requesting"}+ className="h-7 rounded-lg bg-blue-9 px-3 text-xs font-medium text-white transition-opacity hover:opacity-90 disabled:opacity-40"+ >+ {error ? "Try again" : "Next"}+ </button>+ </>+ )}+ </div>+ </div>+ );+}