import { AndroidConfig, ConfigPlugin, createRunOncePlugin, withInfoPlist, } from '@expo/config-plugins'; const MICROPHONE = 'Allow $(PRODUCT_NAME) to access the microphone'; const CAMERA = 'Allow $(PRODUCT_NAME) to access the camera'; const BLUETOOTH = 'Allow $(PRODUCT_NAME) to access the bluetooth'; const BLUETOOTH_ALWAYS = 'Allow $(PRODUCT_NAME) to access the bluetooth'; const LIBRARY = 'Allow $(PRODUCT_NAME) to access the files'; export type Props = { /** * `NSMicrophoneUsageDescription` message. */ microphonePermission?: string | false; /** * `NSCameraUsageDescription` message. */ cameraPermission?: string | false; /** * `NSBluetoothPeripheralUsageDescription` message. */ bluetoothPermission?: string | false; /** * `NSBluetoothPeripheralUsageDescription` message. */ bluetoothAlwaysPermission?: string | false; /** * `NSPhotoLibraryUsageDescription` message. */ libraryPermission?: string | false; }; /** * Adds `NSMicrophoneUsageDescription` and `NSSpeechRecognitionUsageDescription` to the `Info.plist`. * * @param props.speechRecognitionPermission speech recognition message * @param props.microphonePermission microphone permission message * @returns */ const withIosPermissions: ConfigPlugin = ( c, { microphonePermission, cameraPermission, libraryPermission, bluetoothPermission, bluetoothAlwaysPermission, } = {} ) => { return withInfoPlist(c, (config) => { if (microphonePermission !== false) { config.modResults.NSMicrophoneUsageDescription = microphonePermission || config.modResults.NSMicrophoneUsageDescription || MICROPHONE; } if (cameraPermission !== false) { config.modResults.NSCameraUsageDescription = cameraPermission || config.modResults.NSCameraUsageDescription || CAMERA; } if (bluetoothPermission !== false) { config.modResults.NSBluetoothPeripheralUsageDescription = bluetoothPermission || config.modResults.NSBluetoothPeripheralUsageDescription || BLUETOOTH; } if (bluetoothAlwaysPermission !== false) { config.modResults.NSBluetoothAlwaysUsageDescription = bluetoothAlwaysPermission || config.modResults.NSBluetoothAlwaysUsageDescription || BLUETOOTH_ALWAYS; } if (libraryPermission !== false) { config.modResults.NSPhotoLibraryUsageDescription = libraryPermission || config.modResults.NSPhotoLibraryUsageDescription || LIBRARY; } if (config.modResults.UIBackgroundModes === undefined) { config.modResults.UIBackgroundModes = ['audio', 'voip']; } return config; }); }; /** * Adds the following to the `AndroidManifest.xml`: * */ const withAndroidPermissions: ConfigPlugin = (config) => { return AndroidConfig.Permissions.withPermissions(config, [ 'android.permission.ACCESS_NETWORK_STATE', 'android.permission.BLUETOOTH', 'android.permission.CAMERA', 'android.permission.INTERNET', 'android.permission.MODIFY_AUDIO_SETTINGS', 'android.permission.RECORD_AUDIO', 'android.permission.SYSTEM_ALERT_WINDOW', 'android.permission.WAKE_LOCK', 'android.permission.FOREGROUND_SERVICE', 'android.permission.FOREGROUND_SERVICE_CAMERA', 'android.permission.FOREGROUND_SERVICE_MICROPHONE', 'android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION', 'android.permission.WRITE_EXTERNAL_STORAGE', 'android.permission.READ_EXTERNAL_STORAGE', 'android.permission.MICROPHONE', ]); }; const withVoice: ConfigPlugin = (config, props = {}) => { const _props = props ? props : {}; config = withIosPermissions(config, _props); if (_props.microphonePermission !== false) { config = withAndroidPermissions(config); } return config; }; export default createRunOncePlugin(withVoice, '@dytesdk/react-native-core');