Socket
Socket
Sign inDemoInstall

react-media-devices

Package Overview
Dependencies
10
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.2 to 1.0.3

20

lib/cjs/useMediaDevices.js
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useMediaDevices = void 0;
var react_1 = require("react");
var use_deep_compare_effect_1 = __importDefault(require("use-deep-compare-effect"));
var mediaDevices_1 = require("./utils/mediaDevices");
var useMediaDevices = function (_a) {
var _b = _a === void 0 ? {} : _a, constraints = _b.constraints, _c = _b.verbose, verbose = _c === void 0 ? process.env.NODE_ENV !== "production" : _c;
var _b = _a === void 0 ? {} : _a, constraints = _b.constraints, _c = _b.onError, onError = _c === void 0 ? function () { } : _c;
var _d = (0, react_1.useState)(null), mediaDevices = _d[0], setMediaDevices = _d[1];
var errorHandlerRef = (0, react_1.useRef)(null);
(0, react_1.useEffect)(function () {
errorHandlerRef.current = onError;
}, [onError]);
(0, use_deep_compare_effect_1.default)(function () {
var ac = new AbortController();
console.log("effect");
new Promise(function (resolve, reject) {
ac.signal.addEventListener("abort", reject);
console.log(constraints);
(0, mediaDevices_1.getMediaDevices)(constraints).then(resolve);
})
.then(function (devices) {
console.log(devices);
setMediaDevices(devices);
})
.catch(function (error) {
var _a;
if (error.type === "abort")
return;
if (verbose) {
console.error(error);
}
(_a = errorHandlerRef.current) === null || _a === void 0 ? void 0 : _a.call(errorHandlerRef, error);
});

@@ -28,5 +38,5 @@ return function () {

};
}, [verbose, constraints]);
}, [constraints]);
return mediaDevices;
};
exports.useMediaDevices = useMediaDevices;

@@ -1,21 +0,28 @@

import { useEffect, useState } from "react";
import { useEffect, useRef, useState } from "react";
import useDeepCompareEffect from "use-deep-compare-effect";
import { getMediaDevices } from "./utils/mediaDevices";
export var useMediaDevices = function (_a) {
var _b = _a === void 0 ? {} : _a, constraints = _b.constraints, _c = _b.verbose, verbose = _c === void 0 ? process.env.NODE_ENV !== "production" : _c;
var _b = _a === void 0 ? {} : _a, constraints = _b.constraints, _c = _b.onError, onError = _c === void 0 ? function () { } : _c;
var _d = useState(null), mediaDevices = _d[0], setMediaDevices = _d[1];
var errorHandlerRef = useRef(null);
useEffect(function () {
errorHandlerRef.current = onError;
}, [onError]);
useDeepCompareEffect(function () {
var ac = new AbortController();
console.log("effect");
new Promise(function (resolve, reject) {
ac.signal.addEventListener("abort", reject);
console.log(constraints);
getMediaDevices(constraints).then(resolve);
})
.then(function (devices) {
console.log(devices);
setMediaDevices(devices);
})
.catch(function (error) {
var _a;
if (error.type === "abort")
return;
if (verbose) {
console.error(error);
}
(_a = errorHandlerRef.current) === null || _a === void 0 ? void 0 : _a.call(errorHandlerRef, error);
});

@@ -25,4 +32,4 @@ return function () {

};
}, [verbose, constraints]);
}, [constraints]);
return mediaDevices;
};
interface UseMediaDevicesOptions {
constraints?: MediaStreamConstraints;
verbose?: boolean;
onError?: (error: Error) => void;
}
export declare const useMediaDevices: ({ constraints, verbose, }?: UseMediaDevicesOptions) => MediaDeviceInfo[] | null;
export declare const useMediaDevices: ({ constraints, onError, }?: UseMediaDevicesOptions) => MediaDeviceInfo[] | null;
export {};
{
"name": "react-media-devices",
"version": "1.0.2",
"version": "1.0.3",
"description": "A custom hook to enumerate user media devices, using the MediaDevices API",

@@ -68,3 +68,6 @@ "main": "./lib/cjs/index.js",

]
},
"dependencies": {
"use-deep-compare-effect": "^1.8.1"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc