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
|
Rev | Line | |
---|
[d565449] | 1 | import { useEffect, useState } from 'react';
|
---|
| 2 | import { isNavigator, noop, off, on } from './misc/util';
|
---|
| 3 | var 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 | };
|
---|
| 36 | var useMediaDevicesMock = function () { return ({}); };
|
---|
| 37 | export default isNavigator && !!navigator.mediaDevices ? useMediaDevices : useMediaDevicesMock;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.