From 6a4a898fe3f0bfa6b2b61edfcc329c89b74ffaca Mon Sep 17 00:00:00 2001 From: Brian Li Date: Fri, 1 Oct 2021 10:23:05 -0700 Subject: [PATCH] semantic version bump to 1.1.0 --- lib/requestMediaPermissions.d.ts | 6 ++++-- lib/requestMediaPermissions.js | 17 ++++++++--------- package.json | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/requestMediaPermissions.d.ts b/lib/requestMediaPermissions.d.ts index 9c9fc94..246f002 100644 --- a/lib/requestMediaPermissions.d.ts +++ b/lib/requestMediaPermissions.d.ts @@ -14,7 +14,9 @@ export declare enum MediaPermissionsErrorType { Generic = "Generic" } /** - * Here's some documentation + * Request camera and mic permissions from the browser. * @returns */ -export declare const requestMediaPermissions: () => Promise; +export declare const requestMediaPermissions: (constraints?: MediaStreamConstraints | undefined) => Promise; +export declare const requestAudioPermissions: () => Promise; +export declare const requestVideoPermissions: () => Promise; diff --git a/lib/requestMediaPermissions.js b/lib/requestMediaPermissions.js index 4430bd2..edb154c 100644 --- a/lib/requestMediaPermissions.js +++ b/lib/requestMediaPermissions.js @@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.requestMediaPermissions = exports.MediaPermissionsErrorType = void 0; +exports.requestVideoPermissions = exports.requestAudioPermissions = exports.requestMediaPermissions = exports.MediaPermissionsErrorType = void 0; const bowser_1 = __importDefault(require("bowser")); var MediaPermissionsErrorType; (function (MediaPermissionsErrorType) { @@ -17,14 +17,13 @@ var MediaPermissionsErrorType; MediaPermissionsErrorType["Generic"] = "Generic"; })(MediaPermissionsErrorType = exports.MediaPermissionsErrorType || (exports.MediaPermissionsErrorType = {})); /** - * Here's some documentation + * Request camera and mic permissions from the browser. * @returns */ -const requestMediaPermissions = () => { +const requestMediaPermissions = (constraints) => { return new Promise((resolve, reject) => { - let constraints = { audio: true, video: true }; navigator.mediaDevices - .getUserMedia(constraints) + .getUserMedia(constraints !== null && constraints !== void 0 ? constraints : { audio: true, video: true }) .then((stream) => { stream.getTracks().forEach((t) => { t.stop(); @@ -34,10 +33,6 @@ const requestMediaPermissions = () => { .catch((err) => { const browser = bowser_1.default.getParser(window.navigator.userAgent); const browserName = browser.getBrowserName(); - console.log(browserName); - console.log(err.name); - console.log(err.message); - console.log(browser); const errName = err.name; const errMessage = err.message; let errorType = MediaPermissionsErrorType.Generic; @@ -103,3 +98,7 @@ const requestMediaPermissions = () => { }); }; exports.requestMediaPermissions = requestMediaPermissions; +const requestAudioPermissions = () => (0, exports.requestMediaPermissions)({ audio: true, video: false }); +exports.requestAudioPermissions = requestAudioPermissions; +const requestVideoPermissions = () => (0, exports.requestMediaPermissions)({ audio: false, video: true }); +exports.requestVideoPermissions = requestVideoPermissions; diff --git a/package.json b/package.json index ee50e3e..f5fc453 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "mic-check", "title": "mic-check", - "version": "1.0.1", + "version": "1.1.0", "description": "A wrapper for requesting audio and video permissions on JavaScript websites.", "main": "lib/index.js", "module": "lib/index.js",