Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Permission Handling Issues in Microphone and Camera Capture Dialogs #8830

Merged
19 changes: 15 additions & 4 deletions src/Components/Files/AudioCaptureDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Link } from "raviger";
import CareIcon from "../../CAREUI/icons/CareIcon";
import { useTimer } from "../../Utils/useTimer";
import { t } from "i18next";
import * as Notify from "../../Utils/Notifications";

export interface AudioCaptureDialogProps {
show: boolean;
Expand Down Expand Up @@ -35,9 +36,19 @@ export default function AudioCaptureDialog(props: AudioCaptureDialogProps) {
const timer = useTimer();

const handleStartRecording = () => {
setStatus("RECORDING");
startRecording();
timer.start();
navigator.mediaDevices
.getUserMedia({ audio: true })
.then(() => {
setStatus("RECORDING");
startRecording();
timer.start();
})
.catch(() => {
Notify.Error({
msg: "Please grant microphone permission to record audio.",
});
Copy link
Member

Choose a reason for hiding this comment

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

i18n

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

setStatus("PERMISSION_DENIED");
});
};

const handleStopRecording = () => {
Expand Down Expand Up @@ -87,7 +98,7 @@ export default function AudioCaptureDialog(props: AudioCaptureDialogProps) {
}, [show]);

useEffect(() => {
if (autoRecord && show && status === "WAITING_TO_RECORD") {
if (autoRecord && show && status === "RECORDING") {
handleStartRecording();
}
}, [autoRecord, status, show]);
Expand Down
27 changes: 24 additions & 3 deletions src/Components/Files/CameraCaptureDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import CareIcon from "../../CAREUI/icons/CareIcon";
import DialogModal from "../Common/Dialog";
import ButtonV2, { Submit } from "../Common/components/ButtonV2";
import { t } from "i18next";
import { useCallback, useRef, useState } from "react";
import { useCallback, useEffect, useRef, useState } from "react";
import useWindowDimensions from "../../Common/hooks/useWindowDimensions";
import * as Notify from "../../Utils/Notifications";

export interface CameraCaptureDialogProps {
show: boolean;
Expand All @@ -24,9 +25,29 @@ export default function CameraCaptureDialog(props: CameraCaptureDialogProps) {
height: { ideal: 2160 },
facingMode: "user",
};

useEffect(() => {
if (!show) return;
navigator.mediaDevices.getUserMedia({ video: true }).catch(() => {
Notify.Warn({
msg: t("camera_permission_denied"),
});
onHide();
});
}, [show]);
const handleSwitchCamera = useCallback(() => {
setCameraFacingFront((prevState) => !prevState);
const supportedConstraints =
navigator.mediaDevices.getSupportedConstraints();
if (
!isLaptopScreen &&
typeof supportedConstraints.facingMode === "string" &&
(supportedConstraints.facingMode as string).includes("environment")
) {
setCameraFacingFront((prevState) => !prevState);
} else {
Notify.Warn({
msg: t("switch_camera_is_not_available"),
});
}
}, []);

const { width } = useWindowDimensions();
Expand Down
1 change: 1 addition & 0 deletions src/Locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,7 @@
"summary": "Summary",
"support": "Support",
"switch": "Switch",
"switch_camera_is_not_available": "Switch camera is not available.",
"systolic": "Systolic",
"tachycardia": "Tachycardia",
"target_dosage": "Target Dosage",
Expand Down
Loading