Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(web-recorder): use device availability for media permission affordance

Richie McIlroyb76e27a6b481
diff --git a/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/CameraSelector.tsx b/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/CameraSelector.tsx
index 1ae4d3dc9..3a408aec7 100644
--- a/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/CameraSelector.tsx
+++ b/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/CameraSelector.tsx
@@ -36,14 +36,16 @@ export const CameraSelector = ({
onRefreshDevices,
}: CameraSelectorProps) => {
const cameraEnabled = selectedCameraId !== null;
- const { state: permissionState, requestPermission } = useMediaPermission(
- "camera",
- dialogOpen,
- );
+ const { requestPermission } = useMediaPermission("camera", dialogOpen);
- const permissionSupported = permissionState !== "unsupported";
- const shouldRequestPermission =
- permissionSupported && permissionState !== "granted";
+ // Device availability is the reliable cross-browser signal for camera
+ // access: a deviceId is only exposed once permission is actually active.
+ // permissions.query state is not dependable here — Safari and Firefox < 118
+ // can't report it, and Firefox can report "granted" after a restart while
+ // still exposing no usable devices until access is re-requested. Driving the
+ // re-grant affordance off device availability keeps the user from getting
+ // stuck on "No Camera" with no way to recover.
+ const shouldRequestPermission = availableCameras.length === 0;
const statusPillDisabled = !shouldRequestPermission && !cameraEnabled;
diff --git a/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/MicrophoneSelector.tsx b/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/MicrophoneSelector.tsx
index 96a49611a..d93294a1c 100644
--- a/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/MicrophoneSelector.tsx
+++ b/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/MicrophoneSelector.tsx
@@ -36,14 +36,16 @@ export const MicrophoneSelector = ({
onRefreshDevices,
}: MicrophoneSelectorProps) => {
const micEnabled = selectedMicId !== null;
- const { state: permissionState, requestPermission } = useMediaPermission(
- "microphone",
- dialogOpen,
- );
-
- const permissionSupported = permissionState !== "unsupported";
- const shouldRequestPermission =
- permissionSupported && permissionState !== "granted";
+ const { requestPermission } = useMediaPermission("microphone", dialogOpen);
+
+ // Device availability is the reliable cross-browser signal for microphone
+ // access: a deviceId is only exposed once permission is actually active.
+ // permissions.query state is not dependable here — Safari and Firefox < 118
+ // can't report it, and Firefox can report "granted" after a restart while
+ // still exposing no usable devices until access is re-requested. Driving the
+ // re-grant affordance off device availability keeps the user from getting
+ // stuck on "No Microphone" with no way to recover.
+ const shouldRequestPermission = availableMics.length === 0;
const statusPillDisabled =
disabled || (!shouldRequestPermission && !micEnabled);