2023-09-26 03:39:17 -06:00
|
|
|
import { withPlugins, AndroidConfig, ConfigPlugin, createRunOncePlugin } from '@expo/config-plugins'
|
|
|
|
import { withDisableFrameProcessorsAndroid } from './withDisableFrameProcessorsAndroid'
|
|
|
|
import { withDisableFrameProcessorsIOS } from './withDisableFrameProcessorsIOS'
|
2021-07-07 06:55:25 -06:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment
|
2023-09-26 03:39:17 -06:00
|
|
|
const pkg = require('../../../package.json')
|
2021-07-07 06:55:25 -06:00
|
|
|
|
2023-09-26 03:39:17 -06:00
|
|
|
const CAMERA_USAGE = 'Allow $(PRODUCT_NAME) to access your camera'
|
|
|
|
const MICROPHONE_USAGE = 'Allow $(PRODUCT_NAME) to access your microphone'
|
2021-07-07 06:55:25 -06:00
|
|
|
|
|
|
|
type Props = {
|
2023-09-26 03:39:17 -06:00
|
|
|
cameraPermissionText?: string
|
|
|
|
enableMicrophonePermission?: boolean
|
|
|
|
microphonePermissionText?: string
|
|
|
|
disableFrameProcessors?: boolean
|
|
|
|
}
|
2021-07-07 06:55:25 -06:00
|
|
|
|
|
|
|
const withCamera: ConfigPlugin<Props> = (config, props = {}) => {
|
2023-09-26 03:39:17 -06:00
|
|
|
if (config.ios == null) config.ios = {}
|
|
|
|
if (config.ios.infoPlist == null) config.ios.infoPlist = {}
|
2021-07-07 06:55:25 -06:00
|
|
|
config.ios.infoPlist.NSCameraUsageDescription =
|
2023-09-26 03:39:17 -06:00
|
|
|
props.cameraPermissionText ?? (config.ios.infoPlist.NSCameraUsageDescription as string | undefined) ?? CAMERA_USAGE
|
2021-07-07 06:55:25 -06:00
|
|
|
if (props.enableMicrophonePermission) {
|
|
|
|
config.ios.infoPlist.NSMicrophoneUsageDescription =
|
2023-09-26 03:39:17 -06:00
|
|
|
props.microphonePermissionText ?? (config.ios.infoPlist.NSMicrophoneUsageDescription as string | undefined) ?? MICROPHONE_USAGE
|
2021-07-07 06:55:25 -06:00
|
|
|
}
|
2023-09-26 03:39:17 -06:00
|
|
|
const androidPermissions = ['android.permission.CAMERA']
|
|
|
|
if (props.enableMicrophonePermission) androidPermissions.push('android.permission.RECORD_AUDIO')
|
2021-07-07 06:55:25 -06:00
|
|
|
|
2022-01-11 04:31:24 -07:00
|
|
|
if (props.disableFrameProcessors) {
|
2023-09-26 03:39:17 -06:00
|
|
|
config = withDisableFrameProcessorsAndroid(config)
|
|
|
|
config = withDisableFrameProcessorsIOS(config)
|
2022-01-11 04:31:24 -07:00
|
|
|
}
|
|
|
|
|
2023-09-26 03:39:17 -06:00
|
|
|
return withPlugins(config, [[AndroidConfig.Permissions.withPermissions, androidPermissions]])
|
|
|
|
}
|
2021-07-07 06:55:25 -06:00
|
|
|
|
2023-09-26 03:39:17 -06:00
|
|
|
export default createRunOncePlugin(withCamera, pkg.name, pkg.version)
|