Socket
Socket
Sign inDemoInstall

cordova-plugin-ble-central

Package Overview
Dependencies
0
Maintainers
2
Versions
58
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.2-alpha.0 to 1.4.2

.prettierrc

6

CHANGES.txt

@@ -0,1 +1,7 @@

= 1.4.2 =
Add typescript definitions for all methods
Add location state notifications on Android (similar to Bluetooth state notifications)
Add support for iOS state restoration. This is opt-in, see README for usage details #717
Turn API misuse warnings on iOS into reported errors to prevent dead scans #828
= 1.4.1 =

@@ -2,0 +8,0 @@ Add additional options to startScanWithOptions() on Android #835 Thanks helllamer

48

hooks/after_prepare.js

@@ -6,3 +6,4 @@ #!/usr/bin/env node

var ACCESS_BACKGROUND_LOCATION_PERMISSION = '<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />';
var ACCESS_BACKGROUND_LOCATION_PERMISSION =
'<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />';

@@ -18,3 +19,5 @@ module.exports = function (context) {

} else {
console.log(context.opts.plugin.id + ': ACCESS_BACKGROUND_LOCATION permission already exists in ' + manifestPath);
console.log(
context.opts.plugin.id + ': ACCESS_BACKGROUND_LOCATION permission already exists in ' + manifestPath
);
}

@@ -24,16 +27,20 @@ } else {

removeAccessBackgroundLocationToManifest(manifestPath, androidManifest);
console.log(context.opts.plugin.id + ': ACCESS_BACKGROUND_LOCATION permission removed from ' + manifestPath);
console.log(
context.opts.plugin.id + ': ACCESS_BACKGROUND_LOCATION permission removed from ' + manifestPath
);
} else {
console.log(context.opts.plugin.id + ': ACCESS_BACKGROUND_LOCATION permission does not exists in ' + manifestPath);
console.log(
context.opts.plugin.id + ': ACCESS_BACKGROUND_LOCATION permission does not exists in ' + manifestPath
);
}
}
}
};
var getAccessBackgroundLocationVariable = function () {
if (process.argv.join("|").indexOf("ACCESS_BACKGROUND_LOCATION=") > -1) {
return process.argv.join("|").match(/ACCESS_BACKGROUND_LOCATION=(.*?)(\||$)/)[1];
if (process.argv.join('|').indexOf('ACCESS_BACKGROUND_LOCATION=') > -1) {
return process.argv.join('|').match(/ACCESS_BACKGROUND_LOCATION=(.*?)(\||$)/)[1];
} else {
return getPreferenceValue("ACCESS_BACKGROUND_LOCATION");
return getPreferenceValue('ACCESS_BACKGROUND_LOCATION');
}
}
};

@@ -48,6 +55,6 @@ var getPreferenceValue = function (name) {

return preferenceValue;
}
};
var getPreferenceValueFromConfig = function (config, name) {
const value = config.match(new RegExp('name="' + name + '" value="(.*?)"', "i"));
const value = config.match(new RegExp('name="' + name + '" value="(.*?)"', 'i'));
if (value && value[1]) {

@@ -58,6 +65,6 @@ return value[1];

}
}
};
var getPreferenceValueFromPackageJson = function (packageJson, name) {
const value = packageJson.match(new RegExp('"' + name + '":\\s"(.*?)"', "i"));
const value = packageJson.match(new RegExp('"' + name + '":\\s"(.*?)"', 'i'));
if (value && value[1]) {

@@ -68,3 +75,3 @@ return value[1];

}
}
};

@@ -74,3 +81,3 @@ var getAndroidManifestFilePath = function (context) {

cordovaAndroid6: context.opts.projectRoot + '/platforms/android/AndroidManifest.xml',
cordovaAndroid7: context.opts.projectRoot + '/platforms/android/app/src/main/AndroidManifest.xml'
cordovaAndroid7: context.opts.projectRoot + '/platforms/android/app/src/main/AndroidManifest.xml',
};

@@ -84,3 +91,3 @@ if (fs.existsSync(manifestPath.cordovaAndroid7)) {

}
}
};

@@ -94,3 +101,3 @@ var accessBackgroundLocationExists = function (manifest) {

}
}
};

@@ -100,5 +107,6 @@ var addAccessBackgroundLocationToManifest = function (manifestPath, androidManifest) {

const accessBackgroundLocationPermissionLine = ' ' + ACCESS_BACKGROUND_LOCATION_PERMISSION + '\n';
const updatedManifest = androidManifest.substring(0, index) + accessBackgroundLocationPermissionLine + androidManifest.substring(index);
const updatedManifest =
androidManifest.substring(0, index) + accessBackgroundLocationPermissionLine + androidManifest.substring(index);
fs.writeFileSync(manifestPath, updatedManifest);
}
};

