Skip to content

Commit

Permalink
feat: add typescript declaration file
Browse files Browse the repository at this point in the history
This commit adds the typescript declaration file. It further upgrades
parcel to version 2. This needed to be done to get rid of the `Invalid
Version: undefined` error (see
parcel-bundler/parcel#5943). While doing so I
also had to change the react import in the `example/index.js` due to a parcel
bug (see parcel-bundler/parcel#1199).
  • Loading branch information
rickstaa committed Oct 26, 2021
1 parent 3cff891 commit e755c1e
Show file tree
Hide file tree
Showing 10 changed files with 12,444 additions and 22 deletions.
8 changes: 0 additions & 8 deletions .babelrc.js

This file was deleted.

8 changes: 8 additions & 0 deletions .babelrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"env": {
"test": {
"presets": [["@babel/env", { "targets": { "node": "current" } }]]
}
},
"presets": ["@babel/env"]
}
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
module.exports = {
env: { browser: 1 },
extends: 'seegno'
extends: 'seegno',
settings: {
react: {
version: 'detect'
}
}
};
9 changes: 9 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface UserMediaState {
error: MediaError | null;
state: string;
stream: MediaStream | undefined;
}

declare function useUserMedia(constraints: MediaStreamConstraints): UserMediaState;

export default useUserMedia;
10 changes: 7 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ var _stopMediaStream = _interopRequireDefault(require("stop-media-stream"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

Expand Down
2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
</head>
<body>
<div id="root"></div>
<script src="./index.js" type="text/javascript"></script>
<script type="module" src="./index.js" type="text/javascript"></script>
</body>
</html>
8 changes: 4 additions & 4 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { render } from 'react-dom';
import React, { useEffect, useRef } from 'react';
import useUserMedia from '../src';
import useUserMedia from '../dist';

const videoSize = { height: 480, width: 640 };
const constraints = {
Expand All @@ -9,9 +9,9 @@ const constraints = {

const Example = () => {
const { error, state, stream } = useUserMedia(constraints);
const ref = useRef();
const ref = React.useRef();

useEffect(() => {
React.useEffect(() => {
if (state !== 'resolved' || !stream) {
return;
}
Expand Down
Loading

0 comments on commit e755c1e

Please sign in to comment.