* ask for bluetooth permissions on Android * new "switch audio device button" for Android * i18n strings * split audio_device_button into platform-specific files; PR comments * earpiece -> phone * add comments to clarify speakerphone logic * update snapshots * add new compass-icons; use tablet and bluetooth icons; add tablet mode * fix lint
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
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 hasBluetoothPermission = async () => {
|
|
const bluetooth = Platform.select({
|
|
ios: Permissions.PERMISSIONS.IOS.BLUETOOTH_PERIPHERAL,
|
|
default: Permissions.PERMISSIONS.ANDROID.BLUETOOTH_CONNECT,
|
|
});
|
|
|
|
const hasBluetooth = await Permissions.check(bluetooth);
|
|
|
|
switch (hasBluetooth) {
|
|
case Permissions.RESULTS.DENIED:
|
|
case Permissions.RESULTS.UNAVAILABLE: {
|
|
const permissionRequest = await Permissions.request(bluetooth);
|
|
return permissionRequest === Permissions.RESULTS.GRANTED;
|
|
}
|
|
case Permissions.RESULTS.BLOCKED:
|
|
return false;
|
|
default:
|
|
return true;
|
|
}
|
|
};
|
|
|
|
export const hasMicrophonePermission = async () => {
|
|
const microphone = Platform.select({
|
|
ios: Permissions.PERMISSIONS.IOS.MICROPHONE,
|
|
default: Permissions.PERMISSIONS.ANDROID.RECORD_AUDIO,
|
|
});
|
|
|
|
const hasMicrophone = await Permissions.check(microphone);
|
|
|
|
switch (hasMicrophone) {
|
|
case Permissions.RESULTS.DENIED:
|
|
case Permissions.RESULTS.UNAVAILABLE: {
|
|
const permissionRequest = await Permissions.request(microphone);
|
|
return permissionRequest === Permissions.RESULTS.GRANTED;
|
|
}
|
|
case Permissions.RESULTS.BLOCKED:
|
|
return false;
|
|
default:
|
|
return true;
|
|
}
|
|
};
|
|
|