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.5 KB
|
Line | |
---|
1 | "use strict";
|
---|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3 | var react_1 = require("react");
|
---|
4 | var util_1 = require("./misc/util");
|
---|
5 | var useMediaDevices = function () {
|
---|
6 | var _a = react_1.useState({}), state = _a[0], setState = _a[1];
|
---|
7 | react_1.useEffect(function () {
|
---|
8 | var mounted = true;
|
---|
9 | var onChange = function () {
|
---|
10 | navigator.mediaDevices
|
---|
11 | .enumerateDevices()
|
---|
12 | .then(function (devices) {
|
---|
13 | if (mounted) {
|
---|
14 | setState({
|
---|
15 | devices: devices.map(function (_a) {
|
---|
16 | var deviceId = _a.deviceId, groupId = _a.groupId, kind = _a.kind, label = _a.label;
|
---|
17 | return ({
|
---|
18 | deviceId: deviceId,
|
---|
19 | groupId: groupId,
|
---|
20 | kind: kind,
|
---|
21 | label: label,
|
---|
22 | });
|
---|
23 | }),
|
---|
24 | });
|
---|
25 | }
|
---|
26 | })
|
---|
27 | .catch(util_1.noop);
|
---|
28 | };
|
---|
29 | util_1.on(navigator.mediaDevices, 'devicechange', onChange);
|
---|
30 | onChange();
|
---|
31 | return function () {
|
---|
32 | mounted = false;
|
---|
33 | util_1.off(navigator.mediaDevices, 'devicechange', onChange);
|
---|
34 | };
|
---|
35 | }, []);
|
---|
36 | return state;
|
---|
37 | };
|
---|
38 | var useMediaDevicesMock = function () { return ({}); };
|
---|
39 | exports.default = util_1.isNavigator && !!navigator.mediaDevices ? useMediaDevices : useMediaDevicesMock;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.