react-native-ble-manager 11.5.6 → 12.0.0-rc.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.
Files changed (44) hide show
  1. package/README.md +16 -3
  2. package/RNBleManager.podspec +24 -0
  3. package/android/build.gradle +116 -43
  4. package/android/gradle.properties +1 -0
  5. package/android/src/main/java/it/innove/BleManager.java +174 -148
  6. package/android/src/main/java/it/innove/BleManagerPackage.java +15 -14
  7. package/android/src/main/java/it/innove/CompanionScanner.java +39 -13
  8. package/android/src/main/java/it/innove/DefaultPeripheral.java +4 -4
  9. package/android/src/main/java/it/innove/DefaultScanManager.java +16 -16
  10. package/android/src/main/java/it/innove/Peripheral.java +20 -17
  11. package/dist/cjs/NativeBleManager.d.ts +241 -0
  12. package/dist/cjs/NativeBleManager.js +5 -0
  13. package/dist/cjs/NativeBleManager.js.map +1 -0
  14. package/dist/cjs/index.d.ts +15 -3
  15. package/dist/cjs/index.js +89 -38
  16. package/dist/cjs/index.js.map +1 -1
  17. package/dist/cjs/types.d.ts +17 -11
  18. package/dist/cjs/types.js +8 -8
  19. package/dist/cjs/types.js.map +1 -1
  20. package/dist/esm/NativeBleManager.d.ts +241 -0
  21. package/dist/esm/NativeBleManager.js +3 -0
  22. package/dist/esm/NativeBleManager.js.map +1 -0
  23. package/dist/esm/index.d.ts +15 -3
  24. package/dist/esm/index.js +92 -41
  25. package/dist/esm/index.js.map +1 -1
  26. package/dist/esm/types.d.ts +17 -11
  27. package/ios/BleManager-Bridging-Header.h +7 -1
  28. package/ios/BleManager.h +39 -2
  29. package/ios/BleManager.mm +277 -0
  30. package/ios/Helper.swift +6 -6
  31. package/ios/RNBleManager.h +7 -0
  32. package/ios/{BleManager.swift → SwiftBleManager.swift} +322 -355
  33. package/package.json +107 -56
  34. package/src/NativeBleManager.ts +409 -0
  35. package/src/index.ts +162 -77
  36. package/src/types.ts +38 -31
  37. package/android/src/main/java/it/innove/LegacyScanManager.java +0 -112
  38. package/ios/BleManager.m +0 -153
  39. package/ios/BleManager.xcodeproj/project.pbxproj +0 -324
  40. package/ios/BleManager.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  41. package/ios/BleManager.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  42. package/ios/BleManager.xcodeproj/project.xcworkspace/xcuserdata/marco.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  43. package/ios/BleManager.xcodeproj/xcuserdata/marco.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
  44. package/react-native-ble-manager.podspec +0 -17
package/package.json CHANGED
@@ -1,58 +1,109 @@
1
1
  {
2
- "name": "react-native-ble-manager",
3
- "version": "11.5.6",
4
- "description": "A BLE module for react native.",
5
- "repository": {
6
- "type": "git",
7
- "url": "https://github.com/innoveit/react-native-ble-manager.git"
8
- },
9
- "bugs": {
10
- "url": "https://github.com/innoveit/react-native-ble-manager/issues"
11
- },
12
- "keywords": [
13
- "react-native",
14
- "android",
15
- "ios",
16
- "ble",
17
- "bluetooth",
18
- "low energy"
19
- ],
20
- "license": "Apache-2.0",
21
- "author": {
22
- "name": "Innove",
23
- "url": "https://github.com/innoveit"
24
- },
25
- "main": "dist/cjs/index.js",
26
- "types": "dist/esm/index.d.ts",
27
- "module": "dist/esm/index.js",
28
- "react-native": "src/index.ts",
29
- "files": [
30
- "/dist",
31
- "/src",
32
- "/android",
33
- "!/android/build",
34
- "/ios",
35
- "/*.podspec"
36
- ],
37
- "scripts": {
38
- "version": "git add -A",
39
- "clean": "rimraf dist",
40
- "type:check": "tsc -p tsconfig.json --noEmit",
41
- "prebuild": "npm run clean",
42
- "build:cjs": "tsc --module commonjs --outDir dist/cjs",
43
- "build:esm": "tsc --outDir dist/esm",
44
- "build": "npm run build:esm && npm run build:cjs",
45
- "watch": "npm run build --watch",
46
- "prepare": "npm run build",
47
- "preversion": "npm run build",
48
- "postversion": "git push --follow-tags"
49
- },
50
- "peerDependencies": {
51
- "react-native": ">=0.60.0"
52
- },
53
- "devDependencies": {
54
- "react-native": "0.73.6",
55
- "rimraf": "4.1.2",
56
- "typescript": "4.9.5"
57
- }
2
+ "name": "react-native-ble-manager",
3
+ "version": "12.0.0-rc.0",
4
+ "description": "A BLE module for react native.",
5
+ "homepage": "https://innoveit.github.io/react-native-ble-manager/",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/innoveit/react-native-ble-manager.git"
9
+ },
10
+ "bugs": {
11
+ "url": "https://github.com/innoveit/react-native-ble-manager/issues"
12
+ },
13
+ "keywords": [
14
+ "react-native",
15
+ "android",
16
+ "ios",
17
+ "ble",
18
+ "bluetooth",
19
+ "low energy"
20
+ ],
21
+ "license": "Apache-2.0",
22
+ "author": {
23
+ "name": "Innove",
24
+ "url": "https://github.com/innoveit"
25
+ },
26
+ "main": "dist/cjs/index.js",
27
+ "types": "dist/esm/index.d.ts",
28
+ "module": "dist/esm/index.js",
29
+ "react-native": "src/index.ts",
30
+ "files": [
31
+ "/dist",
32
+ "/src",
33
+ "/android",
34
+ "/ios",
35
+ "*.podspec",
36
+ "react-native.config.json",
37
+ "!ios/build",
38
+ "!android/build",
39
+ "!android/gradle",
40
+ "!android/gradlew",
41
+ "!android/gradlew.bat",
42
+ "!android/local.properties",
43
+ "!**/__tests__",
44
+ "!**/__fixtures__",
45
+ "!**/__mocks__",
46
+ "!**/.*"
47
+ ],
48
+ "scripts": {
49
+ "version": "git add -A",
50
+ "clean": "rimraf dist",
51
+ "type:check": "tsc -p tsconfig.json --noEmit",
52
+ "prepare": "npm run build",
53
+ "prebuild": "npm run clean",
54
+ "build:cjs": "tsc --module commonjs --outDir dist/cjs",
55
+ "build:esm": "tsc --outDir dist/esm",
56
+ "build": "npm run build:esm && npm run build:cjs",
57
+ "watch": "npm run build --watch",
58
+ "preversion": "npm run build",
59
+ "postversion": "git push --follow-tags"
60
+ },
61
+ "resolutions": {
62
+ "@types/react": "^18.2.44"
63
+ },
64
+ "peerDependencies": {
65
+ "react": "*",
66
+ "react-native": "*"
67
+ },
68
+ "devDependencies": {
69
+ "@commitlint/config-conventional": "^17.0.2",
70
+ "@react-native/eslint-config": "^0.73.1",
71
+ "@release-it/conventional-changelog": "^5.0.0",
72
+ "@types/jest": "^29.5.5",
73
+ "@types/react": "^18.2.44",
74
+ "commitlint": "^17.0.2",
75
+ "del-cli": "^5.1.0",
76
+ "eslint": "^8.51.0",
77
+ "eslint-config-prettier": "^9.0.0",
78
+ "eslint-plugin-prettier": "^5.0.1",
79
+ "jest": "^29.7.0",
80
+ "prettier": "^3.0.3",
81
+ "react": "18.2.0",
82
+ "react-native": "0.76.1",
83
+ "@react-native/gradle-plugin": "^0.75.1",
84
+ "turbo": "^1.10.7",
85
+ "typescript": "^5.2.2"
86
+ },
87
+ "eslintConfig": {
88
+ "root": true,
89
+ "extends": [
90
+ "@react-native",
91
+ "prettier"
92
+ ],
93
+ "rules": {
94
+ "react/react-in-jsx-scope": "off"
95
+ }
96
+ },
97
+ "eslintIgnore": [
98
+ "node_modules/",
99
+ "lib/"
100
+ ],
101
+ "codegenConfig": {
102
+ "name": "BleManagerSpec",
103
+ "type": "modules",
104
+ "jsSrcsDir": "src",
105
+ "android": {
106
+ "javaPackageName": "it.innove"
107
+ }
108
+ }
58
109
  }
@@ -0,0 +1,409 @@
1
+ import { TurboModule, TurboModuleRegistry } from 'react-native';
2
+ // @ts-ignore Ignore since it comes from codegen types.
3
+ import type { EventEmitter } from 'react-native/Libraries/Types/CodegenTypes';
4
+
5
+ /**
6
+ * This represents the Turbo Module version of react-native-ble-manager.
7
+ * This adds the codegen definition to react-native generate the c++ bindings on compile time.
8
+ * That should work only on 0.75 and higher.
9
+ * Don't remove it! and please modify with caution! Knowing that can create wrong bindings into jsi and break at compile or execution time.
10
+ * - Knowing that also every type needs to match the current Objective C++ and Java callbacks types and callbacks type definitions and be aware of the current differences between implementation in both platforms.
11
+ */
12
+ export interface Spec extends TurboModule {
13
+ start(options: Object, callback: (error: CallbackError) => void): void;
14
+
15
+ scan(
16
+ serviceUUIDStrings: string[],
17
+ timeoutSeconds: number,
18
+ allowDuplicates: boolean,
19
+ scanningOptions: Object,
20
+ callback: (error: CallbackError) => void
21
+ ): void;
22
+
23
+ stopScan(callback: (error: CallbackError) => void): void;
24
+
25
+ connect(
26
+ peripheralUUID: string,
27
+ options: Object,
28
+ callback: (error: CallbackError) => void
29
+ ): void;
30
+
31
+ disconnect(
32
+ peripheralUUID: string,
33
+ force: boolean,
34
+ callback: (error: CallbackError) => void
35
+ ): void;
36
+
37
+ retrieveServices(
38
+ peripheralUUID: string,
39
+ services: string[],
40
+ callback: (error: CallbackError, peripheral: PeripheralInfo) => void
41
+ ): void;
42
+
43
+ readRSSI(
44
+ peripheralUUID: string,
45
+ callback: (error: string | null, rssi: number) => void
46
+ ): void;
47
+
48
+ readDescriptor(
49
+ peripheralUUID: string,
50
+ serviceUUID: string,
51
+ characteristicUUID: string,
52
+ descriptorUUID: string,
53
+ callback: (error: string | null, data: number[]) => void
54
+ ): void;
55
+
56
+ writeDescriptor(
57
+ peripheralUUID: string,
58
+ serviceUUID: string,
59
+ characteristicUUID: string,
60
+ descriptorUUID: string,
61
+ data: object[],
62
+ callback: (error: string | null) => void
63
+ ): void;
64
+
65
+ getDiscoveredPeripherals(
66
+ callback: (error: string | null, result: Peripheral[] | null) => void
67
+ ): void;
68
+
69
+ checkState(callback: (state: BleState) => void): void;
70
+
71
+ write(
72
+ peripheralUUID: string,
73
+ serviceUUID: string,
74
+ characteristicUUID: string,
75
+ message: object[],
76
+ maxByteSize: number,
77
+ callback: (error: string | null) => void
78
+ ): void;
79
+
80
+ writeWithoutResponse(
81
+ peripheralUUID: string,
82
+ serviceUUID: string,
83
+ characteristicUUID: string,
84
+ message: object[],
85
+ maxByteSize: number,
86
+ queueSleepTime: number,
87
+ callback: (error: string | null) => void
88
+ ): void;
89
+
90
+ read(
91
+ peripheralUUID: string,
92
+ serviceUUID: string,
93
+ characteristicUUID: string,
94
+ callback: (error: string | null, data: number[]) => void
95
+ ): void;
96
+
97
+ startNotification(
98
+ peripheralUUID: string,
99
+ serviceUUID: string,
100
+ characteristicUUID: string,
101
+ callback: (error: string | null) => void
102
+ ): void;
103
+
104
+ stopNotification(
105
+ peripheralUUID: string,
106
+ serviceUUID: string,
107
+ characteristicUUID: string,
108
+ callback: (error: string | null) => void
109
+ ): void;
110
+
111
+ getConnectedPeripherals(
112
+ serviceUUIDStrings: string[],
113
+ callback: (error: string | null, result: Peripheral[] | null) => void
114
+ ): void;
115
+
116
+ isPeripheralConnected(
117
+ peripheralUUID: string,
118
+ callback: (error: Peripheral[]) => void
119
+ ): void;
120
+
121
+ isScanning(callback: (error: string | null, status: boolean) => void): void;
122
+
123
+ getMaximumWriteValueLengthForWithoutResponse(
124
+ peripheralUUID: string,
125
+ callback: (error: string | null, max: number) => void
126
+ ): void;
127
+
128
+ getMaximumWriteValueLengthForWithResponse(
129
+ deviceUUID: string,
130
+ callback: (error: string | null, max: number) => void
131
+ ): void;
132
+
133
+ enableBluetooth(callback: (error: string | null) => void): void;
134
+
135
+ getBondedPeripherals(
136
+ callback: (error: string | null, result: Peripheral[] | null) => void
137
+ ): void;
138
+
139
+ createBond(
140
+ peripheralUUID: string,
141
+ devicePin: string,
142
+ callback: (error: string | null) => void
143
+ ): void;
144
+
145
+ removeBond(
146
+ peripheralUUID: string,
147
+ callback: (error: string | null) => void
148
+ ): void;
149
+
150
+ removePeripheral(
151
+ peripheralUUID: string,
152
+ callback: (error: string | null) => void
153
+ ): void;
154
+
155
+ requestMTU(
156
+ peripheralUUID: string,
157
+ mtu: number,
158
+ callback: (error: string | null, mtu: number) => void
159
+ ): void;
160
+
161
+ requestConnectionPriority(
162
+ peripheralUUID: string,
163
+ connectionPriority: number,
164
+ callback: (error: string | null, status: boolean) => void
165
+ ): void;
166
+
167
+ refreshCache(
168
+ peripheralUUID: string,
169
+ callback: (error: string | null, result: boolean) => void
170
+ ): void;
171
+
172
+ setName(name: string): void;
173
+
174
+ getAssociatedPeripherals(
175
+ callback: (error: string | null, peripherals: Peripheral[] | null) => void
176
+ ): void;
177
+
178
+ removeAssociatedPeripheral(
179
+ peripheralUUID: string,
180
+ callback: (error: string | null) => void
181
+ ): void;
182
+
183
+ supportsCompanion(callback: (supports: boolean) => void): void;
184
+
185
+ companionScan(
186
+ serviceUUIDs: string[],
187
+ option: Object,
188
+ callback: (error: string | null, peripheral: Peripheral | null) => void
189
+ ): void;
190
+
191
+ /**
192
+ * Supported events.
193
+ */
194
+ readonly onDiscoverPeripheral: EventEmitter<Peripheral>;
195
+ readonly onStopScan: EventEmitter<EventStopScan>;
196
+ readonly onDidUpdateState: EventEmitter<EventDidUpdateState>;
197
+ readonly onDidUpdateValueForCharacteristic: EventEmitter<EventDidUpdateValueForCharacteristic>;
198
+ readonly onConnectPeripheral: EventEmitter<EventConnectPeripheral>;
199
+ readonly onDisconnectPeripheral: EventEmitter<EventDisconnectPeripheral>;
200
+ readonly onPeripheralDidBond: EventEmitter<EventPeripheralDidBond>;
201
+ readonly onCentralManagerWillRestoreState: EventEmitter<EventCentralManagerWillRestoreState>;
202
+ readonly onDidUpdateNotificationStateFor: EventEmitter<EventDidUpdateNotificationStateFor>;
203
+ readonly onCompanionPeripheral: EventEmitter<EventCompanionPeripheral>;
204
+ readonly onCompanionFailure: EventEmitter<EventCompanionFailure>;
205
+ }
206
+
207
+ export default TurboModuleRegistry.get<Spec>('BleManager') as Spec;
208
+
209
+ /** Turbo Module Type Definitions */
210
+ // These types are more loose than types.ts for simplicity and for codegen support.
211
+ // No interfaces or generics are currently supported.
212
+ export type BleScanCallbackType = number;
213
+ export type BleScanMatchCount = number;
214
+ export type BleScanMatchMode = number;
215
+ export type BleScanMode = number;
216
+ export type BleScanPhyMode = number;
217
+ export type CallbackError = string | null;
218
+ export type BleState = string;
219
+
220
+ export type Peripheral = {
221
+ id: string;
222
+ rssi: number;
223
+ name: string | null;
224
+ advertising: {
225
+ isConnectable?: boolean;
226
+ localName?: string | null;
227
+ rawData?: {
228
+ CDVType: number[];
229
+ bytes: number[];
230
+ data: string;
231
+ };
232
+ manufacturerData?:
233
+ | {
234
+ CDVType: number[];
235
+ bytes: number[];
236
+ data: string;
237
+ }[]
238
+ | null;
239
+ manufacturerRawData?: {
240
+ CDVType: number[];
241
+ bytes: number[];
242
+ data: string;
243
+ } | null;
244
+ serviceData?:
245
+ | {
246
+ CDVType: number[];
247
+ bytes: number[];
248
+ data: string;
249
+ }[]
250
+ | null;
251
+ serviceUUIDs?: string[];
252
+ txPowerLevel?: number;
253
+ };
254
+ };
255
+
256
+ export type PeripheralInfo = {
257
+ id: string;
258
+ rssi: number;
259
+ name: string | null;
260
+ advertising: {
261
+ isConnectable?: boolean;
262
+ localName?: string | null;
263
+ rawData?: {
264
+ CDVType: number[];
265
+ bytes: number[];
266
+ data: string;
267
+ } | null;
268
+ manufacturerData?:
269
+ | {
270
+ CDVType: number[];
271
+ bytes: number[];
272
+ data: string;
273
+ }[]
274
+ | null;
275
+ manufacturerRawData?: {
276
+ CDVType: number[];
277
+ bytes: number[];
278
+ data: string;
279
+ } | null;
280
+ serviceData?:
281
+ | {
282
+ CDVType: number[];
283
+ bytes: number[];
284
+ data: string;
285
+ }[]
286
+ | null;
287
+ serviceUUIDs?: string[];
288
+ txPowerLevel?: number;
289
+ };
290
+ serviceUUIDs?: string[];
291
+ characteristics?: {
292
+ properties: {
293
+ Broadcast?: string;
294
+ Read?: string;
295
+ WriteWithoutResponse?: string;
296
+ Write?: string;
297
+ Notify?: string;
298
+ Indicate?: string;
299
+ AuthenticatedSignedWrites?: string;
300
+ ExtendedProperties?: string;
301
+ NotifyEncryptionRequired?: string;
302
+ IndicateEncryptionRequired?: string;
303
+ };
304
+ characteristic: string;
305
+ service: string;
306
+ descriptors?: {
307
+ value: string;
308
+ uuid: string;
309
+ }[];
310
+ }[];
311
+ services?: { uuid: string }[];
312
+ };
313
+
314
+ export type EventStopScan = {
315
+ status: number;
316
+ };
317
+
318
+ export type EventDidUpdateState = {
319
+ state: string;
320
+ };
321
+
322
+ export type EventDiscoverPeripheral = {
323
+ id: string;
324
+ name: string;
325
+ rssi: number;
326
+ advertising: {
327
+ isConnectable: boolean;
328
+ serviceUUIDs: string[];
329
+ manufacturerData: number[];
330
+ serviceData: number[];
331
+ txPowerLevel: number;
332
+ rawData?: number | null;
333
+ };
334
+ };
335
+
336
+ export type EventDidUpdateValueForCharacteristic = {
337
+ value: number[];
338
+ peripheral: string;
339
+ characteristic: string;
340
+ service: string;
341
+ };
342
+
343
+ export type EventConnectPeripheral = {
344
+ peripheral: string;
345
+ status?: number | null;
346
+ };
347
+
348
+ export type EventDisconnectPeripheral = {
349
+ peripheral: string;
350
+ status?: number | null;
351
+ domain?: string | null;
352
+ code?: number | null;
353
+ };
354
+
355
+ export type EventPeripheralDidBond = {
356
+ id: string;
357
+ name: string;
358
+ rssi: number;
359
+ advertising: {
360
+ isConnectable: boolean;
361
+ serviceUUIDs: string[];
362
+ manufacturerData: number[];
363
+ serviceData: number[];
364
+ txPowerLevel: number;
365
+ rawData?: number | null;
366
+ };
367
+ };
368
+
369
+ export type EventCentralManagerWillRestoreState = {
370
+ peripherals: {
371
+ id: string;
372
+ name: string;
373
+ rssi: number;
374
+ advertising: {
375
+ isConnectable: boolean;
376
+ serviceUUIDs: string[];
377
+ manufacturerData: number[];
378
+ serviceData: number[];
379
+ txPowerLevel: number;
380
+ rawData?: number | null;
381
+ };
382
+ }[];
383
+ };
384
+
385
+ export type EventDidUpdateNotificationStateFor = {
386
+ peripheral: string;
387
+ characteristic: string;
388
+ isNotifying: boolean;
389
+ domain?: string | null;
390
+ code?: number | null;
391
+ };
392
+
393
+ export type EventCompanionPeripheral = {
394
+ id: string;
395
+ name: string;
396
+ rssi: number;
397
+ advertising: {
398
+ isConnectable: boolean;
399
+ serviceUUIDs: string[];
400
+ manufacturerData: number[];
401
+ serviceData: number[];
402
+ txPowerLevel: number;
403
+ rawData?: number | null;
404
+ };
405
+ };
406
+
407
+ export type EventCompanionFailure = {
408
+ error: string;
409
+ };