Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/3.3.0 #1262

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [3.3.0] - 2024-12-20

### Changed

- internal `_manager` property isn't enumerable anymore. This change will hide it from the `console.log`, `JSON.stringify` and other similar methods.
- `BleManager` is now a singleton. It will be created only once and reused across the app. This change will allow users to declare instance in React tree (hooks and components). This change should not affect the existing codebase, where `BleManager` is created once and used across the app.

### Fixed

- Timeout parameter in connect method on Android causing the connection to be closed after the timeout period even if connection was established.
- Missing `serviceUUIDs` data after `discoverAllServicesAndCharacteristics` method call

## [3.2.1] - 2024-07-9

### Changed
Expand Down
15 changes: 15 additions & 0 deletions android/src/main/java/com/bleplx/adapter/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

Expand Down Expand Up @@ -61,6 +62,20 @@ public List<Service> getServices() {
return services;
}

@Nullable
public List<UUID> getServicesUUIDs() {
if (services == null) {
return null;
}

List<UUID> servicesUUIDs = new ArrayList<>();
for (Service service : services) {
servicesUUIDs.add(service.getUuid());
}

return servicesUUIDs;
}

public void setServices(@Nullable List<Service> services) {
this.services = services;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package com.bleplx.converter;

import android.util.Log;

import com.bleplx.adapter.Device;
import com.bleplx.utils.ReadableArrayConverter;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.WritableMap;

import java.util.List;
import java.util.UUID;

public class DeviceToJsObjectConverter extends JSObjectConverter<Device> {

private interface Metadata {
Expand Down Expand Up @@ -39,10 +46,15 @@ public WritableMap toJSObject(Device value) {
result.putNull(Metadata.MTU);
}

if(value.getServices() != null) {
result.putArray(Metadata.SERVICE_UUIDS, ReadableArrayConverter.toReadableArray(value.getServicesUUIDs()));
} else {
result.putNull(Metadata.SERVICE_UUIDS);
}

// Advertisement data is not set
result.putNull(Metadata.MANUFACTURER_DATA);
result.putNull(Metadata.SERVICE_DATA);
result.putNull(Metadata.SERVICE_UUIDS);
result.putNull(Metadata.LOCAL_NAME);
result.putNull(Metadata.TX_POWER_LEVEL);
result.putNull(Metadata.SOLICITED_SERVICE_UUIDS);
Expand Down
15 changes: 15 additions & 0 deletions android/src/main/java/com/bleplx/utils/ReadableArrayConverter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.bleplx.utils;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.WritableArray;

import java.util.List;
import java.util.UUID;

public class ReadableArrayConverter {
public static String[] toStringArray(ReadableArray readableArray) {
Expand All @@ -10,4 +15,14 @@ public static String[] toStringArray(ReadableArray readableArray) {
}
return stringArray;
}

public static ReadableArray toReadableArray(List<UUID> uuids) {
WritableArray array = Arguments.createArray();

for (UUID uuid : uuids) {
array.pushString(uuid.toString());
}

return array;
}
}
13 changes: 7 additions & 6 deletions docs/GETTING_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
<a href="https://github.com/dotintent/react-native-ble-plx"><img style="max-height: 300px;" alt="react-native-ble-plx" src="logo.png" /></a>
</h1>

This guide is an introduction to BLE stack and APIs exported by this library. All examples
will be based on CC2541 SensorTag.
This guide is an introduction to BLE stack and APIs exported by this library. For further information you can refer to

- tutorials and API reference available in this documentation,
- [GitHub wiki](https://github.com/dotintent/react-native-ble-plx/wiki),
- example app available in the repository.

### Install and prepare package

Expand All @@ -15,7 +18,7 @@ In the case of react native CLI you need to configure two environments:

### Creating BLE Manager

First step is to create BleManager instance which is an entry point to all available APIs. It should be declared **OUTSIDE the life cycle of React**. Make sure to create it after application started its execution. We can keep it as a static reference by either creating our own abstraction (ex.1) or by simply creating a new instance (ex.2).
First step is to create BleManager instance which is an entry point to all available APIs. Make sure to create it after application started its execution. We can keep it as a static reference by either creating our own abstraction (ex.1) or by simply creating a new instance (ex.2).

#### Ex.1

Expand All @@ -42,9 +45,7 @@ import { BleManager } from 'react-native-ble-plx'
export const manager = new BleManager()
```

Only _one_ instance of BleManager is allowed. When you don't need any BLE functionality you can destroy created instance by calling `manager.destroy()` function. You can then recreate `BleManager` later on.

Note that you may experience undefined behavior when calling a function on one `BleManager` and continuing with another instance. A frequently made error is to create a new instance of the manager for every re-render of a React Native Component.
When you don't need any BLE functionality you can destroy created instance by calling `manager.destroy()` function. You can then recreate `BleManager` later on.

### Ask for permissions

Expand Down
35 changes: 19 additions & 16 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset='utf-8'>
<title>react-native-ble-plx 3.2.1 | Documentation</title>
<title>react-native-ble-plx 3.3.0 | Documentation</title>
<meta name='description' content='React Native Bluetooth Low Energy library'>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<link href='assets/bass.css' rel='stylesheet'>
Expand All @@ -15,7 +15,7 @@
<div id='split-left' class='overflow-auto fs0 height-viewport-100'>
<div class='py1 px2'>
<h3 class='mb0 no-anchor'>react-native-ble-plx</h3>
<div class='mb1'><code>3.2.1</code></div>
<div class='mb1'><code>3.3.0</code></div>
<input
placeholder='Filter'
id='filter-input'
Expand Down Expand Up @@ -1975,8 +1975,12 @@ <h2 id='getting-started' class='mt0'>
<h1 align="center" >
<a href="https://github.com/dotintent/react-native-ble-plx"><img style="max-height: 300px;" alt="react-native-ble-plx" src="logo.png" /></a>
</h1>
<p>This guide is an introduction to BLE stack and APIs exported by this library. All examples
will be based on CC2541 SensorTag.</p>
<p>This guide is an introduction to BLE stack and APIs exported by this library. For further information you can refer to</p>
<ul>
<li>tutorials and API reference available in this documentation,</li>
<li><a href="https://github.com/dotintent/react-native-ble-plx/wiki">GitHub wiki</a>,</li>
<li>example app available in the repository.</li>
</ul>
<h3>Install and prepare package</h3>
<p>In the case of Expo, you will need to prepare a plugin config, detailed information can be found here: <a href="https://github.com/dotintent/react-native-ble-plx?tab=readme-ov-file#expo-sdk-43">https://github.com/dotintent/react-native-ble-plx?tab=readme-ov-file#expo-sdk-43</a>
In the case of react native CLI you need to configure two environments:</p>
Expand All @@ -1985,13 +1989,13 @@ <h3>Install and prepare package</h3>
<li><a href="https://github.com/dotintent/react-native-ble-plx?tab=readme-ov-file#android-example-setup">Android</a></li>
</ul>
<h3>Creating BLE Manager</h3>
<p>First step is to create BleManager instance which is an entry point to all available APIs. It should be declared <strong>OUTSIDE the life cycle of React</strong>. Make sure to create it after application started its execution. We can keep it as a static reference by either creating our own abstraction (ex.1) or by simply creating a new instance (ex.2).</p>
<p>First step is to create BleManager instance which is an entry point to all available APIs. Make sure to create it after application started its execution. We can keep it as a static reference by either creating our own abstraction (ex.1) or by simply creating a new instance (ex.2).</p>
<h4>Ex.1</h4>
<pre class='hljs'><span class="hljs-keyword">import</span> { BleManager } <span class="hljs-keyword">from</span> <span class="hljs-string">'react-native-ble-plx'</span>

<span class="hljs-comment">// create your own singleton class</span>
<span class="hljs-keyword">class</span> BLEServiceInstance {
manager: BleManage
manager: BleManager

<span class="hljs-keyword">constructor</span>(<span class="hljs-params"></span>) {
<span class="hljs-keyword">this</span>.manager = <span class="hljs-keyword">new</span> BleManager()
Expand All @@ -2003,8 +2007,7 @@ <h4>Ex.2</h4>
<pre class='hljs'><span class="hljs-keyword">import</span> { BleManager } <span class="hljs-keyword">from</span> <span class="hljs-string">'react-native-ble-plx'</span>

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> manager = <span class="hljs-keyword">new</span> BleManager()</pre>
<p>Only <em>one</em> instance of BleManager is allowed. When you don't need any BLE functionality you can destroy created instance by calling <code>manager.destroy()</code> function. You can then recreate <code>BleManager</code> later on.</p>
<p>Note that you may experience undefined behavior when calling a function on one <code>BleManager</code> and continuing with another instance. A frequently made error is to create a new instance of the manager for every re-render of a React Native Component.</p>
<p>When you don't need any BLE functionality you can destroy created instance by calling <code>manager.destroy()</code> function. You can then recreate <code>BleManager</code> later on.</p>
<h3>Ask for permissions</h3>
<p>Check if you requested following permissions</p>
<ul>
Expand Down Expand Up @@ -2300,7 +2303,7 @@ <h3 class='fl m0' id='blemanager'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
<span class='code strong strong truncate'>destroy</span>
<span class='code strong strong truncate'>destroy()</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
Expand All @@ -2311,7 +2314,7 @@ <h3 class='fl m0' id='blemanager'>
<p>Destroys <a href="#blemanager">BleManager</a> instance. A new instance needs to be created to continue working with
this library. All operations which were in progress completes with</p>

<div class='pre p1 fill-light mt0'>destroy</div>
<div class='pre p1 fill-light mt0'>destroy(): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>&#x3C;void></div>



Expand Down Expand Up @@ -2724,7 +2727,7 @@ <h3 class='fl m0' id='blemanager'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
<span class='code strong strong truncate'>state</span>
<span class='code strong strong truncate'>state()</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
Expand All @@ -2735,7 +2738,7 @@ <h3 class='fl m0' id='blemanager'>
<p>Current, global <a href="#state">State</a> of a <a href="#blemanager">BleManager</a>. All APIs are working only when active state
is "PoweredOn".</p>

<div class='pre p1 fill-light mt0'>state</div>
<div class='pre p1 fill-light mt0'>state(): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>&#x3C;<a href="#state">State</a>></div>



Expand Down Expand Up @@ -2782,7 +2785,7 @@ <h3 class='fl m0' id='blemanager'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
<span class='code strong strong truncate'>onStateChange</span>
<span class='code strong strong truncate'>onStateChange(listener, emitCurrentState)</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
Expand All @@ -2792,7 +2795,7 @@ <h3 class='fl m0' id='blemanager'>

<p>Notifies about <a href="#state">State</a> changes of a <a href="#blemanager">BleManager</a>.</p>

<div class='pre p1 fill-light mt0'>onStateChange</div>
<div class='pre p1 fill-light mt0'>onStateChange(listener: function (newState: <a href="#state">State</a>), emitCurrentState: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a>): <a href="#subscription">Subscription</a></div>



Expand Down Expand Up @@ -2996,7 +2999,7 @@ <h3 class='fl m0' id='blemanager'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
<span class='code strong strong truncate'>stopDeviceScan</span>
<span class='code strong strong truncate'>stopDeviceScan()</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
Expand All @@ -3006,7 +3009,7 @@ <h3 class='fl m0' id='blemanager'>

<p>Stops <a href="#device">Device</a> scan if in progress.</p>

<div class='pre p1 fill-light mt0'>stopDeviceScan</div>
<div class='pre p1 fill-light mt0'>stopDeviceScan(): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>&#x3C;void></div>



Expand Down
35 changes: 34 additions & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ PODS:
- hermes-engine (0.74.1):
- hermes-engine/Pre-built (= 0.74.1)
- hermes-engine/Pre-built (0.74.1)
- MMKV (1.3.7):
- MMKVCore (~> 1.3.7)
- MMKVCore (1.3.7)
- MultiplatformBleAdapter (0.2.0)
- RCT-Folly (2024.01.01.00):
- boost
Expand Down Expand Up @@ -958,6 +961,28 @@ PODS:
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- react-native-mmkv (2.12.2):
- DoubleConversion
- glog
- hermes-engine
- MMKV (>= 1.3.3)
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Codegen
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- react-native-safe-area-context (4.10.1):
- React-Core
- React-nativeconfig (0.74.1)
Expand Down Expand Up @@ -1248,6 +1273,7 @@ DEPENDENCIES:
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
- React-Mapbuffer (from `../node_modules/react-native/ReactCommon`)
- react-native-ble-plx (from `../..`)
- react-native-mmkv (from `../node_modules/react-native-mmkv`)
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
- React-nativeconfig (from `../node_modules/react-native/ReactCommon`)
- React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`)
Expand Down Expand Up @@ -1277,6 +1303,8 @@ DEPENDENCIES:

SPEC REPOS:
trunk:
- MMKV
- MMKVCore
- MultiplatformBleAdapter
- SocketRocket

Expand Down Expand Up @@ -1344,6 +1372,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon"
react-native-ble-plx:
:path: "../.."
react-native-mmkv:
:path: "../node_modules/react-native-mmkv"
react-native-safe-area-context:
:path: "../node_modules/react-native-safe-area-context"
React-nativeconfig:
Expand Down Expand Up @@ -1404,7 +1434,9 @@ SPEC CHECKSUMS:
fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120
glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2
hermes-engine: 16b8530de1b383cdada1476cf52d1b52f0692cbc
MultiplatformBleAdapter: ea8bac405ec200d0ca9de0f89afef6f06fb2abbc
MMKV: 36a22a9ec84c9bb960613a089ddf6f48be9312b0
MMKVCore: 158e61c8516401a9fac730288acb29e6fc19bbf9
MultiplatformBleAdapter: b1fddd0d499b96b607e00f0faa8e60648343dc1d
RCT-Folly: 02617c592a293bd6d418e0a88ff4ee1f88329b47
RCTDeprecation: efb313d8126259e9294dc4ee0002f44a6f676aba
RCTRequired: f49ea29cece52aee20db633ae7edc4b271435562
Expand All @@ -1430,6 +1462,7 @@ SPEC CHECKSUMS:
React-logger: 7e7403a2b14c97f847d90763af76b84b152b6fce
React-Mapbuffer: 11029dcd47c5c9e057a4092ab9c2a8d10a496a33
react-native-ble-plx: 08539040709361221aa9f8cada60dc730b9168c5
react-native-mmkv: 8c9a677e64a1ac89b0c6cf240feea528318b3074
react-native-safe-area-context: dcab599c527c2d7de2d76507a523d20a0b83823d
React-nativeconfig: b0073a590774e8b35192fead188a36d1dca23dec
React-NativeModulesApple: df46ff3e3de5b842b30b4ca8a6caae6d7c8ab09f
Expand Down
9 changes: 5 additions & 4 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"react": "18.2.0",
"react-native": "0.74.1",
"react-native-base64": "^0.2.1",
"react-native-mmkv": "^2.12.2",
"react-native-safe-area-context": "^4.10.1",
"react-native-screens": "^3.31.1",
"react-native-toast-message": "^2.1.6",
Expand All @@ -23,13 +24,13 @@
"@babel/core": "^7.20.0",
"@babel/preset-env": "^7.20.0",
"@babel/runtime": "^7.20.0",
"@react-native/babel-preset": "0.74.83",
"@react-native/eslint-config": "^0.72.2",
"@types/react-native-base64": "^0.2.0",
"@react-native/metro-config": "0.74.83",
"@react-native/typescript-config": "0.74.83",
"@types/react-native-base64": "^0.2.0",
"babel-plugin-module-resolver": "^5.0.0",
"metro-react-native-babel-preset": "0.76.8",
"@react-native/babel-preset": "0.74.83",
"@react-native/typescript-config": "0.74.83"
"metro-react-native-babel-preset": "0.76.8"
},
"engines": {
"node": ">=18"
Expand Down
1 change: 1 addition & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ThemeProvider } from 'styled-components'
import Toast from 'react-native-toast-message'
import { commonTheme } from './theme/theme'
import { Navigation } from './navigation'
import './services/storage/storage'

export function App() {
return (
Expand Down
Loading
Loading