mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
handle audio input permissions
This commit is contained in:
@@ -7,6 +7,46 @@ import "react-dropdown/style.css";
|
|||||||
|
|
||||||
import CustomRecordPlugin from "./CustomRecordPlugin";
|
import CustomRecordPlugin from "./CustomRecordPlugin";
|
||||||
|
|
||||||
|
const queryAndPromptAudio = async () => {
|
||||||
|
const permissionStatus = await navigator.permissions.query({name: 'microphone'})
|
||||||
|
if (permissionStatus.state == 'prompt') {
|
||||||
|
await navigator.mediaDevices.getUserMedia({ audio: true })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const AudioInputsDropdown = (props) => {
|
||||||
|
const [ddOptions, setDdOptions] = useState([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const init = async () => {
|
||||||
|
await queryAndPromptAudio()
|
||||||
|
|
||||||
|
const devices = await navigator.mediaDevices.enumerateDevices()
|
||||||
|
const audioDevices = devices
|
||||||
|
.filter((d) => d.kind === "audioinput" && d.deviceId != "")
|
||||||
|
.map((d) => ({ value: d.deviceId, label: d.label }))
|
||||||
|
|
||||||
|
if (audioDevices.length < 1) return console.log("no audio input devices")
|
||||||
|
|
||||||
|
setDdOptions(audioDevices)
|
||||||
|
props.setDeviceId(audioDevices[0].value)
|
||||||
|
}
|
||||||
|
init()
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const handleDropdownChange = (e) => {
|
||||||
|
props.setDeviceId(e.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dropdown
|
||||||
|
options={ddOptions}
|
||||||
|
onChange={handleDropdownChange}
|
||||||
|
value={ddOptions[0]}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export default function Recorder(props) {
|
export default function Recorder(props) {
|
||||||
const waveformRef = useRef();
|
const waveformRef = useRef();
|
||||||
const [wavesurfer, setWavesurfer] = useState(null);
|
const [wavesurfer, setWavesurfer] = useState(null);
|
||||||
@@ -14,22 +54,10 @@ export default function Recorder(props) {
|
|||||||
const [isRecording, setIsRecording] = useState(false);
|
const [isRecording, setIsRecording] = useState(false);
|
||||||
const [isPlaying, setIsPlaying] = useState(false);
|
const [isPlaying, setIsPlaying] = useState(false);
|
||||||
const [deviceId, setDeviceId] = useState(null);
|
const [deviceId, setDeviceId] = useState(null);
|
||||||
const [ddOptions, setDdOptions] = useState([]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
document.getElementById("play-btn").disabled = true;
|
document.getElementById("play-btn").disabled = true;
|
||||||
|
|
||||||
navigator.mediaDevices.enumerateDevices().then((devices) => {
|
|
||||||
const audioDevices = devices
|
|
||||||
.filter((d) => d.kind === "audioinput")
|
|
||||||
.map((d) => ({ value: d.deviceId, label: d.label }));
|
|
||||||
|
|
||||||
if (audioDevices.length < 1) return console.log("no audio input devices");
|
|
||||||
|
|
||||||
setDdOptions(audioDevices);
|
|
||||||
setDeviceId(audioDevices[0].value);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (waveformRef.current) {
|
if (waveformRef.current) {
|
||||||
const _wavesurfer = WaveSurfer.create({
|
const _wavesurfer = WaveSurfer.create({
|
||||||
container: waveformRef.current,
|
container: waveformRef.current,
|
||||||
@@ -84,22 +112,15 @@ export default function Recorder(props) {
|
|||||||
wavesurfer?.playPause();
|
wavesurfer?.playPause();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDropdownChange = (e) => {
|
|
||||||
setDeviceId(e.value);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col items-center justify-center max-w-[75vw] w-full">
|
<div className="flex flex-col items-center justify-center max-w-[75vw] w-full">
|
||||||
<div className="flex my-2 mx-auto">
|
<div className="flex my-2 mx-auto">
|
||||||
<Dropdown
|
<AudioInputsDropdown setDeviceId={setDeviceId} />
|
||||||
options={ddOptions}
|
|
||||||
onChange={handleDropdownChange}
|
|
||||||
value={ddOptions[0]}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<button
|
<button
|
||||||
onClick={handleRecClick}
|
onClick={handleRecClick}
|
||||||
data-color={isRecording ? "red" : "blue"}
|
data-color={isRecording ? "red" : "blue"}
|
||||||
|
disabled={!deviceId}
|
||||||
>
|
>
|
||||||
{isRecording ? "Stop" : "Record"}
|
{isRecording ? "Stop" : "Record"}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ const App = () => {
|
|||||||
<p className="text-gray-500">Capture The Signal, Not The Noise</p>
|
<p className="text-gray-500">Capture The Signal, Not The Noise</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Recorder setStream={setStream} onStop={() => serverData.peer.send(JSON.stringify({ cmd: 'STOP' }))}/>
|
<Recorder setStream={setStream} onStop={() => serverData?.peer?.send(JSON.stringify({ cmd: 'STOP' }))}/>
|
||||||
<Dashboard
|
<Dashboard
|
||||||
transcriptionText={serverData.text ?? "..."}
|
transcriptionText={serverData.text ?? "..."}
|
||||||
finalSummary={serverData.finalSummary}
|
finalSummary={serverData.finalSummary}
|
||||||
|
|||||||
Reference in New Issue
Block a user