Created
July 1, 2021 07:34
-
-
Save alexxty7/b80fc168af8f5bfe21732b92eaefd9c9 to your computer and use it in GitHub Desktop.
Revisions
-
alexxty7 revised this gist
Jul 1, 2021 . 1 changed file with 12 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,4 +20,16 @@ export default function useDevices() { return deviceInfo; } export async function getDeviceInfo() { const devices = await navigator.mediaDevices.enumerateDevices(); return { audioInputDevices: devices.filter(device => device.kind === 'audioinput'), videoInputDevices: devices.filter(device => device.kind === 'videoinput'), audioOutputDevices: devices.filter(device => device.kind === 'audiooutput'), hasAudioInputDevices: devices.some(device => device.kind === 'audioinput'), hasVideoInputDevices: devices.some(device => device.kind === 'videoinput'), }; } -
alexxty7 created this gist
Jul 1, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ export default function useDevices() { const [deviceInfo, setDeviceInfo] = useState({ audioInputDevices: [], videoInputDevices: [], audioOutputDevices: [], hasAudioInputDevices: false, hasVideoInputDevices: false, }); useEffect(() => { const getDevices = () => getDeviceInfo().then(devices => setDeviceInfo(devices)); navigator.mediaDevices.addEventListener('devicechange', getDevices); getDevices(); return () => { navigator.mediaDevices.removeEventListener('devicechange', getDevices); }; }, []); return deviceInfo; }