The useMicrophone hook gathers functions responsible for managing microphones.
| Name | Type | Description |
|---|---|---|
getMicrophones |
() => Promise<Mic[]> | Gets a list of the available microphones. |
selectMicrophone |
(Mic) => void | Selects a microphone. |
getDefaultLocalMicrophone |
() => Promise<MediaDeviceInfo|null> | Gets data of default microphone. |
getMicrophonePermission |
() => Promise | Check status of browser microphone permissions. |
const { getMicrophones, selectMicrophone } = useMicrophone();
const microphones = getMicrophones();
...
return (
microphones.map((m) => (
<div onClick={() => selectMicrophone(m)}>...</div>
))
)const { toggleAudio } = useMicrophone();
...
<button onClick={toggleMicrophone}>...</button>const { getMicrophonePermission } = useMicrophone();
const [isMicrophonePermission, setIsMicrophonePermission] = useState(false);
useEffect(() => {
(async () => {
try {
const hasAccess = await getMicrophonePermission();
setIsMicrophonePermission(hasAccess);
} catch {
setIsMicrophonePermission(false);
}
})();
}, []);
<button disabled={!isMicrophonePermission}>...</button>;