react-native-ble-manager 11.2.0 → 11.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/it/innove/DefaultPeripheral.java +13 -1
- package/android/src/main/java/it/innove/DefaultScanManager.java +44 -0
- package/dist/cjs/types.d.ts +13 -0
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/types.d.ts +13 -0
- package/dist/esm/types.js.map +1 -1
- package/ios/BleManager.m +1 -2
- package/ios/BleManager.swift +3 -3
- package/ios/Helper.swift +1 -1
- package/package.json +1 -1
- package/react-native-ble-manager.podspec +1 -1
- package/src/types.ts +13 -0
|
@@ -14,6 +14,7 @@ import com.facebook.react.bridge.ReactContext;
|
|
|
14
14
|
import com.facebook.react.bridge.WritableArray;
|
|
15
15
|
import com.facebook.react.bridge.WritableMap;
|
|
16
16
|
|
|
17
|
+
import java.nio.ByteBuffer;
|
|
17
18
|
import java.util.Map;
|
|
18
19
|
|
|
19
20
|
|
|
@@ -80,10 +81,21 @@ public class DefaultPeripheral extends Peripheral {
|
|
|
80
81
|
|
|
81
82
|
WritableMap manufacturerData = Arguments.createMap();
|
|
82
83
|
SparseArray<byte[]> manufacturerRawData = advertisingData.getManufacturerSpecificData();
|
|
84
|
+
byte[] manufacturerRawBytes = new byte[0];
|
|
83
85
|
if (manufacturerRawData != null && manufacturerRawData.size() > 0) {
|
|
84
|
-
|
|
86
|
+
int key = manufacturerRawData.keyAt(0);
|
|
87
|
+
byte[] data = manufacturerRawData.valueAt(0);
|
|
88
|
+
manufacturerData.putMap(String.format("%04x", key), byteArrayToWritableMap(data));
|
|
89
|
+
|
|
90
|
+
ByteBuffer keyBuffer = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE);
|
|
91
|
+
keyBuffer.putInt(key);
|
|
92
|
+
byte[] keyBytes = keyBuffer.array();
|
|
93
|
+
manufacturerRawBytes = new byte[keyBytes.length + data.length];
|
|
94
|
+
System.arraycopy(keyBytes, 0, manufacturerRawBytes, 0, keyBytes.length);
|
|
95
|
+
System.arraycopy(data, 0, manufacturerRawBytes, keyBytes.length, data.length);
|
|
85
96
|
}
|
|
86
97
|
advertising.putMap("manufacturerData", manufacturerData);
|
|
98
|
+
advertising.putMap("manufacturerRawData", byteArrayToWritableMap(manufacturerRawBytes));
|
|
87
99
|
|
|
88
100
|
advertising.putInt("txPowerLevel", advertisingData.getTxPowerLevel());
|
|
89
101
|
}
|
|
@@ -27,6 +27,7 @@ import com.facebook.react.bridge.ReadableMap;
|
|
|
27
27
|
import com.facebook.react.bridge.WritableMap;
|
|
28
28
|
|
|
29
29
|
import java.util.ArrayList;
|
|
30
|
+
import java.util.Arrays;
|
|
30
31
|
import java.util.List;
|
|
31
32
|
|
|
32
33
|
@SuppressLint("MissingPermission")
|
|
@@ -106,6 +107,49 @@ public class DefaultScanManager extends ScanManager {
|
|
|
106
107
|
}
|
|
107
108
|
}
|
|
108
109
|
|
|
110
|
+
if (options.hasKey("manufacturerData")) {
|
|
111
|
+
ReadableMap manufacturerDataMap = options.getMap("manufacturerData");
|
|
112
|
+
if (manufacturerDataMap != null && manufacturerDataMap.hasKey("manufacturerId")) {
|
|
113
|
+
int manufacturerId = manufacturerDataMap.getInt("manufacturerId");
|
|
114
|
+
ReadableArray manufacturerData = manufacturerDataMap.getArray("manufacturerData");
|
|
115
|
+
ReadableArray manufacturerDataMask = manufacturerDataMap.getArray("manufacturerDataMask");
|
|
116
|
+
byte[] manufacturerDataBytes = new byte[0];
|
|
117
|
+
byte[] manufacturerDataMaskBytes = new byte[0];
|
|
118
|
+
if (manufacturerData != null) {
|
|
119
|
+
manufacturerDataBytes = new byte[manufacturerData.size()];
|
|
120
|
+
for (int i = 0; i < manufacturerData.size(); i++) {
|
|
121
|
+
manufacturerDataBytes[i] = Integer.valueOf(manufacturerData.getInt(i)).byteValue();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (manufacturerDataMask != null) {
|
|
125
|
+
manufacturerDataMaskBytes = new byte[manufacturerDataMask.size()];
|
|
126
|
+
for (int i = 0; i < manufacturerDataMask.size(); i++) {
|
|
127
|
+
manufacturerDataMaskBytes[i] = Integer.valueOf(manufacturerDataMask.getInt(i)).byteValue();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (manufacturerDataBytes.length != manufacturerDataMaskBytes.length) {
|
|
131
|
+
callback.invoke("manufacturerData and manufacturerDataMask must have the same length");
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
Log.d(
|
|
135
|
+
BleManager.LOG_TAG,
|
|
136
|
+
String.format(
|
|
137
|
+
"Filter on manufacturerId: %d; manufacturerData: %s; manufacturerDataMask: %s",
|
|
138
|
+
manufacturerId,
|
|
139
|
+
Arrays.toString(manufacturerDataBytes),
|
|
140
|
+
Arrays.toString(manufacturerDataMaskBytes)
|
|
141
|
+
)
|
|
142
|
+
);
|
|
143
|
+
ScanFilter filter = new ScanFilter.Builder()
|
|
144
|
+
.setManufacturerData(
|
|
145
|
+
manufacturerId,
|
|
146
|
+
manufacturerDataBytes,
|
|
147
|
+
manufacturerDataMaskBytes
|
|
148
|
+
).build();
|
|
149
|
+
filters.add(filter);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
109
153
|
getBluetoothAdapter().getBluetoothLeScanner().startScan(filters, scanSettingsBuilder.build(), mScanCallback);
|
|
110
154
|
isScanning = true;
|
|
111
155
|
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ export interface AdvertisingData {
|
|
|
38
38
|
localName?: string;
|
|
39
39
|
rawData?: CustomAdvertisingData;
|
|
40
40
|
manufacturerData?: Record<string, CustomAdvertisingData>;
|
|
41
|
+
manufacturerRawData?: Record<string, CustomAdvertisingData>;
|
|
41
42
|
serviceData?: Record<string, CustomAdvertisingData>;
|
|
42
43
|
serviceUUIDs?: string[];
|
|
43
44
|
txPowerLevel?: number;
|
|
@@ -132,6 +133,18 @@ export interface ScanOptions {
|
|
|
132
133
|
* https://developer.android.com/reference/android/bluetooth/le/ScanFilter.Builder#setDeviceName(java.lang.String)
|
|
133
134
|
*/
|
|
134
135
|
exactAdvertisingName?: string | string[];
|
|
136
|
+
/**
|
|
137
|
+
* Android only. Filters scan results by manufacturer id and data.
|
|
138
|
+
* `manufacturerId` usually matches the company id, can be given as a hex, e.g. 0xe4f7.
|
|
139
|
+
* `manufacturerData` and `manufacturerDataMask` must have the same length. For any bit in the mask, set it to 1 if
|
|
140
|
+
* it needs to match the one in manufacturer data, otherwise set it to 0.
|
|
141
|
+
* https://developer.android.com/reference/android/bluetooth/le/ScanFilter.Builder#setManufacturerData(int,%20byte[],%20byte[])
|
|
142
|
+
*/
|
|
143
|
+
manufacturerData?: {
|
|
144
|
+
manufacturerId: number;
|
|
145
|
+
manufacturerData?: number[];
|
|
146
|
+
manufacturerDataMask?: number[];
|
|
147
|
+
};
|
|
135
148
|
}
|
|
136
149
|
/**
|
|
137
150
|
* [android only]
|
package/dist/cjs/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AAAA;;;KAGK;AACL,IAAY,QAwBX;AAxBD,WAAY,QAAQ;IAClB;;OAEG;IACH,+BAAmB,CAAA;IACnB;;OAEG;IACH,mCAAuB,CAAA;IACvB,uCAA2B,CAAA;IAC3B;;OAEG;IACH,yCAA6B,CAAA;IAC7B,qBAAS,CAAA;IACT,uBAAW,CAAA;IACX;;OAEG;IACH,oCAAwB,CAAA;IACxB;;OAEG;IACH,sCAA0B,CAAA;AAC5B,CAAC,EAxBW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAwBnB;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AAAA;;;KAGK;AACL,IAAY,QAwBX;AAxBD,WAAY,QAAQ;IAClB;;OAEG;IACH,+BAAmB,CAAA;IACnB;;OA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W,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAI7B;AAsCD,IAAY,YAmBX;AAnBD,WAAY,YAAY;IACtB,qEAAqD,CAAA;IACrD,yDAAyC,CAAA;IACzC,6EAA6D,CAAA;IAC7D,uGAAuF,CAAA;IACvF,2EAA2D,CAAA;IAC3D,iFAAiE,CAAA;IACjE;;OAEG;IACH,2EAA2D,CAAA;IAC3D;;OAEG;IACH,qGAAqF,CAAA;IACrF;;OAEG;IACH,mGAAmF,CAAA;AACrF,CAAC,EAnBW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAmBvB"}
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ export interface AdvertisingData {
|
|
|
38
38
|
localName?: string;
|
|
39
39
|
rawData?: CustomAdvertisingData;
|
|
40
40
|
manufacturerData?: Record<string, CustomAdvertisingData>;
|
|
41
|
+
manufacturerRawData?: Record<string, CustomAdvertisingData>;
|
|
41
42
|
serviceData?: Record<string, CustomAdvertisingData>;
|
|
42
43
|
serviceUUIDs?: string[];
|
|
43
44
|
txPowerLevel?: number;
|
|
@@ -132,6 +133,18 @@ export interface ScanOptions {
|
|
|
132
133
|
* https://developer.android.com/reference/android/bluetooth/le/ScanFilter.Builder#setDeviceName(java.lang.String)
|
|
133
134
|
*/
|
|
134
135
|
exactAdvertisingName?: string | string[];
|
|
136
|
+
/**
|
|
137
|
+
* Android only. Filters scan results by manufacturer id and data.
|
|
138
|
+
* `manufacturerId` usually matches the company id, can be given as a hex, e.g. 0xe4f7.
|
|
139
|
+
* `manufacturerData` and `manufacturerDataMask` must have the same length. For any bit in the mask, set it to 1 if
|
|
140
|
+
* it needs to match the one in manufacturer data, otherwise set it to 0.
|
|
141
|
+
* https://developer.android.com/reference/android/bluetooth/le/ScanFilter.Builder#setManufacturerData(int,%20byte[],%20byte[])
|
|
142
|
+
*/
|
|
143
|
+
manufacturerData?: {
|
|
144
|
+
manufacturerId: number;
|
|
145
|
+
manufacturerData?: number[];
|
|
146
|
+
manufacturerDataMask?: number[];
|
|
147
|
+
};
|
|
135
148
|
}
|
|
136
149
|
/**
|
|
137
150
|
* [android only]
|
package/dist/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;KAGK;AACL,MAAM,CAAN,IAAY,QAwBX;AAxBD,WAAY,QAAQ;IAClB;;OAEG;IACH,+BAAmB,CAAA;IACnB;;OAEG;IACH,mCAAuB,CAAA;IACvB,uCAA2B,CAAA;IAC3B;;OAEG;IACH,yCAA6B,CAAA;IAC7B,qBAAS,CAAA;IACT,uBAAW,CAAA;IACX;;OAEG;IACH,oCAAwB,CAAA;IACxB;;OAEG;IACH,sCAA0B,CAAA;AAC5B,CAAC,EAxBW,QAAQ,KAAR,QAAQ,QAwBnB;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;KAGK;AACL,MAAM,CAAN,IAAY,QAwBX;AAxBD,WAAY,QAAQ;IAClB;;OAEG;IACH,+BAAmB,CAAA;IACnB;;OAEG;IACH,mCAAuB,CAAA;IACvB,uCAA2B,CAAA;IAC3B;;OAEG;IACH,yCAA6B,CAAA;IAC7B,qBAAS,CAAA;IACT,uBAAW,CAAA;IACX;;OAEG;IACH,oCAAwB,CAAA;IACxB;;OAEG;IACH,sCAA0B,CAAA;AAC5B,CAAC,EAxBW,QAAQ,KAAR,QAAQ,QAwBnB;AA+HD;;GAEG;AACH,MAAM,CAAN,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,gEAAkB,CAAA;IAClB,qDAAY,CAAA;IACZ,qDAAY,CAAA;IACZ,yDAAc,CAAA;AAChB,CAAC,EALW,WAAW,KAAX,WAAW,QAKtB;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,mEAAc,CAAA;IACd,2DAAU,CAAA;AACZ,CAAC,EAHW,gBAAgB,KAAhB,gBAAgB,QAG3B;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,mBAIX;AAJD,WAAY,mBAAmB;IAC7B,yEAAc,CAAA;IACd,yEAAc,CAAA;IACd,uEAAa,CAAA;AACf,CAAC,EAJW,mBAAmB,KAAnB,mBAAmB,QAI9B;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IAC3B,iFAAoB,CAAA;IACpB,mFAAqB,CAAA;IACrB,mFAAqB,CAAA;AACvB,CAAC,EAJW,iBAAiB,KAAjB,iBAAiB,QAI5B;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,cAKX;AALD,WAAY,cAAc;IACxB,qDAAS,CAAA;IACT,qDAAS,CAAA;IACT,2DAAY,CAAA;IACZ,uEAAmB,CAAA;AACrB,CAAC,EALW,cAAc,KAAd,cAAc,QAKzB;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC5B,mEAAY,CAAA;IACZ,2DAAQ,CAAA;IACR,yDAAO,CAAA;AACT,CAAC,EAJW,kBAAkB,KAAlB,kBAAkB,QAI7B;AAsCD,MAAM,CAAN,IAAY,YAmBX;AAnBD,WAAY,YAAY;IACtB,qEAAqD,CAAA;IACrD,yDAAyC,CAAA;IACzC,6EAA6D,CAAA;IAC7D,uGAAuF,CAAA;IACvF,2EAA2D,CAAA;IAC3D,iFAAiE,CAAA;IACjE;;OAEG;IACH,2EAA2D,CAAA;IAC3D;;OAEG;IACH,qGAAqF,CAAA;IACrF;;OAEG;IACH,mGAAmF,CAAA;AACrF,CAAC,EAnBW,YAAY,KAAZ,YAAY,QAmBvB"}
|
package/ios/BleManager.m
CHANGED
|
@@ -98,8 +98,7 @@ RCT_EXTERN_METHOD(isPeripheralConnected:
|
|
|
98
98
|
(NSString *)peripheralUUID
|
|
99
99
|
callback:(nonnull RCTResponseSenderBlock)callback)
|
|
100
100
|
|
|
101
|
-
RCT_EXTERN_METHOD(isScanning:
|
|
102
|
-
callback:(nonnull RCTResponseSenderBlock)callback)
|
|
101
|
+
RCT_EXTERN_METHOD(isScanning:(nonnull RCTResponseSenderBlock)callback)
|
|
103
102
|
|
|
104
103
|
RCT_EXTERN_METHOD(getMaximumWriteValueLengthForWithoutResponse:
|
|
105
104
|
(NSString *)peripheralUUID
|
package/ios/BleManager.swift
CHANGED
|
@@ -318,9 +318,9 @@ class BleManager: RCTEventEmitter, CBCentralManagerDelegate, CBPeripheralDelegat
|
|
|
318
318
|
if let uuid = UUID(uuidString: peripheralUUID) {
|
|
319
319
|
let peripheralArray = manager?.retrievePeripherals(withIdentifiers: [uuid])
|
|
320
320
|
if let retrievedPeripheral = peripheralArray?.first {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
321
|
+
serialQueue.sync {
|
|
322
|
+
peripherals[retrievedPeripheral.uuidAsString()] = Peripheral(peripheral:retrievedPeripheral)
|
|
323
|
+
}
|
|
324
324
|
NSLog("Successfully retrieved and connecting to peripheral with UUID: \(peripheralUUID)")
|
|
325
325
|
|
|
326
326
|
// Connect to the retrieved peripheral
|
package/ios/Helper.swift
CHANGED
|
@@ -109,7 +109,7 @@ class Helper {
|
|
|
109
109
|
adv["manufacturerData"] = manInfo
|
|
110
110
|
}
|
|
111
111
|
adv.removeValue(forKey: CBAdvertisementDataManufacturerDataKey)
|
|
112
|
-
adv["manufacturerRawData"] =
|
|
112
|
+
adv["manufacturerRawData"] = Helper.dataToArrayBuffer(mfgData)
|
|
113
113
|
|
|
114
114
|
}
|
|
115
115
|
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@ Pod::Spec.new do |s|
|
|
|
9
9
|
s.authors = { "Innove" => "https://github.com/innoveit" }
|
|
10
10
|
s.homepage = "https://github.com/innoveit/react-native-ble-manager"
|
|
11
11
|
s.license = "Apache-2.0"
|
|
12
|
-
s.platform = :ios, "
|
|
12
|
+
s.platform = :ios, "10.0"
|
|
13
13
|
s.source = { :git => "https://github.com/innoveit/react-native-ble-manager.git" }
|
|
14
14
|
s.source_files = "ios/**/*.{h,c,cc,cpp,m,mm,swift}"
|
|
15
15
|
|
package/src/types.ts
CHANGED
|
@@ -40,6 +40,7 @@ export interface AdvertisingData {
|
|
|
40
40
|
localName?: string;
|
|
41
41
|
rawData?: CustomAdvertisingData;
|
|
42
42
|
manufacturerData?: Record<string, CustomAdvertisingData>;
|
|
43
|
+
manufacturerRawData?: Record<string, CustomAdvertisingData>;
|
|
43
44
|
serviceData?: Record<string, CustomAdvertisingData>;
|
|
44
45
|
serviceUUIDs?: string[];
|
|
45
46
|
txPowerLevel?: number;
|
|
@@ -138,6 +139,18 @@ export interface ScanOptions {
|
|
|
138
139
|
* https://developer.android.com/reference/android/bluetooth/le/ScanFilter.Builder#setDeviceName(java.lang.String)
|
|
139
140
|
*/
|
|
140
141
|
exactAdvertisingName?: string|string[];
|
|
142
|
+
/**
|
|
143
|
+
* Android only. Filters scan results by manufacturer id and data.
|
|
144
|
+
* `manufacturerId` usually matches the company id, can be given as a hex, e.g. 0xe4f7.
|
|
145
|
+
* `manufacturerData` and `manufacturerDataMask` must have the same length. For any bit in the mask, set it to 1 if
|
|
146
|
+
* it needs to match the one in manufacturer data, otherwise set it to 0.
|
|
147
|
+
* https://developer.android.com/reference/android/bluetooth/le/ScanFilter.Builder#setManufacturerData(int,%20byte[],%20byte[])
|
|
148
|
+
*/
|
|
149
|
+
manufacturerData?: {
|
|
150
|
+
manufacturerId: number;
|
|
151
|
+
manufacturerData?: number[];
|
|
152
|
+
manufacturerDataMask?: number[];
|
|
153
|
+
}
|
|
141
154
|
}
|
|
142
155
|
|
|
143
156
|
/**
|