mattermost-mobile/app/products/calls/actions/permissions.ts
Christopher Poile 8374d7e87f
MM-47004 - Calls: Client-side errors for microphone permissions (#6669)
* call error bar for microphone permissions; global permissions state

* i18n

* refactor permissionErrorBar component, PR comments

* add module dependency's mocks for tests

* fix error bar height

* change permissions error text

* working on 46999 redo audio handling -- will revert

* Revert "working on 46999 redo audio handling -- will revert"

This reverts commit 87bafc452c6ad6e1d7ae79ce78a0f2b461c2f150.

* only get voice track when we have mic permissions

* Android: enable mic when permissions are granted
2022-11-08 10:52:52 -05:00

27 lines
865 B
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Platform} from 'react-native';
import Permissions from 'react-native-permissions';
export const hasMicrophonePermission = async () => {
const targetSource = Platform.select({
ios: Permissions.PERMISSIONS.IOS.MICROPHONE,
default: Permissions.PERMISSIONS.ANDROID.RECORD_AUDIO,
});
const hasPermission = await Permissions.check(targetSource);
switch (hasPermission) {
case Permissions.RESULTS.DENIED:
case Permissions.RESULTS.UNAVAILABLE: {
const permissionRequest = await Permissions.request(targetSource);
return permissionRequest === Permissions.RESULTS.GRANTED;
}
case Permissions.RESULTS.BLOCKED:
return false;
}
return true;
};