import { useEffect, useState } from 'react'; import { isNavigator, noop, off, on } from './misc/util'; var useMediaDevices = function () { var _a = useState({}), state = _a[0], setState = _a[1]; useEffect(function () { var mounted = true; var onChange = function () { navigator.mediaDevices .enumerateDevices() .then(function (devices) { if (mounted) { setState({ devices: devices.map(function (_a) { var deviceId = _a.deviceId, groupId = _a.groupId, kind = _a.kind, label = _a.label; return ({ deviceId: deviceId, groupId: groupId, kind: kind, label: label, }); }), }); } }) .catch(noop); }; on(navigator.mediaDevices, 'devicechange', onChange); onChange(); return function () { mounted = false; off(navigator.mediaDevices, 'devicechange', onChange); }; }, []); return state; }; var useMediaDevicesMock = function () { return ({}); }; export default isNavigator && !!navigator.mediaDevices ? useMediaDevices : useMediaDevicesMock;