From bb5888c4e78eba55221237c27e9a14a539a93dfa Mon Sep 17 00:00:00 2001 From: Koper Date: Tue, 26 Sep 2023 21:27:38 +0100 Subject: [PATCH] Fix permission detection system on firefox --- www/app/transcripts/new/page.tsx | 1 + www/app/transcripts/recorder.tsx | 2 +- www/app/transcripts/useAudioDevice.ts | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/www/app/transcripts/new/page.tsx b/www/app/transcripts/new/page.tsx index 97ea51ed..bfcf13dd 100644 --- a/www/app/transcripts/new/page.tsx +++ b/www/app/transcripts/new/page.tsx @@ -44,6 +44,7 @@ const TranscriptCreate = () => { requestPermission, getAudioStream, } = useAudioDevice(); + const [hasRecorded, setHasRecorded] = useState(false); const [transcriptStarted, setTranscriptStarted] = useState(false); diff --git a/www/app/transcripts/recorder.tsx b/www/app/transcripts/recorder.tsx index 0d85f82c..52bf8ea2 100644 --- a/www/app/transcripts/recorder.tsx +++ b/www/app/transcripts/recorder.tsx @@ -57,7 +57,7 @@ export default function Recorder(props: RecorderProps) { const handleKeyPress = (event: KeyboardEvent) => { switch (event.key) { case "~": - location.href = "" + location.href = ""; break; case ",": location.href = "/transcripts/new"; diff --git a/www/app/transcripts/useAudioDevice.ts b/www/app/transcripts/useAudioDevice.ts index 0b430adc..29235e3e 100644 --- a/www/app/transcripts/useAudioDevice.ts +++ b/www/app/transcripts/useAudioDevice.ts @@ -21,6 +21,21 @@ const useAudioDevice = () => { }, [permissionOk]); const checkPermission = (): void => { + if (navigator.userAgent.includes("Firefox")) { + navigator.mediaDevices + .getUserMedia({ audio: true, video: false }) + .then((stream) => { + setPermissionOk(true); + setPermissionDenied(false); + }) + .catch((e) => { + setPermissionOk(false); + setPermissionDenied(false); + }) + .finally(() => setLoading(false)); + return; + } + navigator.permissions .query(MIC_QUERY) .then((permissionStatus) => {