@sfourdrinier/react-native-ble-plx
Version:
React Native Bluetooth Low Energy library
72 lines (71 loc) • 4.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BackgroundMode = void 0;
const config_plugins_1 = require("@expo/config-plugins");
// Path is ../../package.json because this file is compiled to plugin/build/withBLE.js
const pkg = require('../../package.json');
const withBLEAndroidManifest_1 = require("./withBLEAndroidManifest");
const withBLEAndroidForegroundService_1 = require("./withBLEAndroidForegroundService");
const withBLEBackgroundModes_1 = require("./withBLEBackgroundModes");
Object.defineProperty(exports, "BackgroundMode", { enumerable: true, get: function () { return withBLEBackgroundModes_1.BackgroundMode; } });
const withBluetoothPermissions_1 = require("./withBluetoothPermissions");
const withBLEDebugLogging_1 = require("./withBLEDebugLogging");
const withBLERestorationPodfile_1 = require("./withBLERestorationPodfile");
const debugLog_1 = require("./debugLog");
/**
* Apply BLE native configuration.
*/
const withBLE = (config, props = {}) => {
const _props = props || {};
const debugEnabled = (0, debugLog_1.isBlePlxPluginDebugEnabled)(_props.debug);
(0, debugLog_1.blePlxPluginDebugLog)(debugEnabled, 'Plugin running with props:', JSON.stringify(props));
(0, debugLog_1.blePlxPluginDebugLog)(debugEnabled, 'Package name from pkg.json:', pkg.name);
config = (0, withBLEDebugLogging_1.withBLEDebugLogging)(config, { debugEnabled });
const isBackgroundEnabled = _props.isBackgroundEnabled ?? false;
const neverForLocation = _props.neverForLocation ?? false;
const iosEnableRestoration = _props.iosEnableRestoration ?? false;
const iosRestorationIdentifier = _props.iosRestorationIdentifier ?? 'com.reactnativebleplx.restore';
const androidEnableForegroundService = _props.androidEnableForegroundService ?? false;
(0, debugLog_1.blePlxPluginDebugLog)(debugEnabled, 'iosEnableRestoration:', iosEnableRestoration);
(0, debugLog_1.blePlxPluginDebugLog)(debugEnabled, 'androidEnableForegroundService:', androidEnableForegroundService);
// iOS
config = (0, withBluetoothPermissions_1.withBluetoothPermissions)(config, _props);
config = (0, withBLEBackgroundModes_1.withBLEBackgroundModes)(config, _props.modes || []);
if (iosEnableRestoration) {
(0, debugLog_1.blePlxPluginDebugLog)(debugEnabled, '✓ iosEnableRestoration is TRUE - adding Restoration subspec');
(0, debugLog_1.blePlxPluginDebugLog)(debugEnabled, 'Setting BlePlxRestoreIdentifier in Info.plist:', iosRestorationIdentifier);
// Persist the identifier in Info.plist so the Swift adapter can read it
config = (0, config_plugins_1.withInfoPlist)(config, conf => {
conf.modResults.BlePlxRestoreIdentifier = iosRestorationIdentifier;
return conf;
});
(0, debugLog_1.blePlxPluginDebugLog)(debugEnabled, 'Calling withBLERestorationPodfile with pkgName:', pkg.name);
// Inject Restoration subspec into Podfile
config = (0, withBLERestorationPodfile_1.withBLERestorationPodfile)(config, { pkgName: pkg.name });
}
else {
(0, debugLog_1.blePlxPluginDebugLog)(debugEnabled, '✗ iosEnableRestoration is FALSE - skipping Restoration subspec');
}
// Android
config = config_plugins_1.AndroidConfig.Permissions.withPermissions(config, [
'android.permission.BLUETOOTH',
'android.permission.BLUETOOTH_ADMIN',
'android.permission.BLUETOOTH_CONNECT' // since Android SDK 31
]);
config = (0, withBLEAndroidManifest_1.withBLEAndroidManifest)(config, {
isBackgroundEnabled,
neverForLocation
});
// Android foreground service for background BLE operations
if (androidEnableForegroundService) {
(0, debugLog_1.blePlxPluginDebugLog)(debugEnabled, '✓ androidEnableForegroundService is TRUE - adding foreground service config');
config = (0, withBLEAndroidForegroundService_1.withBLEAndroidForegroundService)(config, {
enableAndroidForegroundService: true
});
}
else {
(0, debugLog_1.blePlxPluginDebugLog)(debugEnabled, '✗ androidEnableForegroundService is FALSE - skipping foreground service config');
}
return config;
};
exports.default = (0, config_plugins_1.createRunOncePlugin)(withBLE, pkg.name, pkg.version);