Skip to content

Commit

Permalink
feat: Rework permissions check for cam/mic
Browse files Browse the repository at this point in the history
  • Loading branch information
richiemcilroy committed Sep 11, 2024
1 parent 3c1ca8a commit 0315f5f
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions apps/desktop/src/routes/permissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,41 @@ export default function () {
const c = check.latest;
if (c?.os === "macOS") {
const hasScreenRecording = c?.screenRecording;
let hasCamera = c?.camera;
let hasMicrophone = c?.microphone;

if (!hasCamera || !hasMicrophone) {
try {
const devices = await navigator.mediaDevices.enumerateDevices();
hasCamera = devices.some((device) => device.kind === "videoinput");
hasMicrophone = devices.some(
(device) => device.kind === "audioinput"
);
} catch (error) {
console.error("Error enumerating devices:", error);
}
}
const hasCamera = c?.camera || (await checkCameraPermission());
const hasMicrophone =
c?.microphone || (await checkMicrophonePermission());

return hasScreenRecording && hasCamera && hasMicrophone;
}
return false;
};

const checkCameraPermission = async () => {
try {
const cameraStream = await navigator.mediaDevices.getUserMedia({
video: true,
});
cameraStream.getTracks().forEach((track) => track.stop());
return true;
} catch (error) {
console.error("Error requesting camera permission:", error);
return false;
}
};

const checkMicrophonePermission = async () => {
try {
const microphoneStream = await navigator.mediaDevices.getUserMedia({
audio: true,
});
microphoneStream.getTracks().forEach((track) => track.stop());
return true;
} catch (error) {
console.error("Error requesting microphone permission:", error);
return false;
}
};

createEffect(async () => {
if (await permissionsGranted()) {
commands.openMainWindow();
Expand Down

1 comment on commit 0315f5f

@vercel
Copy link

@vercel vercel bot commented on 0315f5f Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.