source: imaps-frontend/node_modules/react-use/esm/useMediaDevices.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.4 KB
RevLine 
[d565449]1import { useEffect, useState } from 'react';
2import { isNavigator, noop, off, on } from './misc/util';
3var useMediaDevices = function () {
4 var _a = useState({}), state = _a[0], setState = _a[1];
5 useEffect(function () {
6 var mounted = true;
7 var onChange = function () {
8 navigator.mediaDevices
9 .enumerateDevices()
10 .then(function (devices) {
11 if (mounted) {
12 setState({
13 devices: devices.map(function (_a) {
14 var deviceId = _a.deviceId, groupId = _a.groupId, kind = _a.kind, label = _a.label;
15 return ({
16 deviceId: deviceId,
17 groupId: groupId,
18 kind: kind,
19 label: label,
20 });
21 }),
22 });
23 }
24 })
25 .catch(noop);
26 };
27 on(navigator.mediaDevices, 'devicechange', onChange);
28 onChange();
29 return function () {
30 mounted = false;
31 off(navigator.mediaDevices, 'devicechange', onChange);
32 };
33 }, []);
34 return state;
35};
36var useMediaDevicesMock = function () { return ({}); };
37export default isNavigator && !!navigator.mediaDevices ? useMediaDevices : useMediaDevicesMock;
Note: See TracBrowser for help on using the repository browser.