From de03543b28f1fc0e4f7fb9f8fb81f8f7a082c3b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E7=A8=8B=E8=AE=AD?= Date: Thu, 2 Nov 2023 23:29:41 +0800 Subject: [PATCH] Version_0.2.6-fix2 --- dist/index.js | 92 ++++++++++++++++++++++++++++++++++++++++++++++-- esm/index.js | 2 +- package.json | 2 +- src/index.ts | 2 +- types/index.d.ts | 2 +- 5 files changed, 94 insertions(+), 6 deletions(-) diff --git a/dist/index.js b/dist/index.js index 1280fdb..ebca316 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,5 +1,5 @@ /*! - * @uni-helper/galanga 0.2.6-fix1 (https://github.com/uni-helper/galanga) + * @uni-helper/galanga 0.2.6-fix2 (https://github.com/uni-helper/galanga) * API https://galanga.censujiang.com/api/ * Copyright 2014-2023 censujiang. All Rights Reserved * Licensed under Apache License 2.0 (https://github.com/uni-helper/galanga/blob/master/LICENSE) @@ -450,6 +450,42 @@ const cameraPermission$1 = { } } }; +//麦克风权限相关 +const microphonePermission$1 = { + //判断是否有麦克风权限 + check: async () => { + //判断浏览器是否支持MediaDevices + if (!('mediaDevices' in navigator)) { + return false; + } + else { + //尝试获取麦克风信息 + try { + return await defaultW3PermissionQueryCheck("microphone"); + } + catch { + return false; + } + } + }, + //请求麦克风权限 + request: async () => { + let check = await microphonePermission$1.check(); + if (check === null) { + try { + await navigator.mediaDevices.getUserMedia({ audio: true }); + return true; + } + catch { + check = await microphonePermission$1.check(); + return check === true; + } + } + else { + return check === true; + } + } +}; async function defaultW3PermissionQueryCheck(permissionName) { const info = await navigator.permissions.query({ name: permissionName }); if (info.state === 'granted') { @@ -1177,6 +1213,58 @@ const cameraPermission = { return result; } }; +// 麦克风权限相关 +const microphonePermission = { + check: async () => { + let result; + // #ifdef H5 + result = await microphonePermission$1.check(); + // #endif + // #ifdef APP-PLUS + result = await requestAndroidPermission('android.permission.RECORD_AUDIO'); + // #endif + // #ifndef H5 || APP-PLUS + result = await uni.authorize({ + scope: 'scope.record' + }).then(() => { + return true; + }).catch(() => { + return false; + }); + // #endif + return result; + }, + request: async () => { + let result; + // #ifdef H5 + result = await microphonePermission$1.request(); + // #endif + // #ifdef MP || QUICKAPP-WEBVIEW + result = await uni.authorize({ + scope: 'scope.record' + }).then(() => { + return true; + }).catch(() => { + return false; + }); + // #endif + // #ifdef APP-PLUS + if (isIOS === true) { + //直接发起一个录音请求,如果用户拒绝了,就会返回错误 + result = await uni.startRecord().then(() => { + uni.stopRecord(); + return true; + }).catch(() => { + return false; + }); + } + else { + result = await requestAndroidPermission('android.permission.RECORD_AUDIO'); + } + // #endif + return result; + } +}; // Android权限查询 async function requestAndroidPermission(permissionID) { return new Promise((resolve, reject) => { @@ -1219,4 +1307,4 @@ const info = { //version: packageJson.version, }; -export { afterTime, arrayFilterUniqueItem, cameraPermission, checkDeviceType, checkEmail, checkNotNull, checkNull, checkPassword, clipboard, clipboardPermission, decode62, encode62, filterUniqueByProperty, formatBytes, formatNumber, formatPercent, getFileExtFromString, getFileNameFromURL, getPreURL, info, localCookie, locationPermission, notificationPermission, share, sleep, spliceSiteTitle, strLength, updateObjectFromImport, url }; +export { afterTime, arrayFilterUniqueItem, cameraPermission, checkDeviceType, checkEmail, checkNotNull, checkNull, checkPassword, clipboard, clipboardPermission, decode62, encode62, filterUniqueByProperty, formatBytes, formatNumber, formatPercent, getFileExtFromString, getFileNameFromURL, getPreURL, info, localCookie, locationPermission, microphonePermission, notificationPermission, share, sleep, spliceSiteTitle, strLength, updateObjectFromImport, url }; diff --git a/esm/index.js b/esm/index.js index 7824b38..8b3baa9 100644 --- a/esm/index.js +++ b/esm/index.js @@ -17,4 +17,4 @@ export { sleep } from 'galanga'; export { localCookie } from './cookie'; export { url, getPreURL } from './url'; export { checkDeviceType, clipboard, share } from './device'; -export { notificationPermission, clipboardPermission, locationPermission, cameraPermission } from './permission'; +export { notificationPermission, clipboardPermission, locationPermission, cameraPermission, microphonePermission } from './permission'; diff --git a/package.json b/package.json index 61bfb21..ca574ba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uni-helper/galanga", - "version": "0.2.6-fix1", + "version": "0.2.6-fix2", "description": "JS common function library(UNI-APP version of Galanga)", "main": "esm/index.js", "jsnext:main": "esm/index.js", diff --git a/src/index.ts b/src/index.ts index 04ec0c7..a0e7d81 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,4 +20,4 @@ export { sleep } from 'galanga'; export { localCookie } from './cookie'; export { url, getPreURL } from './url'; export { checkDeviceType, clipboard, share } from './device'; -export { notificationPermission, clipboardPermission, locationPermission, cameraPermission } from './permission'; \ No newline at end of file +export { notificationPermission, clipboardPermission, locationPermission, cameraPermission, microphonePermission } from './permission'; \ No newline at end of file diff --git a/types/index.d.ts b/types/index.d.ts index d46cdc9..78b8559 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -12,4 +12,4 @@ export { sleep } from 'galanga'; export { localCookie } from './cookie'; export { url, getPreURL } from './url'; export { checkDeviceType, clipboard, share } from './device'; -export { notificationPermission, clipboardPermission, locationPermission, cameraPermission } from './permission'; +export { notificationPermission, clipboardPermission, locationPermission, cameraPermission, microphonePermission } from './permission';