react-native-ble-manager 12.2.2 → 12.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ble-manager",
3
- "version": "12.2.2",
3
+ "version": "12.4.0",
4
4
  "description": "A BLE module for react native.",
5
5
  "homepage": "https://innoveit.github.io/react-native-ble-manager/",
6
6
  "repository": {
@@ -63,7 +63,7 @@
63
63
  "postversion": "git push --follow-tags"
64
64
  },
65
65
  "resolutions": {
66
- "@types/react": "^18.2.44"
66
+ "@types/react": "^19.2.2"
67
67
  },
68
68
  "peerDependencies": {
69
69
  "react": "*",
@@ -71,22 +71,16 @@
71
71
  },
72
72
  "devDependencies": {
73
73
  "@commitlint/config-conventional": "^19.6.0",
74
- "@react-native/eslint-config": "^0.76.2",
75
- "@release-it/conventional-changelog": "^9.0.3",
76
- "@types/jest": "^29.5.14",
77
- "@types/react": "^18.3.12",
78
- "commitlint": "^19.6.0",
79
- "del-cli": "^6.0.0",
80
- "eslint": "^9.15.0",
81
- "eslint-config-prettier": "^9.1.0",
82
- "eslint-plugin-prettier": "^5.2.1",
83
- "jest": "^29.7.0",
84
- "prettier": "^3.3.3",
85
- "react": "18.3.1",
86
- "react-native": "0.76.2",
87
- "@react-native/gradle-plugin": "^0.76.2",
88
- "turbo": "^2.3.0",
89
- "typescript": "^5.6.3",
74
+ "@react-native/eslint-config": "^0.82.1",
75
+ "@types/react": "^19.2.2",
76
+ "eslint": "^9.39.1",
77
+ "eslint-config-prettier": "^10.1.8",
78
+ "eslint-plugin-prettier": "^5.5.4",
79
+ "prettier": "^3.6.2",
80
+ "react": "19.2.0",
81
+ "react-native": "0.82.1",
82
+ "@react-native/gradle-plugin": "^0.82.1",
83
+ "typescript": "^5.9.3",
90
84
  "@expo/config-plugins": "^9.0.10",
91
85
  "expo-module-scripts": "^4.0.2"
92
86
  },
@@ -1,3 +1,4 @@
1
+ // oxlint-disable no-wrapper-object-types
1
2
  import { TurboModule, TurboModuleRegistry } from 'react-native';
2
3
  // @ts-ignore Ignore since it comes from codegen types.
3
4
  import type { EventEmitter } from 'react-native/Libraries/Types/CodegenTypes';
@@ -12,13 +13,9 @@ import type { EventEmitter } from 'react-native/Libraries/Types/CodegenTypes';
12
13
  export interface Spec extends TurboModule {
13
14
  start(options: Object, callback: (error: CallbackError) => void): void;
14
15
 
15
- scan(
16
- serviceUUIDStrings: string[],
17
- timeoutSeconds: number,
18
- allowDuplicates: boolean,
19
- scanningOptions: Object,
20
- callback: (error: CallbackError) => void
21
- ): void;
16
+ isStarted(callback: (error: CallbackError, started: boolean) => void): void;
17
+
18
+ scan(scanningOptions: Object, callback: (error: CallbackError) => void): void;
22
19
 
23
20
  stopScan(callback: (error: CallbackError) => void): void;
24
21
 
@@ -42,7 +39,7 @@ export interface Spec extends TurboModule {
42
39
 
43
40
  readRSSI(
44
41
  peripheralUUID: string,
45
- callback: (error: string | null, rssi: number) => void
42
+ callback: (error: CallbackError, rssi: number) => void
46
43
  ): void;
47
44
 
48
45
  readDescriptor(
@@ -50,7 +47,7 @@ export interface Spec extends TurboModule {
50
47
  serviceUUID: string,
51
48
  characteristicUUID: string,
52
49
  descriptorUUID: string,
53
- callback: (error: string | null, data: number[]) => void
50
+ callback: (error: CallbackError, data: number[]) => void
54
51
  ): void;
55
52
 
56
53
  writeDescriptor(
@@ -58,12 +55,12 @@ export interface Spec extends TurboModule {
58
55
  serviceUUID: string,
59
56
  characteristicUUID: string,
60
57
  descriptorUUID: string,
61
- data: object[],
62
- callback: (error: string | null) => void
58
+ data: Object[],
59
+ callback: (error: CallbackError) => void
63
60
  ): void;
64
61
 
65
62
  getDiscoveredPeripherals(
66
- callback: (error: string | null, result: Peripheral[] | null) => void
63
+ callback: (error: CallbackError, result: Peripheral[] | null) => void
67
64
  ): void;
68
65
 
69
66
  checkState(callback: (state: BleState) => void): void;
@@ -72,26 +69,26 @@ export interface Spec extends TurboModule {
72
69
  peripheralUUID: string,
73
70
  serviceUUID: string,
74
71
  characteristicUUID: string,
75
- message: object[],
72
+ message: Object[],
76
73
  maxByteSize: number,
77
- callback: (error: string | null) => void
74
+ callback: (error: CallbackError) => void
78
75
  ): void;
79
76
 
80
77
  writeWithoutResponse(
81
78
  peripheralUUID: string,
82
79
  serviceUUID: string,
83
80
  characteristicUUID: string,
84
- message: object[],
81
+ message: Object[],
85
82
  maxByteSize: number,
86
83
  queueSleepTime: number,
87
- callback: (error: string | null) => void
84
+ callback: (error: CallbackError) => void
88
85
  ): void;
89
86
 
90
87
  read(
91
88
  peripheralUUID: string,
92
89
  serviceUUID: string,
93
90
  characteristicUUID: string,
94
- callback: (error: string | null, data: number[]) => void
91
+ callback: (error: CallbackError, data: number[]) => void
95
92
  ): void;
96
93
 
97
94
  startNotificationWithBuffer(
@@ -99,26 +96,26 @@ export interface Spec extends TurboModule {
99
96
  serviceUUID: string,
100
97
  characteristicUUID: string,
101
98
  bufferLength: number,
102
- callback: (error: string | null) => void
99
+ callback: (error: CallbackError) => void
103
100
  ): void;
104
101
 
105
102
  startNotification(
106
103
  peripheralUUID: string,
107
104
  serviceUUID: string,
108
105
  characteristicUUID: string,
109
- callback: (error: string | null) => void
106
+ callback: (error: CallbackError) => void
110
107
  ): void;
111
108
 
112
109
  stopNotification(
113
110
  peripheralUUID: string,
114
111
  serviceUUID: string,
115
112
  characteristicUUID: string,
116
- callback: (error: string | null) => void
113
+ callback: (error: CallbackError) => void
117
114
  ): void;
118
115
 
119
116
  getConnectedPeripherals(
120
117
  serviceUUIDStrings: string[],
121
- callback: (error: string | null, result: Peripheral[] | null) => void
118
+ callback: (error: CallbackError, result: Peripheral[] | null) => void
122
119
  ): void;
123
120
 
124
121
  isPeripheralConnected(
@@ -126,66 +123,66 @@ export interface Spec extends TurboModule {
126
123
  callback: (error: Peripheral[]) => void
127
124
  ): void;
128
125
 
129
- isScanning(callback: (error: string | null, status: boolean) => void): void;
126
+ isScanning(callback: (error: CallbackError, status: boolean) => void): void;
130
127
 
131
128
  getMaximumWriteValueLengthForWithoutResponse(
132
129
  peripheralUUID: string,
133
- callback: (error: string | null, max: number) => void
130
+ callback: (error: CallbackError, max: number) => void
134
131
  ): void;
135
132
 
136
133
  getMaximumWriteValueLengthForWithResponse(
137
134
  deviceUUID: string,
138
- callback: (error: string | null, max: number) => void
135
+ callback: (error: CallbackError, max: number) => void
139
136
  ): void;
140
137
 
141
- enableBluetooth(callback: (error: string | null) => void): void;
138
+ enableBluetooth(callback: (error: CallbackError) => void): void;
142
139
 
143
140
  getBondedPeripherals(
144
- callback: (error: string | null, result: Peripheral[] | null) => void
141
+ callback: (error: CallbackError, result: Peripheral[] | null) => void
145
142
  ): void;
146
143
 
147
144
  createBond(
148
145
  peripheralUUID: string,
149
146
  devicePin: string,
150
- callback: (error: string | null) => void
147
+ callback: (error: CallbackError) => void
151
148
  ): void;
152
149
 
153
150
  removeBond(
154
151
  peripheralUUID: string,
155
- callback: (error: string | null) => void
152
+ callback: (error: CallbackError) => void
156
153
  ): void;
157
154
 
158
155
  removePeripheral(
159
156
  peripheralUUID: string,
160
- callback: (error: string | null) => void
157
+ callback: (error: CallbackError) => void
161
158
  ): void;
162
159
 
163
160
  requestMTU(
164
161
  peripheralUUID: string,
165
162
  mtu: number,
166
- callback: (error: string | null, mtu: number) => void
163
+ callback: (error: CallbackError, mtu: number) => void
167
164
  ): void;
168
165
 
169
166
  requestConnectionPriority(
170
167
  peripheralUUID: string,
171
168
  connectionPriority: number,
172
- callback: (error: string | null, status: boolean) => void
169
+ callback: (error: CallbackError, status: boolean) => void
173
170
  ): void;
174
171
 
175
172
  refreshCache(
176
173
  peripheralUUID: string,
177
- callback: (error: string | null, result: boolean) => void
174
+ callback: (error: CallbackError, result: boolean) => void
178
175
  ): void;
179
176
 
180
177
  setName(name: string): void;
181
178
 
182
179
  getAssociatedPeripherals(
183
- callback: (error: string | null, peripherals: Peripheral[] | null) => void
180
+ callback: (error: CallbackError, peripherals: Peripheral[] | null) => void
184
181
  ): void;
185
182
 
186
183
  removeAssociatedPeripheral(
187
184
  peripheralUUID: string,
188
- callback: (error: string | null) => void
185
+ callback: (error: CallbackError) => void
189
186
  ): void;
190
187
 
191
188
  supportsCompanion(callback: (supports: boolean) => void): void;
@@ -193,7 +190,7 @@ export interface Spec extends TurboModule {
193
190
  companionScan(
194
191
  serviceUUIDs: string[],
195
192
  option: Object,
196
- callback: (error: string | null, peripheral: Peripheral | null) => void
193
+ callback: (error: CallbackError, peripheral: Peripheral | null) => void
197
194
  ): void;
198
195
 
199
196
  /**
@@ -232,30 +229,16 @@ export type Peripheral = {
232
229
  advertising: {
233
230
  isConnectable?: boolean;
234
231
  localName?: string | null;
235
- rawData?: {
236
- CDVType: number[];
237
- bytes: number[];
238
- data: string;
239
- };
232
+ rawData?: { CDVType: number[]; bytes: number[]; data: string };
240
233
  manufacturerData?:
241
- | {
242
- CDVType: number[];
243
- bytes: number[];
244
- data: string;
245
- }[]
234
+ | { CDVType: number[]; bytes: number[]; data: string }[]
246
235
  | null;
247
236
  manufacturerRawData?: {
248
237
  CDVType: number[];
249
238
  bytes: number[];
250
239
  data: string;
251
240
  } | null;
252
- serviceData?:
253
- | {
254
- CDVType: number[];
255
- bytes: number[];
256
- data: string;
257
- }[]
258
- | null;
241
+ serviceData?: { CDVType: number[]; bytes: number[]; data: string }[] | null;
259
242
  serviceUUIDs?: string[];
260
243
  txPowerLevel?: number;
261
244
  };
@@ -268,30 +251,16 @@ export type PeripheralInfo = {
268
251
  advertising: {
269
252
  isConnectable?: boolean;
270
253
  localName?: string | null;
271
- rawData?: {
272
- CDVType: number[];
273
- bytes: number[];
274
- data: string;
275
- } | null;
254
+ rawData?: { CDVType: number[]; bytes: number[]; data: string } | null;
276
255
  manufacturerData?:
277
- | {
278
- CDVType: number[];
279
- bytes: number[];
280
- data: string;
281
- }[]
256
+ | { CDVType: number[]; bytes: number[]; data: string }[]
282
257
  | null;
283
258
  manufacturerRawData?: {
284
259
  CDVType: number[];
285
260
  bytes: number[];
286
261
  data: string;
287
262
  } | null;
288
- serviceData?:
289
- | {
290
- CDVType: number[];
291
- bytes: number[];
292
- data: string;
293
- }[]
294
- | null;
263
+ serviceData?: { CDVType: number[]; bytes: number[]; data: string }[] | null;
295
264
  serviceUUIDs?: string[];
296
265
  txPowerLevel?: number;
297
266
  };
@@ -311,21 +280,14 @@ export type PeripheralInfo = {
311
280
  };
312
281
  characteristic: string;
313
282
  service: string;
314
- descriptors?: {
315
- value: string;
316
- uuid: string;
317
- }[];
283
+ descriptors?: { value: string; uuid: string }[];
318
284
  }[];
319
285
  services?: { uuid: string }[];
320
286
  };
321
287
 
322
- export type EventStopScan = {
323
- status: number;
324
- };
288
+ export type EventStopScan = { status: number };
325
289
 
326
- export type EventDidUpdateState = {
327
- state: string;
328
- };
290
+ export type EventDidUpdateState = { state: string };
329
291
 
330
292
  export type EventDiscoverPeripheral = {
331
293
  id: string;
@@ -412,6 +374,4 @@ export type EventCompanionPeripheral = {
412
374
  };
413
375
  };
414
376
 
415
- export type EventCompanionFailure = {
416
- error: string;
417
- };
377
+ export type EventCompanionFailure = { error: string };
package/src/index.ts CHANGED
@@ -1,7 +1,4 @@
1
- import {
2
- EventSubscription,
3
- NativeModules,
4
- } from 'react-native';
1
+ import { EventSubscription, NativeModules } from 'react-native';
5
2
  import {
6
3
  BleScanCallbackType,
7
4
  BleScanMatchCount,
@@ -16,6 +13,7 @@ import {
16
13
  ScanOptions,
17
14
  StartOptions,
18
15
  } from './types';
16
+ import { CallbackError } from './NativeBleManager';
19
17
  export * from './types';
20
18
 
21
19
  // @ts-expect-error This applies the turbo module version only when turbo is enabled for backwards compatibility.
@@ -431,6 +429,22 @@ class BleManager {
431
429
  });
432
430
  }
433
431
 
432
+ /**
433
+ * Check if the BLE manager has been started.
434
+ * @returns boolean promise indicating if the manager is started.
435
+ */
436
+ isStarted(): Promise<boolean> {
437
+ return new Promise((fulfill, reject) => {
438
+ BleManagerModule.isStarted((error: CallbackError, started: boolean) => {
439
+ if (error) {
440
+ reject(error);
441
+ } else {
442
+ fulfill(started);
443
+ }
444
+ });
445
+ });
446
+ }
447
+
434
448
  /**
435
449
  *
436
450
  * @param serviceUUIDs
@@ -439,15 +453,16 @@ class BleManager {
439
453
  * @param scanningOptions optional map of properties to fine-tune scan behavior, see DOCS.
440
454
  * @returns
441
455
  */
442
- scan(
443
- serviceUUIDs: string[],
444
- seconds: number,
445
- allowDuplicates?: boolean,
446
- scanningOptions: ScanOptions = {}
447
- ) {
456
+ scan(scanningOptions: ScanOptions = {}) {
448
457
  return new Promise<void>((fulfill, reject) => {
449
- if (allowDuplicates == null) {
450
- allowDuplicates = false;
458
+ if (scanningOptions.serviceUUIDs == null) {
459
+ scanningOptions.serviceUUIDs = [];
460
+ }
461
+ if (scanningOptions.seconds == null) {
462
+ scanningOptions.seconds = 0;
463
+ }
464
+ if (scanningOptions.allowDuplicates == null) {
465
+ scanningOptions.allowDuplicates = false;
451
466
  }
452
467
 
453
468
  // (ANDROID) Match as many advertisement per filter as hw could allow
@@ -491,19 +506,13 @@ class BleManager {
491
506
  }
492
507
  }
493
508
 
494
- BleManagerModule.scan(
495
- serviceUUIDs,
496
- seconds,
497
- allowDuplicates,
498
- scanningOptions,
499
- (error: string | null) => {
500
- if (error) {
501
- reject(error);
502
- } else {
503
- fulfill();
504
- }
509
+ BleManagerModule.scan(scanningOptions, (error: string | null) => {
510
+ if (error) {
511
+ reject(error);
512
+ } else {
513
+ fulfill();
505
514
  }
506
- );
515
+ });
507
516
  });
508
517
  }
509
518
 
package/src/types.ts CHANGED
@@ -94,6 +94,12 @@ export interface ConnectOptions {
94
94
  * https://developer.android.com/reference/android/bluetooth/le/ScanSettings
95
95
  */
96
96
  export interface ScanOptions {
97
+ serviceUUIDs?: string[];
98
+ seconds?: number;
99
+ /**
100
+ * iOS only: whether to allow duplicate peripheral during a scan
101
+ */
102
+ allowDuplicates?: boolean;
97
103
  /**
98
104
  * This will only works if a ScanFilter is active. Otherwise, may not retrieve any result.
99
105
  * See https://developer.android.com/reference/android/bluetooth/le/ScanSettings#MATCH_NUM_FEW_ADVERTISEMENT.
@@ -158,6 +164,10 @@ export interface ScanOptions {
158
164
  */
159
165
  single?: boolean;
160
166
  companion?: boolean;
167
+ /**
168
+ * [Android O+] Deliver scan results using a PendingIntent instead of the default callback.
169
+ */
170
+ useScanIntent?: boolean;
161
171
  }
162
172
 
163
173
  export interface CompanionScanOptions {