Skip to content

Commit

Permalink
Version_0.2.6-fix2
Browse files Browse the repository at this point in the history
  • Loading branch information
censujiang committed Nov 2, 2023
1 parent d9bc904 commit de03543
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 6 deletions.
92 changes: 90 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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 };
2 changes: 1 addition & 1 deletion esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
export { notificationPermission, clipboardPermission, locationPermission, cameraPermission, microphonePermission } from './permission';
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit de03543

Please sign in to comment.