@@ -109,2 +117,2 @@ var removeAccessBackgroundLocationToManifest = function (manifestPath, androidManifest) {

fs.writeFileSync(manifestPath, updatedManifest);
}
};
{
"name": "cordova-plugin-ble-central",
"version": "1.4.2-alpha.0",
"version": "1.4.2",
"description": "Bluetooth Low Energy (BLE) Central Plugin",

@@ -34,3 +34,4 @@ "cordova": {

},
"types": "./types.d.ts",
"homepage": "https://github.com/don/cordova-plugin-ble-central#readme"
}

@@ -64,2 +64,8 @@ # Bluetooth Low Energy (BLE) Central Plugin for Apache Cordova

If background scanning and operation is required, the [iOS restore state](https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html#//apple_ref/doc/uid/TP40013257-CH7-SW13) should be enabled:
--variable BLUETOOTH_RESTORE_STATE=true
For more information about background operation, see [Background Scanning and Notifications on iOS](#background-scanning-and-notifications-on-ios).
### Android

@@ -71,4 +77,2 @@

If your app targets Android 12 (API level 31) or higher, you have to define BLUETOOTH_SCAN and BLUETOOTH_CONNECT permissions (https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#declare-android12-or-higher) into your Android Manifest.
# API

@@ -103,2 +107,3 @@

- [ble.peripheralsWithIdentifiers](#peripheralswithidentifiers)
- [ble.restoredBluetoothState](#restoredbluetoothstate)
- [ble.bondedDevices](#bondeddevices)

@@ -682,2 +687,43 @@

## startLocationStateNotifications
Registers to be notified when Location service state changes on the device.
ble.startLocationStateNotifications(success, failure);
### Description
Function `startLocationStateNotifications` calls the success callback when the Location service is enabled or disabled on the device.
### Supported Platforms
* Android
### Parameters
- __success__: Success callback function that is invoked with a boolean for the Location state.
- __failure__: Error callback function, invoked when error occurs. [optional]
### Quick Example
ble.startLocationStateNotifications(
function(enabled) {
console.log("Location is " + enabled);
}
);
## stopLocationStateNotifications
Stops state notifications.
ble.stopLocationStateNotifications(success, failure);
### Description
Function `stopLocationStateNotifications` calls the success callback when Location state notifications have been stopped.
### Supported Platforms
* Android
## startStateNotifications

@@ -838,3 +884,3 @@

Find the connected peripherals offering the listed service UUIDs.
Find the connected peripherals offering the listed peripheral UUIDs.

@@ -857,2 +903,26 @@ ble.peripheralsWithIdentifiers([uuids], success, failure);

## restoredBluetoothState
Retrieve the CBManager restoration state (if applicable)
ble.restoredBluetoothState(success, failure);
await ble.withPromises.restoredBluetoothState();
### Description
**Use of this feature requires the [BLUETOOTH_RESTORE_STATE variable to be set](#background-scanning-and-notifications-on-ios) to true.** For more information about background operation, see [Background Scanning and Notifications on iOS](#background-scanning-and-notifications-on-ios).
Retrives the state dictionary that [iOS State Preservation and Restoration](https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html#//apple_ref/doc/uid/TP40013257-CH7-SW10) will supply when the application was launched by iOS.
If the application has no state restored, this will return an empty object.
### Parameters
- __success__: Success callback function, invoked with the restored Bluetooth state (if any)
- __failure__: Error callback function
### Supported Platforms
* iOS
## bondedDevices

@@ -1032,6 +1102,2 @@

Install the [cordova-custom-config](https://www.npmjs.com/package/cordova-custom-config) plugin.
cordova plugin add cordova-custom-config
Add a new section to config.xml

@@ -1049,2 +1115,14 @@

Additionally, iOS state restoration should be enabled if long-running scans or connects should be restarted after the phone is rebooted or the app is suspended by iOS. See [iOS restore state](https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html#//apple_ref/doc/uid/TP40013257-CH7-SW13) for the details and limitations of this feature.
To activate iOS state restoration, set the BLUETOOTH_RESTORE_STATE to true when adding the plugin to the project:
--variable BLUETOOTH_RESTORE_STATE=true
By default, the app id (otherwise known as the bundle identifier) will be used as the iOS restore identifier key. This can be overridden by setting the variable to the desired key directly. For example:
--variable BLUETOOTH_RESTORE_STATE=my.custom.restoration.identifier.key
It's important to note that iOS will **not** automatically relaunch an application under some conditions. For a detailed list of these conditions, see the [iOS Technical QA on the subject](https://developer.apple.com/library/archive/qa/qa1962/_index.html).
# Testing the Plugin

@@ -1051,0 +1129,0 @@

exports.defineAutoTests = function () {
describe('BLE object', function () {
it("ble should exist", function () {
it('ble should exist', function () {
expect(ble).toBeDefined();
});
it("should contain a startScan function", function () {
it('should contain a startScan function', function () {
expect(typeof ble.startScan).toBeDefined();
expect(typeof ble.startScan).toBe("function");
expect(typeof ble.startScan).toBe('function');
});
});
};
exports.defineManualTests = function (contentEl, createActionButton) {
createActionButton('Is Bluetooth Enabled?', function() {
createActionButton('Is Bluetooth Enabled?', function () {
ble.isEnabled(
function() {
console.log("Bluetooth is enabled");
function () {
console.log('Bluetooth is enabled');
},
function() {
console.log("Bluetooth is *not* enabled");
function () {
console.log('Bluetooth is *not* enabled');
}

@@ -30,7 +26,5 @@ );

if (cordova.platformId !== 'ios') {
// not supported on iOS
createActionButton('Show Bluetooth Settings', function() {
createActionButton('Show Bluetooth Settings', function () {
ble.showBluetoothSettings();

@@ -40,34 +34,38 @@ });

// not supported on iOS
createActionButton('Enable Bluetooth', function() {
createActionButton('Enable Bluetooth', function () {
ble.enable(
function() {
console.log("Bluetooth is enabled");
function () {
console.log('Bluetooth is enabled');
},
function() {
console.log("The user did *not* enable Bluetooth");
function () {
console.log('The user did *not* enable Bluetooth');
}
);
});
}
createActionButton('Scan', function() {
createActionButton('Scan', function () {
var scanSeconds = 5;
console.log("Scanning for BLE peripherals for " + scanSeconds + " seconds.");
ble.startScan([], function(device) {
console.log(JSON.stringify(device));
}, function(reason) {
console.log("BLE Scan failed " + reason);
});
console.log('Scanning for BLE peripherals for ' + scanSeconds + ' seconds.');
ble.startScan(
[],
function (device) {
console.log(JSON.stringify(device));
},
function (reason) {
console.log('BLE Scan failed ' + reason);
}
);
setTimeout(ble.stopScan,
setTimeout(
ble.stopScan,
scanSeconds * 1000,
function() { console.log("Scan complete"); },
function() { console.log("stopScan failed"); }
function () {
console.log('Scan complete');
},
function () {
console.log('stopScan failed');
}
);
});
};

@@ -16,5 +16,5 @@ // (c) 2014-2016 Don Coleman

/* global cordova, module */
"use strict";
'use strict';
var stringToArrayBuffer = function(str) {
var stringToArrayBuffer = function (str) {
var ret = new Uint8Array(str.length);

@@ -27,3 +27,3 @@ for (var i = 0; i < str.length; i++) {

var base64ToArrayBuffer = function(b64) {
var base64ToArrayBuffer = function (b64) {
return stringToArrayBuffer(atob(b64));

@@ -45,3 +45,3 @@ };

object[key] = massageMessageNativeToJs(value);
if (typeof(value) === 'object') {
if (typeof value === 'object') {
convertToNativeJS(value);

@@ -56,5 +56,4 @@ }

module.exports = {
scan: function (services, seconds, success, failure) {
var successWrapper = function(peripheral) {
var successWrapper = function (peripheral) {
convertToNativeJS(peripheral);

@@ -67,3 +66,3 @@ success(peripheral);

startScan: function (services, success, failure) {
var successWrapper = function(peripheral) {
var successWrapper = function (peripheral) {
convertToNativeJS(peripheral);

@@ -79,4 +78,4 @@ success(peripheral);

startScanWithOptions: function(services, options, success, failure) {
var successWrapper = function(peripheral) {
startScanWithOptions: function (services, options, success, failure) {
var successWrapper = function (peripheral) {
convertToNativeJS(peripheral);

@@ -90,3 +89,3 @@ success(peripheral);

// iOS only
connectedPeripheralsWithServices: function(services, success, failure) {
connectedPeripheralsWithServices: function (services, success, failure) {
cordova.exec(success, failure, 'BLE', 'connectedPeripheralsWithServices', [services]);

@@ -96,3 +95,3 @@ },

// iOS only
peripheralsWithIdentifiers: function(identifiers, success, failure) {
peripheralsWithIdentifiers: function (identifiers, success, failure) {
cordova.exec(success, failure, 'BLE', 'peripheralsWithIdentifiers', [identifiers]);

@@ -102,3 +101,3 @@ },

// Android only
bondedDevices: function(success, failure) {
bondedDevices: function (success, failure) {
cordova.exec(success, failure, 'BLE', 'bondedDevices', []);

@@ -114,7 +113,7 @@ },

// wrap success so nested array buffers in advertising info are handled correctly
var successWrapper = function(peripheral) {
var successWrapper = function (peripheral) {
convertToNativeJS(peripheral);
success(peripheral);
};
cordova.exec(successWrapper, failure, 'BLE', 'connect', [device_id]);
cordova.exec(successWrapper, failure, 'BLE', 'connect', [device_id]);
},

@@ -127,3 +126,3 @@

// wrap connectCallback so nested array buffers in advertising info are handled correctly
var connectCallbackWrapper = function(peripheral) {
var connectCallbackWrapper = function (peripheral) {
convertToNativeJS(peripheral);

@@ -133,8 +132,8 @@ connectCallback(peripheral);

// iOS needs to reconnect on disconnect, unless ble.disconnect was called.
// iOS needs to reconnect on disconnect, unless ble.disconnect was called.
if (cordova.platformId === 'ios') {
disconnectCallbackWrapper = function(peripheral) {
disconnectCallbackWrapper = function (peripheral) {
// let the app know the peripheral disconnected
disconnectCallback(peripheral);
// reconnect if we have a peripheral.id and the user didn't call disconnect

@@ -144,5 +143,6 @@ if (peripheral.id && autoconnected[peripheral.id]) {

}
};
} else { // no wrapper for Android
disconnectCallbackWrapper = disconnectCallback;
};
} else {
// no wrapper for Android
disconnectCallbackWrapper = disconnectCallback;
}

@@ -156,3 +156,3 @@

delete autoconnected[device_id];
} catch(e) {
} catch (e) {
// ignore error

@@ -163,3 +163,3 @@ }

queueCleanup: function (device_id, success, failure) {
queueCleanup: function (device_id, success, failure) {
cordova.exec(success, failure, 'BLE', 'queueCleanup', [device_id]);

@@ -172,3 +172,3 @@ },

requestMtu: function (device_id, mtu, success, failure) {
requestMtu: function (device_id, mtu, success, failure) {
cordova.exec(success, failure, 'BLE', 'requestMtu', [device_id, mtu]);

@@ -178,7 +178,7 @@ },

requestConnectionPriority: function (device_id, connectionPriority, success, failure) {
cordova.exec(success, failure, 'BLE', 'requestConnectionPriority', [device_id, connectionPriority])
cordova.exec(success, failure, 'BLE', 'requestConnectionPriority', [device_id, connectionPriority]);
},
refreshDeviceCache: function(deviceId, timeoutMillis, success, failure) {
var successWrapper = function(peripheral) {
refreshDeviceCache: function (deviceId, timeoutMillis, success, failure) {
var successWrapper = function (peripheral) {
convertToNativeJS(peripheral);

@@ -196,3 +196,3 @@ success(peripheral);

// RSSI value comes back as an integer
readRSSI: function(device_id, success, failure) {
readRSSI: function (device_id, success, failure) {
cordova.exec(success, failure, 'BLE', 'readRSSI', [device_id]);

@@ -208,3 +208,8 @@ },

writeWithoutResponse: function (device_id, service_uuid, characteristic_uuid, value, success, failure) {
cordova.exec(success, failure, 'BLE', 'writeWithoutResponse', [device_id, service_uuid, characteristic_uuid, value]);
cordova.exec(success, failure, 'BLE', 'writeWithoutResponse', [
device_id,
service_uuid,
characteristic_uuid,
value,
]);
},

@@ -214,4 +219,9 @@

writeCommand: function (device_id, service_uuid, characteristic_uuid, value, success, failure) {
console.log("WARNING: writeCommand is deprecated, use writeWithoutResponse");
cordova.exec(success, failure, 'BLE', 'writeWithoutResponse', [device_id, service_uuid, characteristic_uuid, value]);
console.log('WARNING: writeCommand is deprecated, use writeWithoutResponse');
cordova.exec(success, failure, 'BLE', 'writeWithoutResponse', [
device_id,
service_uuid,
characteristic_uuid,
value,
]);
},

@@ -221,3 +231,3 @@

notify: function (device_id, service_uuid, characteristic_uuid, success, failure) {
console.log("WARNING: notify is deprecated, use startNotification");
console.log('WARNING: notify is deprecated, use startNotification');
cordova.exec(success, failure, 'BLE', 'startNotification', [device_id, service_uuid, characteristic_uuid]);

@@ -250,17 +260,28 @@ },

enable: function (success, failure) {
cordova.exec(success, failure, "BLE", "enable", []);
cordova.exec(success, failure, 'BLE', 'enable', []);
},
showBluetoothSettings: function (success, failure) {
cordova.exec(success, failure, "BLE", "showBluetoothSettings", []);
cordova.exec(success, failure, 'BLE', 'showBluetoothSettings', []);
},
startLocationStateNotifications: function (success, failure) {
cordova.exec(success, failure, "BLE", "startLocationStateNotifications", []);
},
stopLocationStateNotifications: function (success, failure) {
cordova.exec(success, failure, "BLE", "stopLocationStateNotifications", []);
},
startStateNotifications: function (success, failure) {
cordova.exec(success, failure, "BLE", "startStateNotifications", []);
cordova.exec(success, failure, 'BLE', 'startStateNotifications', []);
},
stopStateNotifications: function (success, failure) {
cordova.exec(success, failure, "BLE", "stopStateNotifications", []);
}
cordova.exec(success, failure, 'BLE', 'stopStateNotifications', []);
},
restoredBluetoothState: function (success, failure) {
cordova.exec(success, failure, 'BLE', 'restoredBluetoothState', []);
},
};

@@ -276,4 +297,4 @@

stopScan: function() {
return new Promise(function(resolve, reject) {
stopScan: function () {
return new Promise(function (resolve, reject) {
module.exports.stopScan(resolve, reject);

@@ -283,4 +304,4 @@ });

disconnect: function(device_id) {
return new Promise(function(resolve, reject) {
disconnect: function (device_id) {
return new Promise(function (resolve, reject) {
module.exports.disconnect(device_id, resolve, reject);

@@ -290,4 +311,4 @@ });

queueCleanup: function(device_id) {
return new Promise(function(resolve, reject) {
queueCleanup: function (device_id) {
return new Promise(function (resolve, reject) {
module.exports.queueCleanup(device_id, resolve, reject);

@@ -303,4 +324,4 @@ });

read: function(device_id, service_uuid, characteristic_uuid) {
return new Promise(function(resolve, reject) {
read: function (device_id, service_uuid, characteristic_uuid) {
return new Promise(function (resolve, reject) {
module.exports.read(device_id, service_uuid, characteristic_uuid, resolve, reject);

@@ -310,4 +331,4 @@ });

write: function(device_id, service_uuid, characteristic_uuid, value) {
return new Promise(function(resolve, reject) {
write: function (device_id, service_uuid, characteristic_uuid, value) {
return new Promise(function (resolve, reject) {
module.exports.write(device_id, service_uuid, characteristic_uuid, value, resolve, reject);

@@ -318,3 +339,3 @@ });

writeWithoutResponse: function (device_id, service_uuid, characteristic_uuid, value) {
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
module.exports.writeWithoutResponse(device_id, service_uuid, characteristic_uuid, value, resolve, reject);

@@ -325,3 +346,3 @@ });

stopNotification: function (device_id, service_uuid, characteristic_uuid) {
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
module.exports.stopNotification(device_id, service_uuid, characteristic_uuid, resolve, reject);

@@ -332,3 +353,3 @@ });

isConnected: function (device_id) {
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
module.exports.isConnected(device_id, resolve, reject);

@@ -339,3 +360,3 @@ });

isEnabled: function () {
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
module.exports.isEnabled(resolve, reject);

@@ -346,3 +367,3 @@ });

enable: function () {
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
module.exports.enable(resolve, reject);

@@ -353,3 +374,3 @@ });

showBluetoothSettings: function () {
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
module.exports.showBluetoothSettings(resolve, reject);

@@ -360,3 +381,3 @@ });

stopStateNotifications: function () {
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
module.exports.stopStateNotifications(resolve, reject);

@@ -366,7 +387,19 @@ });

readRSSI: function(device_id) {
return new Promise(function(resolve, reject) {
stopLocationStateNotifications: function () {
return new Promise(function(resolve, reject) {
module.exports.stopLocationStateNotifications(resolve, reject);
});
},
readRSSI: function (device_id) {
return new Promise(function (resolve, reject) {
module.exports.readRSSI(device_id, resolve, reject);
});
}
},
restoredBluetoothState: function () {
return new Promise(function (resolve, reject) {
module.exports.restoredBluetoothState(resolve, reject);
});
},
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc