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.4-alpha.3 to 1.4.4

7

CHANGES.txt

@@ -0,1 +1,8 @@

= 1.4.4 =
Browser: Add support via navigator.Bluetooth #907 #231 Thanks joeferner
iOS: More explicitly handle edge cases when starting/stopping notifications on iOS #577 #893
iOS: Improve ble.write handling when given non-ArrayBuffer types #897 #900
Android: Report peripherals as disconnected when BLE is turned off #894 #896
Android: Properly dispose of connected gatts on plugin reset #825 #845
= 1.4.3 =

@@ -2,0 +9,0 @@ iOS: Make BLUETOOTH_RESTORE_STATE variable optional

2

package.json
{
"name": "cordova-plugin-ble-central",
"version": "1.4.4-alpha.3",
"version": "1.4.4",
"description": "Bluetooth Low Energy (BLE) Central Plugin",

@@ -5,0 +5,0 @@ "cordova": {

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

* Scan for peripherals
* Connect to a peripheral
* Read the value of a characteristic
* Write new value to a characteristic
* Get notified when characteristic's value changes
- Scan for peripherals
- Connect to a peripheral
- Read the value of a characteristic
- Write new value to a characteristic
- Get notified when characteristic's value changes

@@ -27,4 +27,5 @@ Advertising information is returned when scanning for peripherals.

* iOS
* Android (4.3 or greater)
- iOS
- Android (4.3 or greater)
- Browser (where navigator.bluetooth is supported)

@@ -82,29 +83,32 @@ # Installing

- [ble.scan](#scan)
- [ble.startScan](#startscan)
- [ble.startScanWithOptions](#startscanwithoptions)
- [ble.stopScan](#stopscan)
- [ble.setPin](#setpin)
- [ble.connect](#connect)
- [ble.autoConnect](#autoconnect)
- [ble.disconnect](#disconnect)
- [ble.requestMtu](#requestmtu)
- [ble.requestConnectionPriority](#requestconnectionpriority)
- [ble.read](#read)
- [ble.write](#write)
- [ble.writeWithoutResponse](#writewithoutresponse)
- [ble.startNotification](#startnotification)
- [ble.stopNotification](#stopnotification)
- [ble.isEnabled](#isenabled)
- [ble.isLocationEnabled](#islocationenabled)
- [ble.isConnected](#isconnected)
- [ble.startStateNotifications](#startstatenotifications)
- [ble.stopStateNotifications](#stopstatenotifications)
- [ble.showBluetoothSettings](#showbluetoothsettings)
- [ble.enable](#enable)
- [ble.readRSSI](#readrssi)
- [ble.connectedPeripheralsWithServices](#connectedperipheralswithservices)
- [ble.peripheralsWithIdentifiers](#peripheralswithidentifiers)
- [ble.restoredBluetoothState](#restoredbluetoothstate)
- [ble.bondedDevices](#bondeddevices)
- [ble.scan](#scan)
- [ble.startScan](#startscan)
- [ble.startScanWithOptions](#startscanwithoptions)
- [ble.stopScan](#stopscan)
- [ble.setPin](#setpin)
- [ble.connect](#connect)
- [ble.autoConnect](#autoconnect)
- [ble.disconnect](#disconnect)
- [ble.requestMtu](#requestmtu)
- [ble.requestConnectionPriority](#requestconnectionpriority)
- [ble.refreshDeviceCache](#refreshdevicecache)
- [ble.read](#read)
- [ble.write](#write)
- [ble.writeWithoutResponse](#writewithoutresponse)
- [ble.startNotification](#startnotification)
- [ble.stopNotification](#stopnotification)
- [ble.isConnected](#isconnected)
- [ble.isEnabled](#isenabled)
- [ble.isLocationEnabled](#islocationenabled)
- [ble.startLocationStateNotifications](#startlocationstatenotifications)
- [ble.stopLocationStateNotifications](#stoplocationstatenotifications)
- [ble.startStateNotifications](#startstatenotifications)
- [ble.stopStateNotifications](#stopstatenotifications)
- [ble.showBluetoothSettings](#showbluetoothsettings)
- [ble.enable](#enable)
- [ble.readRSSI](#readrssi)
- [ble.connectedPeripheralsWithServices](#connectedperipheralswithservices)
- [ble.peripheralsWithIdentifiers](#peripheralswithidentifiers)
- [ble.restoredBluetoothState](#restoredbluetoothstate)
- [ble.bondedDevices](#bondeddevices)

@@ -119,3 +123,3 @@ ## scan

Function `scan` scans for BLE devices. The success callback is called each time a peripheral is discovered. Scanning automatically stops after the specified number of seconds.
Function `scan` scans for BLE devices. The success callback is called each time a peripheral is discovered. Scanning automatically stops after the specified number of seconds.

@@ -132,2 +136,3 @@ {

### Location Permission Notes
With Android SDK >= 23 (6.0), additional permissions are required for Bluetooth low energy scanning. The location permission [ACCESS_COARSE_LOCATION](https://developer.android.com/reference/android/Manifest.permission.html#ACCESS_COARSE_LOCATION) is required because Bluetooth beacons can be used to determine a user's location. If necessary, the plugin will prompt the user to allow the app to access to device's location. If the user denies permission, the scan failure callback will receive the error "Location permission not granted".

@@ -139,6 +144,6 @@

- __services__: List of services to discover, or [] to find all devices
- __seconds__: Number of seconds to run discovery
- __success__: Success callback function that is invoked which each discovered device.
- __failure__: Error callback function, invoked when error occurs. [optional]
- **services**: List of services to discover, or [] to find all devices
- **seconds**: Number of seconds to run discovery
- **success**: Success callback function that is invoked which each discovered device.
- **failure**: Error callback function, invoked when error occurs. [optional]

@@ -159,3 +164,3 @@ ### Quick Example

Function `startScan` scans for BLE devices. The success callback is called each time a peripheral is discovered. Scanning will continue until `stopScan` is called.
Function `startScan` scans for BLE devices. The success callback is called each time a peripheral is discovered. Scanning will continue until `stopScan` is called.

@@ -175,5 +180,5 @@ {

- __services__: List of services to discover, or [] to find all devices
- __success__: Success callback function that is invoked which each discovered device.
- __failure__: Error callback function, invoked when error occurs. [optional]
- **services**: List of services to discover, or [] to find all devices
- **success**: Success callback function that is invoked which each discovered device.
- **failure**: Error callback function, invoked when error occurs. [optional]

@@ -200,3 +205,3 @@ ### Quick Example

Function `startScanWithOptions` scans for BLE devices. It operates similarly to the `startScan` function, but allows you to specify extra options (like allowing duplicate device reports). The success callback is called each time a peripheral is discovered. Scanning will continue until `stopScan` is called.
Function `startScanWithOptions` scans for BLE devices. It operates similarly to the `startScan` function, but allows you to specify extra options (like allowing duplicate device reports). The success callback is called each time a peripheral is discovered. Scanning will continue until `stopScan` is called.

@@ -216,19 +221,19 @@ {

- __services__: List of services to discover, or [] to find all devices
- __options__: an object specifying a set of name-value pairs. The currently acceptable options are:
* _reportDuplicates_: _true_ if duplicate devices should be reported, _false_ (default) if devices should only be reported once. [optional]
* _scanMode_: String defines [setScanMode()](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setscanmode) argument on Android.
Can be one of: _lowPower_ | _balanced_ | _lowLatency_ | _opportunistic_
* _callbackType_: String defines [setCallbackType()](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setcallbacktype) argument on Android.
Can be one of: _all_ | _first_ | _lost_
* _matchMode_: String defines [setMatchMode()](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setmatchmode) argument on Android.
Can be one of: _aggressive_ | _sticky_
* _numOfMatches_: String defines [setNumOfMatches()](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setnumofmatches) argument on Android.
Can be one of: _one_ | _few_ | _max_
* _phy_: String for [setPhy()](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setphy) on Android.
Can be one of: _1m_ | _coded_ | _all_
* _legacy_: _true_ or _false_ to [control filtering](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setlegacy) bluetooth spec.pre-4.2 advertisements on Android.
* _reportDelay_: Milliseconds for [setReportDelay()](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setreportdelay) on Android. _0_ to be notified of results immediately. Values > _0_ causes the scan results to be queued up and delivered after the requested delay or when the internal buffers fill up.
- __success__: Success callback function that is invoked which each discovered device.
- __failure__: Error callback function, invoked when error occurs. [optional]
- **services**: List of services to discover, or [] to find all devices
- **options**: an object specifying a set of name-value pairs. The currently acceptable options are:
- _reportDuplicates_: _true_ if duplicate devices should be reported, _false_ (default) if devices should only be reported once. [optional]
- _scanMode_: String defines [setScanMode()](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setscanmode) argument on Android.
Can be one of: _lowPower_ | _balanced_ | _lowLatency_ | _opportunistic_
- _callbackType_: String defines [setCallbackType()](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setcallbacktype) argument on Android.
Can be one of: _all_ | _first_ | _lost_
- _matchMode_: String defines [setMatchMode()](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setmatchmode) argument on Android.
Can be one of: _aggressive_ | _sticky_
- _numOfMatches_: String defines [setNumOfMatches()](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setnumofmatches) argument on Android.
Can be one of: _one_ | _few_ | _max_
- _phy_: String for [setPhy()](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setphy) on Android.
Can be one of: _1m_ | _coded_ | _all_
- _legacy_: _true_ or _false_ to [control filtering](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setlegacy) bluetooth spec.pre-4.2 advertisements on Android.
- _reportDelay_: Milliseconds for [setReportDelay()](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setreportdelay) on Android. _0_ to be notified of results immediately. Values > _0_ causes the scan results to be queued up and delivered after the requested delay or when the internal buffers fill up.
- **success**: Success callback function that is invoked which each discovered device.
- **failure**: Error callback function, invoked when error occurs. [optional]

@@ -250,3 +255,2 @@ ### Quick Example

## stopScan

@@ -264,4 +268,4 @@

- __success__: Success callback function, invoked when scanning is stopped. [optional]
- __failure__: Error callback function, invoked when error occurs. [optional]
- **success**: Success callback function, invoked when scanning is stopped. [optional]
- **failure**: Error callback function, invoked when error occurs. [optional]

@@ -301,5 +305,5 @@ ### Quick Example

- __pin__: Pin of the device as a string
- __success__: Success callback function that is invoked when the function is invoked. [optional]
- __failure__: Error callback function, invoked when error occurs. [optional]
- **pin**: Pin of the device as a string
- **success**: Success callback function that is invoked when the function is invoked. [optional]
- **failure**: Error callback function, invoked when error occurs. [optional]

@@ -314,3 +318,3 @@ ## connect

Function `connect` connects to a BLE peripheral. The callback is long running. The connect callback will be called when the connection is successful. Service and characteristic info will be passed to the connect callback in the [peripheral object](#peripheral-data).
Function `connect` connects to a BLE peripheral. The callback is long running. The connect callback will be called when the connection is successful. Service and characteristic info will be passed to the connect callback in the [peripheral object](#peripheral-data).

@@ -327,5 +331,5 @@ The disconnect callback is called if the connection fails, or later if the peripheral disconnects. When possible, a peripheral object is passed to the failure callback. The disconnect callback is only called when the peripheral initates the disconnection. The disconnect callback is not called when the application calls [ble.disconnect](#disconnect). The disconnect callback is how your app knows the peripheral inintiated a disconnect.

- __device_id__: UUID or MAC address of the peripheral
- __connectCallback__: Connect callback function that is invoked when the connection is successful.
- __disconnectCallback__: Disconnect callback function, invoked when the peripheral disconnects or an error occurs.
- **device_id**: UUID or MAC address of the peripheral
- **connectCallback**: Connect callback function that is invoked when the connection is successful.
- **disconnectCallback**: Disconnect callback function, invoked when the peripheral disconnects or an error occurs.

@@ -344,3 +348,3 @@ ## autoConnect

Both the connect and disconnect callbacks can be called many times as the device connects and disconnects. Do not wrap this function in a Promise or Observable.
Both the connect and disconnect callbacks can be called many times as the device connects and disconnects. Do not wrap this function in a Promise or Observable.

@@ -353,5 +357,5 @@ On iOS, [background notifications on ios](#background-notifications-on-ios) must be enabled if you want to run in the background. On Android, this relies on the autoConnect argument of `BluetoothDevice.connectGatt()`. Not all Android devices implement this feature correctly.

- __device_id__: UUID or MAC address of the peripheral
- __connectCallback__: Connect callback function that is invoked when the connection is successful.
- __disconnectCallback__: Disconnect callback function, invoked when the peripheral disconnects or an error occurs.
- **device_id**: UUID or MAC address of the peripheral
- **connectCallback**: Connect callback function that is invoked when the connection is successful.
- **disconnectCallback**: Disconnect callback function, invoked when the peripheral disconnects or an error occurs.

@@ -370,5 +374,5 @@ ## disconnect

- __device_id__: UUID or MAC address of the peripheral
- __success__: Success callback function that is invoked when the connection is successful. [optional]
- __failure__: Error callback function, invoked when error occurs. [optional]
- **device_id**: UUID or MAC address of the peripheral
- **success**: Success callback function that is invoked when the connection is successful. [optional]
- **failure**: Error callback function, invoked when error occurs. [optional]

@@ -389,10 +393,10 @@ ## requestMtu

* Android
- Android
### Parameters
- __device_id__: UUID or MAC address of the peripheral
- __mtu__: MTU size
- __success__: Success callback function that is invoked when the MTU size request is successful. The resulting MTU size is passed as an integer.
- __failure__: Error callback function, invoked when error occurs. [optional]
- **device_id**: UUID or MAC address of the peripheral
- **mtu**: MTU size
- **success**: Success callback function that is invoked when the MTU size request is successful. The resulting MTU size is passed as an integer.
- **failure**: Error callback function, invoked when error occurs. [optional]

@@ -418,11 +422,21 @@ ### Quick Example

When Connecting to a peripheral android can request for the connection priority for better communication. See [BluetoothGatt#requestConnectionPriority](https://developer.android.com/reference/android/bluetooth/BluetoothGatt#requestConnectionPriority(int)) for technical details
When Connecting to a peripheral android can request for the connection priority for better communication. See [BluetoothGatt#requestConnectionPriority](<https://developer.android.com/reference/android/bluetooth/BluetoothGatt#requestConnectionPriority(int)>) for technical details
Connection priority can be one of:
- `0` - [CONNECTION_PRIORITY_BALANCED](https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_BALANCED)
- `1` - [CONNECTION_PRIORITY_HIGH](https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_HIGH)
- `2` - [CONNECTION_PRIORITY_LOW_POWER](https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_LOW_POWER)
- `0` - [CONNECTION_PRIORITY_BALANCED](https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_BALANCED)
- `1` - [CONNECTION_PRIORITY_HIGH](https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_HIGH)
- `2` - [CONNECTION_PRIORITY_LOW_POWER](https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_LOW_POWER)
### Supported Platforms
- Android
### Parameters
- **device_id**: UUID or MAC address of the peripheral
- **priority**: high or balanced or low
- **success**: Success callback function that is invoked when the connection is successful. [optional]
- **failure**: Error callback function, invoked when error occurs. [optional]
### Quick Example

@@ -439,13 +453,2 @@

### Supported Platforms
* Android
### Parameters
- __device_id__: UUID or MAC address of the peripheral
- __priority__: high or balanced or low
- __success__: Success callback function that is invoked when the connection is successful. [optional]
- __failure__: Error callback function, invoked when error occurs. [optional]
## refreshDeviceCache

@@ -460,17 +463,17 @@

Some poorly behaved devices show old cached services and characteristics info. (Usually because they
don't implement Service Changed 0x2a05 on Generic Attribute Service 0x1801 and the central doesn't know
don't implement Service Changed 0x2a05 on Generic Attribute Service 0x1801 and the central doesn't know
the data needs to be refreshed.) This method might help.
*NOTE* Since this uses an undocumented API it's not guaranteed to work.
_NOTE_ Since this uses an undocumented API it's not guaranteed to work.
### Supported Platforms
* Android
- Android
### Parameters
- __deviceId__: UUID or MAC address of the peripheral
- __timeoutMillis__: timeout in milliseconds after refresh before discovering services
- __success__: Success callback function invoked with the refreshed peripheral. [optional]
- __failure__: Error callback function, invoked when an error occurs. [optional]
- **deviceId**: UUID or MAC address of the peripheral
- **timeoutMillis**: timeout in milliseconds after refresh before discovering services
- **success**: Success callback function invoked with the refreshed peripheral. [optional]
- **failure**: Error callback function, invoked when an error occurs. [optional]

@@ -491,7 +494,7 @@ ## read

- __device_id__: UUID or MAC address of the peripheral
- __service_uuid__: UUID of the BLE service
- __characteristic_uuid__: UUID of the BLE characteristic
- __success__: Success callback function that is invoked when the connection is successful. [optional]
- __failure__: Error callback function, invoked when error occurs. [optional]
- **device_id**: UUID or MAC address of the peripheral
- **service_uuid**: UUID of the BLE service
- **characteristic_uuid**: UUID of the BLE characteristic
- **success**: Success callback function that is invoked when the connection is successful. [optional]
- **failure**: Error callback function, invoked when error occurs. [optional]

@@ -524,9 +527,10 @@ ### Quick Example

### Parameters
- __device_id__: UUID or MAC address of the peripheral
- __service_uuid__: UUID of the BLE service
- __characteristic_uuid__: UUID of the BLE characteristic
- __data__: binary data, use an [ArrayBuffer](#typed-arrays)
- __success__: Success callback function that is invoked when the connection is successful. [optional]
- __failure__: Error callback function, invoked when error occurs. [optional]
- **device_id**: UUID or MAC address of the peripheral
- **service_uuid**: UUID of the BLE service
- **characteristic_uuid**: UUID of the BLE characteristic
- **data**: binary data, use an [ArrayBuffer](#typed-arrays)
- **success**: Success callback function that is invoked when the connection is successful. [optional]
- **failure**: Error callback function, invoked when error occurs. [optional]
### Quick Example

@@ -564,9 +568,10 @@

### Parameters
- __device_id__: UUID or MAC address of the peripheral
- __service_uuid__: UUID of the BLE service
- __characteristic_uuid__: UUID of the BLE characteristic
- __data__: binary data, use an [ArrayBuffer](#typed-arrays)
- __success__: Success callback function that is invoked when the connection is successful. [optional]
- __failure__: Error callback function, invoked when error occurs. [optional]
- **device_id**: UUID or MAC address of the peripheral
- **service_uuid**: UUID of the BLE service
- **characteristic_uuid**: UUID of the BLE characteristic
- **data**: binary data, use an [ArrayBuffer](#typed-arrays)
- **success**: Success callback function that is invoked when the connection is successful. [optional]
- **failure**: Error callback function, invoked when error occurs. [optional]
## startNotification

@@ -580,3 +585,3 @@

Function `startNotification` registers a callback that is called *every time* the value of a characteristic changes. This method handles both `notifications` and `indications`. The success callback is called multiple times.
Function `startNotification` registers a callback that is called _every time_ the value of a characteristic changes. This method handles both `notifications` and `indications`. The success callback is called multiple times.

@@ -589,7 +594,7 @@ Raw data is passed from native code to the success callback as an [ArrayBuffer](#typed-arrays).

- __device_id__: UUID or MAC address of the peripheral
- __service_uuid__: UUID of the BLE service
- __characteristic_uuid__: UUID of the BLE characteristic
- __success__: Success callback function invoked every time a notification occurs
- __failure__: Error callback function, invoked when error occurs. [optional]
- **device_id**: UUID or MAC address of the peripheral
- **service_uuid**: UUID of the BLE service
- **characteristic_uuid**: UUID of the BLE characteristic
- **success**: Success callback function invoked every time a notification occurs
- **failure**: Error callback function, invoked when error occurs. [optional]

@@ -618,7 +623,7 @@ ### Quick Example

- __device_id__: UUID or MAC address of the peripheral
- __service_uuid__: UUID of the BLE service
- __characteristic_uuid__: UUID of the BLE characteristic
- __success__: Success callback function that is invoked when the notification is removed. [optional]
- __failure__: Error callback function, invoked when error occurs. [optional]
- **device_id**: UUID or MAC address of the peripheral
- **service_uuid**: UUID of the BLE service
- **characteristic_uuid**: UUID of the BLE characteristic
- **success**: Success callback function that is invoked when the notification is removed. [optional]
- **failure**: Error callback function, invoked when error occurs. [optional]

@@ -633,3 +638,3 @@ ## isConnected

Function `isConnected` calls the success callback when the peripheral is connected and the failure callback when *not* connected.
Function `isConnected` calls the success callback when the peripheral is connected and the failure callback when _not_ connected.

@@ -640,5 +645,5 @@ NOTE that for many apps isConnected is unncessary. The app can track the connected state. Ater calling [connect](#connect) the app is connected when the success callback function is called. If the device disconnects at any point in the future, the failure callback of connect will be called.

- __device_id__: UUID or MAC address of the peripheral
- __success__: Success callback function that is invoked with a boolean for connected status.
- __failure__: Error callback function, invoked when error occurs. [optional]
- **device_id**: UUID or MAC address of the peripheral
- **success**: Success callback function that is invoked with a boolean for connected status.
- **failure**: Error callback function, invoked when error occurs. [optional]

@@ -665,8 +670,8 @@ ### Quick Example

Function `isEnabled` calls the success callback when Bluetooth is enabled and the failure callback when Bluetooth is *not* enabled.
Function `isEnabled` calls the success callback when Bluetooth is enabled and the failure callback when Bluetooth is _not_ enabled.
### Parameters
- __success__: Success callback function, invoked when Bluetooth is enabled.
- __failure__: Error callback function, invoked when Bluetooth is disabled.
- **success**: Success callback function, invoked when Bluetooth is enabled.
- **failure**: Error callback function, invoked when Bluetooth is disabled.

@@ -684,3 +689,2 @@ ### Quick Example

## isLocationEnabled

@@ -694,16 +698,16 @@

Function `isLocationEnabled` calls the success callback when location services are enabled and the failure callback when location services are *not* enabled. On some devices, location services must be enabled in order to scan for peripherals.
Function `isLocationEnabled` calls the success callback when location services are enabled and the failure callback when location services are _not_ enabled. On some devices, location services must be enabled in order to scan for peripherals.
### Supported Platforms
* Android
- Android
### Parameters
- __success__: Success callback function, invoked when location services are enabled.
- __failure__: Error callback function, invoked when location services are disabled.
- **success**: Success callback function, invoked when location services are enabled.
- **failure**: Error callback function, invoked when location services are disabled.
### Quick Example
ble.isEnabled(
ble.isLocationEnabled(
function() {

@@ -729,8 +733,8 @@ console.log("location services are enabled");

* Android
- 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]
- **success**: Success callback function that is invoked with a boolean for the Location state.
- **failure**: Error callback function, invoked when error occurs. [optional]

@@ -757,3 +761,3 @@ ### Quick Example

* Android
- Android

@@ -770,17 +774,22 @@ ## startStateNotifications

__States__
**States**
- "on"
- "off"
- "turningOn" (Android Only)
- "turningOff" (Android Only)
- "unknown" (iOS Only)
- "resetting" (iOS Only)
- "unsupported" (iOS Only)
- "unauthorized" (iOS Only)
- "on"
- "off"
- "turningOn" (Android Only)
- "turningOff" (Android Only)
- "unknown" (iOS Only)
- "resetting" (iOS Only)
- "unsupported" (iOS Only)
- "unauthorized" (iOS Only)
### Supported Platforms
- Android
- iOS
### Parameters
- __success__: Success callback function that is invoked with a string for the Bluetooth state.
- __failure__: Error callback function, invoked when error occurs. [optional]
- **success**: Success callback function that is invoked with a string for the Bluetooth state.
- **failure**: Error callback function, invoked when error occurs. [optional]

@@ -805,2 +814,7 @@ ### Quick Example

### Supported Platforms
- Android
- iOS
## showBluetoothSettings

@@ -820,8 +834,8 @@

* Android
- Android
### Parameters
- __success__: Success callback function [optional]
- __failure__: Error callback function, invoked when error occurs. [optional]
- **success**: Success callback function [optional]
- **failure**: Error callback function, invoked when error occurs. [optional]

@@ -842,4 +856,2 @@ ### Quick Example

#### Android
`enable` is only supported on Android and does not work on iOS.

@@ -849,6 +861,10 @@

### Supported Platforms
- Android
### Parameters
- __success__: Success callback function, invoked if the user enabled Bluetooth.
- __failure__: Error callback function, invoked if the user does not enabled Bluetooth.
- **success**: Success callback function, invoked if the user enabled Bluetooth.
- **failure**: Error callback function, invoked if the user does not enabled Bluetooth.

@@ -878,7 +894,8 @@ ### Quick Example

- __device_id__: device identifier
- __success__: Success callback function, invoked with the RSSI value (as an integer)
- __failure__: Error callback function, invoked if there is no current connection or if there is an error reading the RSSI.
- **device_id**: device identifier
- **success**: Success callback function, invoked with the RSSI value (as an integer)
- **failure**: Error callback function, invoked if there is no current connection or if there is an error reading the RSSI.
### Quick Example
var rssiSample;

@@ -909,11 +926,11 @@ ble.connect(device_id,

### Parameters
### Supported Platforms
- __services__: List of services to discover
- __success__: Success callback function, invoked with a list of peripheral objects
- __failure__: Error callback function
- iOS
### Supported Platforms
### Parameters
* iOS
- **services**: List of services to discover
- **success**: Success callback function, invoked with a list of peripheral objects
- **failure**: Error callback function

@@ -930,11 +947,11 @@ ## peripheralsWithIdentifiers

### Parameters
### Supported Platforms
- __identifiers__: List of peripheral UUIDs
- __success__: Success callback function, invoked with a list of peripheral objects
- __failure__: Error callback function
- iOS
### Supported Platforms
### Parameters
* iOS
- **identifiers**: List of peripheral UUIDs
- **success**: Success callback function, invoked with a list of peripheral objects
- **failure**: Error callback function

@@ -956,10 +973,10 @@ ## restoredBluetoothState

### Parameters
### Supported Platforms
- __success__: Success callback function, invoked with the restored Bluetooth state (if any)
- __failure__: Error callback function
- iOS
### Supported Platforms
### Parameters
* iOS
- **success**: Success callback function, invoked with the restored Bluetooth state (if any)
- **failure**: Error callback function

@@ -976,12 +993,11 @@ ## bondedDevices

### Parameters
### Supported Platforms
- __success__: Success callback function, invoked with a list of peripheral objects
- __failure__: Error callback function
- Android
### Supported Platforms
### Parameters
* Android
- **success**: Success callback function, invoked with a list of peripheral objects
- **failure**: Error callback function
# Peripheral Data

@@ -1050,3 +1066,2 @@

# Advertising Data

@@ -1083,3 +1098,3 @@

"721b"
],
],
"kCBAdvDataIsConnectable": true,

@@ -1109,2 +1124,11 @@ "kCBAdvDataServiceData": {

## Browser
### Chrome
Enable: chrome://flags/#enable-experimental-web-platform-features and
chrome://flags/#enable-web-bluetooth-new-permissions-backend
Scan must be initiated from a user action (click, touch, etc).
# Typed Arrays

@@ -1204,6 +1228,6 @@

* [cordova-plugin-ble-peripheral](https://github.com/don/cordova-plugin-ble-peripheral) - Create and publish Bluetooth LE services on iOS and Android using Javascript.
* [BluetoothSerial](https://github.com/don/BluetoothSerial) - Connect to Arduino and other devices. Bluetooth Classic on Android, BLE on iOS.
* [RFduino](https://github.com/don/cordova-plugin-rfduino) - RFduino specific plugin for iOS and Android.
* [BluetoothLE](https://github.com/randdusing/BluetoothLE) - Rand Dusing's BLE plugin for Cordova
* [PhoneGap Bluetooth Plugin](https://github.com/tanelih/phonegap-bluetooth-plugin) - Bluetooth classic pairing and connecting for Android
- [cordova-plugin-ble-peripheral](https://github.com/don/cordova-plugin-ble-peripheral) - Create and publish Bluetooth LE services on iOS and Android using Javascript.
- [BluetoothSerial](https://github.com/don/BluetoothSerial) - Connect to Arduino and other devices. Bluetooth Classic on Android, BLE on iOS.
- [RFduino](https://github.com/don/cordova-plugin-rfduino) - RFduino specific plugin for iOS and Android.
- [BluetoothLE](https://github.com/randdusing/BluetoothLE) - Rand Dusing's BLE plugin for Cordova
- [PhoneGap Bluetooth Plugin](https://github.com/tanelih/phonegap-bluetooth-plugin) - Bluetooth classic pairing and connecting for Android

@@ -0,1 +1,2 @@

function notSupported() {

@@ -5,75 +6,204 @@ console.log('BLE is not supported on the browser');

function formatUUID(uuid) {
if (uuid.startsWith('0x')) {
return parseInt(uuid);
}
if (/^[0-9a-fA-F]+$/.test(uuid)) {
return parseInt(uuid, 16);
}
return uuid;
}
module.exports = {
deviceInfos: new Map(),
scan: function(services, seconds, success, failure) {
notSupported();
if (failure) failure();
return this.startScanWithOptions(services, {}, success, failure);
},
startScan: function(services, success, failure) {
notSupported();
if (failure) failure();
return this.startScanWithOptions(services, {}, success, failure);
},
startScanWithOptions: function(services, options, success, failure) {
if (!navigator.bluetooth) {
failure('Bluetooth is not supported on this browser.');
return;
}
let requestDeviceOptions = {};
if (services && services.length) {
requestDeviceOptions.filters = [{
services: services.map(formatUUID)
}];
} else {
requestDeviceOptions.acceptAllDevices = true;
}
navigator.bluetooth.requestDevice(requestDeviceOptions).then(device => {
var deviceInfo = this.deviceInfos.get(device.id) || {};
deviceInfo.device = device;
this.deviceInfos.set(device.id, deviceInfo);
success({ id: device.id });
}).catch(failure);
},
stopScan: function(success, failure) {
notSupported();
if (failure) failure();
if (success) success();
},
startScanWithOptions: function(services, options, success, failure) {
notSupported();
if (failure) failure();
connect: function(deviceId, success, failure) {
const connectGatt = (gatt) => {
return gatt.connect().then(server => {
this.deviceInfos.set(deviceId, {
device: deviceInfo,
server: server
})
success();
}).catch(err => {
if (failure) failure(err);
});
};
const deviceInfo = this.deviceInfos.get(deviceId);
if (!deviceInfo) {
return navigator.bluetooth.getDevices().then(devices => {
for (const device of devices) {
if (device.id === deviceId) {
return connectGatt(device.gatt);
}
}
if (failure) failure(new Error('device not found'));
});
}
if (deviceInfo.server) {
success();
} else {
return connectGatt(deviceInfo.device.gatt);
}
},
connect: function(device_id, connectSuccess, connectFailure) {
notSupported();
if (connectFailure) connectFailure();
disconnect: function(deviceId, success, failure) {
var deviceInfo = this.deviceInfos.get(deviceId)
if (deviceInfo) {
var device = deviceInfo.server && deviceInfo.server.device;
if (device && device.gatt.connected) {
device.gatt.disconnect();
success(device);
} else {
success();
}
} else if (failure) {
failure(new Error("Peripheral not found"));
}
},
disconnect: function(device_id, connectSuccess, connectFailure) {
notSupported();
if (connectFailure) connectFailure();
read: function(deviceId, service_uuid, characteristic_uuid, success, failure) {
if (this.deviceInfos.has(deviceId)) {
this.deviceInfos.get(deviceId).server.getPrimaryService(formatUUID(service_uuid)).then(service => {
return service.getCharacteristic(formatUUID(characteristic_uuid));
}).then(characteristic => {
return characteristic.readValue();
}).then(result => {
success(result);
}).catch(error => {
if (failure) failure(error);
});
} else if (failure) {
failure();
}
},
read: function(device_id, service_uuid, characteristic_uuid, success, failure) {
readRSSI: function(deviceId, success, failure) {
notSupported();
if (failure) failure();
if (failure) failure(new Error("not supported"));
},
readRSSI: function(device_id, success, failure) {
notSupported();
if (failure) failure();
write: function(deviceId, service_uuid, characteristic_uuid, data, success, failure) {
if (this.deviceInfos.has(deviceId)) {
this.deviceInfos.get(deviceId).server.getPrimaryService(formatUUID(service_uuid)).then(service => {
return service.getCharacteristic(formatUUID(characteristic_uuid));
}).then(characteristic => {
return characteristic.writeValueWithResponse(data);
}).then(result => {
success(result);
}).catch(error => {
if (failure) failure(error);
});
} else if (failure) {
failure(new Error("device not connected"));
}
},
write: function(device_id, service_uuid, characteristic_uuid, data, success, failure) {
notSupported();
if (failure) failure();
writeWithoutResponse: function(deviceId, service_uuid, characteristic_uuid, data, success, failure) {
if (this.deviceInfos.has(deviceId)) {
this.deviceInfos.get(deviceId).server.getPrimaryService(formatUUID(service_uuid)).then(service => {
return service.getCharacteristic(formatUUID(characteristic_uuid));
}).then(characteristic => {
return characteristic.writeWithoutResponse(data);
}).then(result => {
success(result);
}).catch(error => {
if (failure) failure(error);
});
} else if (failure) {
failure(new Error("device not connected"));
}
},
writeWithoutResponse: function(device_id, service_uuid, characteristic_uuid, data, success, failure) {
notSupported();
if (failure) failure();
startNotification: function(deviceId, service_uuid, characteristic_uuid, success, failure) {
if (this.deviceInfos.has(deviceId)) {
this.deviceInfos.get(deviceId).server.getPrimaryService(formatUUID(service_uuid)).then(service => {
return service.getCharacteristic(formatUUID(characteristic_uuid));
}).then(characteristic => {
return characteristic.startNotifications().then(result => {
characteristic.addEventListener('characteristicvaluechanged', function (event) {
success(event.target.value.buffer);
});
});
}).catch(error => {
if (failure) failure(error);
})
} else if (failure) {
failure(new Error("device not connected"));
}
},
startNotification: function(device_id, service_uuid, characteristic_uuid, success, failure) {
notSupported();
if (failure) failure();
stopNotifcation: function(deviceId, service_uuid, characteristic_uuid, success, failure) {
if (this.deviceInfos.has(deviceId)) {
this.deviceInfos.get(deviceId).server.getPrimaryService(formatUUID(service_uuid)).then(service => {
return service.getCharacteristic(formatUUID(characteristic_uuid));
}).then(characteristic => {
return characteristic.stopNotifications();
}).then(result => {
success(result);
}).catch(error => {
if (failure) failure(error);
});
} else if (failure) {
failure(new Error("device not connected"));
}
},
stopNotifcation: function(device_id, service_uuid, characteristic_uuid, success, failure) {
notSupported();
if (failure) failure();
},
isEnabled: function(success, failure) {
notSupported();
if (failure) failure();
if (failure) failure(new Error("not supported"));
},
isConnected: function(device_id, success, failure) {
notSupported();
if (failure) failure();
isConnected: function(deviceId, success, failure) {
if (this.deviceInfos.has(deviceId)) {
var device = this.deviceInfos.get(deviceId).server.device;
if (device.gatt.connected) {
success();
} else {
if (failure) failure();
}
} else if (failure) {
failure();
}
},
showBluetoothSettings: function(success, failure) {
notSupported();
if (failure) failure();
if (failure) failure(new Error("not supported"));
},
enable: function(success, failure) {
notSupported();
if (failure) failure();
if (failure) failure(new Error("not supported"));
},
startStateNotifications: function(success, failure) {
notSupported();
if (failure) failure();
notSupported();
if (failure) failure(new Error("not supported"));
},
stopStateNotifications: function(success, failure) {
notSupported();
if (failure) failure();
notSupported();
if (failure) failure(new Error("not supported"));
}
};
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