react-native-ble-nitro 1.0.0-alpha.1

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 (73) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +298 -0
  3. package/android/build.gradle +55 -0
  4. package/android/src/main/AndroidManifest.xml +23 -0
  5. package/android/src/main/kotlin/co/zyke/ble/BleNitroBleManager.kt +651 -0
  6. package/android/src/main/kotlin/co/zyke/ble/BleNitroPackage.kt +37 -0
  7. package/ios/BleNitro.podspec +37 -0
  8. package/ios/BleNitroBleManager.swift +509 -0
  9. package/ios/BleNitroModule.swift +31 -0
  10. package/lib/BleManagerCompatFactory.d.ts +53 -0
  11. package/lib/BleManagerCompatFactory.js +191 -0
  12. package/lib/BleManagerFactory.d.ts +12 -0
  13. package/lib/BleManagerFactory.js +22 -0
  14. package/lib/compatibility/constants.d.ts +49 -0
  15. package/lib/compatibility/constants.js +50 -0
  16. package/lib/compatibility/deviceWrapper.d.ts +99 -0
  17. package/lib/compatibility/deviceWrapper.js +259 -0
  18. package/lib/compatibility/enums.d.ts +43 -0
  19. package/lib/compatibility/enums.js +124 -0
  20. package/lib/compatibility/index.d.ts +11 -0
  21. package/lib/compatibility/index.js +12 -0
  22. package/lib/compatibility/serviceData.d.ts +51 -0
  23. package/lib/compatibility/serviceData.js +70 -0
  24. package/lib/errors/BleError.d.ts +59 -0
  25. package/lib/errors/BleError.js +120 -0
  26. package/lib/index.d.ts +7 -0
  27. package/lib/index.js +12 -0
  28. package/lib/specs/BleManager.nitro.d.ts +36 -0
  29. package/lib/specs/BleManager.nitro.js +1 -0
  30. package/lib/specs/Characteristic.nitro.d.ts +26 -0
  31. package/lib/specs/Characteristic.nitro.js +1 -0
  32. package/lib/specs/Descriptor.nitro.d.ts +17 -0
  33. package/lib/specs/Descriptor.nitro.js +1 -0
  34. package/lib/specs/Device.nitro.d.ts +37 -0
  35. package/lib/specs/Device.nitro.js +1 -0
  36. package/lib/specs/Service.nitro.d.ts +19 -0
  37. package/lib/specs/Service.nitro.js +1 -0
  38. package/lib/specs/types.d.ts +228 -0
  39. package/lib/specs/types.js +146 -0
  40. package/lib/utils/base64.d.ts +25 -0
  41. package/lib/utils/base64.js +80 -0
  42. package/lib/utils/index.d.ts +2 -0
  43. package/lib/utils/index.js +2 -0
  44. package/lib/utils/uuid.d.ts +9 -0
  45. package/lib/utils/uuid.js +37 -0
  46. package/nitro.json +15 -0
  47. package/package.json +102 -0
  48. package/plugin/build/index.d.ts +28 -0
  49. package/plugin/build/index.js +29 -0
  50. package/plugin/build/withBleNitro.d.ts +31 -0
  51. package/plugin/build/withBleNitro.js +87 -0
  52. package/react-native.config.js +13 -0
  53. package/src/BleManagerCompatFactory.ts +373 -0
  54. package/src/BleManagerFactory.ts +30 -0
  55. package/src/__tests__/BleManager.test.ts +327 -0
  56. package/src/__tests__/compatibility/deviceWrapper.test.ts +563 -0
  57. package/src/__tests__/compatibility/enums.test.ts +254 -0
  58. package/src/compatibility/constants.ts +71 -0
  59. package/src/compatibility/deviceWrapper.ts +427 -0
  60. package/src/compatibility/enums.ts +160 -0
  61. package/src/compatibility/index.ts +24 -0
  62. package/src/compatibility/serviceData.ts +85 -0
  63. package/src/errors/BleError.ts +193 -0
  64. package/src/index.ts +30 -0
  65. package/src/specs/BleManager.nitro.ts +152 -0
  66. package/src/specs/Characteristic.nitro.ts +61 -0
  67. package/src/specs/Descriptor.nitro.ts +28 -0
  68. package/src/specs/Device.nitro.ts +104 -0
  69. package/src/specs/Service.nitro.ts +64 -0
  70. package/src/specs/types.ts +259 -0
  71. package/src/utils/base64.ts +80 -0
  72. package/src/utils/index.ts +2 -0
  73. package/src/utils/uuid.ts +45 -0
@@ -0,0 +1,193 @@
1
+ import {
2
+ BleErrorCode,
3
+ BleATTErrorCode,
4
+ BleIOSErrorCode,
5
+ BleAndroidErrorCode
6
+ } from '../specs/types';
7
+ import type {
8
+ NativeBleError,
9
+ BleErrorCodeMessageMapping
10
+ } from '../specs/types';
11
+
12
+ /**
13
+ * Default error messages for BLE error codes
14
+ * Maintains compatibility with react-native-ble-plx error messages
15
+ */
16
+ const BleErrorCodeMessage: BleErrorCodeMessageMapping = {
17
+ [BleErrorCode.UnknownError]: 'Unknown error occurred',
18
+ [BleErrorCode.BluetoothManagerDestroyed]: 'BLE Manager was destroyed',
19
+ [BleErrorCode.OperationCancelled]: 'Operation was cancelled',
20
+ [BleErrorCode.OperationTimedOut]: 'Operation timed out',
21
+ [BleErrorCode.OperationStartFailed]: 'Operation could not be started',
22
+ [BleErrorCode.InvalidIdentifiers]: 'Invalid identifiers provided',
23
+ [BleErrorCode.BluetoothUnsupported]: 'Bluetooth is not supported on this device',
24
+ [BleErrorCode.BluetoothUnauthorized]: 'App is not authorized to use Bluetooth',
25
+ [BleErrorCode.BluetoothPoweredOff]: 'Bluetooth is powered off',
26
+ [BleErrorCode.BluetoothInUnknownState]: 'Bluetooth is in unknown state',
27
+ [BleErrorCode.BluetoothResetting]: 'Bluetooth is resetting',
28
+ [BleErrorCode.BluetoothStateChangeFailed]: 'Bluetooth state change failed',
29
+ [BleErrorCode.DeviceConnectionFailed]: 'Device connection failed',
30
+ [BleErrorCode.DeviceDisconnected]: 'Device was disconnected',
31
+ [BleErrorCode.DeviceRSSIReadFailed]: 'Failed to read RSSI',
32
+ [BleErrorCode.DeviceAlreadyConnected]: 'Device is already connected',
33
+ [BleErrorCode.DeviceNotFound]: 'Device not found',
34
+ [BleErrorCode.DeviceNotConnected]: 'Device is not connected',
35
+ [BleErrorCode.DeviceMTUChangeFailed]: 'Failed to change MTU',
36
+ [BleErrorCode.ServicesDiscoveryFailed]: 'Services discovery failed',
37
+ [BleErrorCode.IncludedServicesDiscoveryFailed]: 'Included services discovery failed',
38
+ [BleErrorCode.ServiceNotFound]: 'Service not found',
39
+ [BleErrorCode.ServicesNotDiscovered]: 'Services not discovered',
40
+ [BleErrorCode.CharacteristicsDiscoveryFailed]: 'Characteristics discovery failed',
41
+ [BleErrorCode.CharacteristicWriteFailed]: 'Characteristic write failed',
42
+ [BleErrorCode.CharacteristicReadFailed]: 'Characteristic read failed',
43
+ [BleErrorCode.CharacteristicNotifyChangeFailed]: 'Failed to change characteristic notification state',
44
+ [BleErrorCode.CharacteristicNotFound]: 'Characteristic not found',
45
+ [BleErrorCode.CharacteristicsNotDiscovered]: 'Characteristics not discovered',
46
+ [BleErrorCode.CharacteristicInvalidDataFormat]: 'Invalid characteristic data format',
47
+ [BleErrorCode.DescriptorsDiscoveryFailed]: 'Descriptors discovery failed',
48
+ [BleErrorCode.DescriptorWriteFailed]: 'Descriptor write failed',
49
+ [BleErrorCode.DescriptorReadFailed]: 'Descriptor read failed',
50
+ [BleErrorCode.DescriptorNotFound]: 'Descriptor not found',
51
+ [BleErrorCode.DescriptorsNotDiscovered]: 'Descriptors not discovered',
52
+ [BleErrorCode.DescriptorInvalidDataFormat]: 'Invalid descriptor data format',
53
+ [BleErrorCode.DescriptorWriteNotAllowed]: 'Descriptor write not allowed',
54
+ [BleErrorCode.ScanStartFailed]: 'Failed to start scan',
55
+ [BleErrorCode.LocationServicesDisabled]: 'Location services are disabled'
56
+ };
57
+
58
+ /**
59
+ * BleError class that maintains 100% compatibility with react-native-ble-plx
60
+ * Contains additional properties for platform-independent error handling
61
+ */
62
+ export class BleError extends Error {
63
+ /**
64
+ * Platform independent error code
65
+ */
66
+ public readonly errorCode: BleErrorCode;
67
+
68
+ /**
69
+ * Platform independent error code related to ATT errors
70
+ */
71
+ public readonly attErrorCode: BleATTErrorCode | null;
72
+
73
+ /**
74
+ * iOS specific error code (if not an ATT error)
75
+ */
76
+ public readonly iosErrorCode: BleIOSErrorCode | null;
77
+
78
+ /**
79
+ * Android specific error code (if not an ATT error)
80
+ */
81
+ public readonly androidErrorCode: BleAndroidErrorCode | null;
82
+
83
+ /**
84
+ * Platform specific error message
85
+ */
86
+ public readonly reason: string | null;
87
+
88
+ /**
89
+ * Device ID associated with error (if applicable)
90
+ */
91
+ public readonly deviceID?: string;
92
+
93
+ /**
94
+ * Service UUID associated with error (if applicable)
95
+ */
96
+ public readonly serviceUUID?: string;
97
+
98
+ /**
99
+ * Characteristic UUID associated with error (if applicable)
100
+ */
101
+ public readonly characteristicUUID?: string;
102
+
103
+ /**
104
+ * Descriptor UUID associated with error (if applicable)
105
+ */
106
+ public readonly descriptorUUID?: string;
107
+
108
+ /**
109
+ * Internal error message for debugging
110
+ */
111
+ public readonly internalMessage?: string;
112
+
113
+ constructor(
114
+ nativeBleError: NativeBleError | string,
115
+ errorMessageMapping: BleErrorCodeMessageMapping = BleErrorCodeMessage
116
+ ) {
117
+ if (typeof nativeBleError === 'string') {
118
+ // Simple string error case
119
+ super(nativeBleError);
120
+ this.errorCode = BleErrorCode.UnknownError;
121
+ this.attErrorCode = null;
122
+ this.iosErrorCode = null;
123
+ this.androidErrorCode = null;
124
+ this.reason = nativeBleError;
125
+ return;
126
+ }
127
+
128
+ // Native BLE error case
129
+ const errorMessage = errorMessageMapping[nativeBleError.errorCode] || 'Unknown BLE error';
130
+ super(errorMessage);
131
+
132
+ this.errorCode = nativeBleError.errorCode;
133
+ this.attErrorCode = nativeBleError.attErrorCode;
134
+ this.iosErrorCode = nativeBleError.iosErrorCode;
135
+ this.androidErrorCode = nativeBleError.androidErrorCode;
136
+ this.reason = nativeBleError.reason;
137
+ if (nativeBleError.deviceID !== undefined) this.deviceID = nativeBleError.deviceID;
138
+ if (nativeBleError.serviceUUID !== undefined) this.serviceUUID = nativeBleError.serviceUUID;
139
+ if (nativeBleError.characteristicUUID !== undefined) this.characteristicUUID = nativeBleError.characteristicUUID;
140
+ if (nativeBleError.descriptorUUID !== undefined) this.descriptorUUID = nativeBleError.descriptorUUID;
141
+ if (nativeBleError.internalMessage !== undefined) this.internalMessage = nativeBleError.internalMessage;
142
+
143
+ // Set proper prototype chain
144
+ Object.setPrototypeOf(this, BleError.prototype);
145
+ this.name = 'BleError';
146
+ }
147
+
148
+ /**
149
+ * Returns a string representation of the error with all relevant information
150
+ */
151
+ public toString(): string {
152
+ const parts = [
153
+ `BleError: ${this.message}`,
154
+ `Error code: ${this.errorCode}`
155
+ ];
156
+
157
+ if (this.attErrorCode !== null) {
158
+ parts.push(`ATT error code: ${this.attErrorCode}`);
159
+ }
160
+
161
+ if (this.iosErrorCode !== null) {
162
+ parts.push(`iOS error code: ${this.iosErrorCode}`);
163
+ }
164
+
165
+ if (this.androidErrorCode !== null) {
166
+ parts.push(`Android error code: ${this.androidErrorCode}`);
167
+ }
168
+
169
+ if (this.reason) {
170
+ parts.push(`Reason: ${this.reason}`);
171
+ }
172
+
173
+ if (this.deviceID) {
174
+ parts.push(`Device ID: ${this.deviceID}`);
175
+ }
176
+
177
+ if (this.serviceUUID) {
178
+ parts.push(`Service UUID: ${this.serviceUUID}`);
179
+ }
180
+
181
+ if (this.characteristicUUID) {
182
+ parts.push(`Characteristic UUID: ${this.characteristicUUID}`);
183
+ }
184
+
185
+ if (this.descriptorUUID) {
186
+ parts.push(`Descriptor UUID: ${this.descriptorUUID}`);
187
+ }
188
+
189
+ return parts.join(', ');
190
+ }
191
+ }
192
+
193
+ export { BleErrorCodeMessage };
package/src/index.ts ADDED
@@ -0,0 +1,30 @@
1
+ // Export compatibility layer types and constants
2
+ export * from './compatibility/constants';
3
+
4
+ // Export utility functions
5
+ export * from './utils';
6
+
7
+ // Export the main BleManager instance with compatibility wrapper
8
+ export { BleManagerCompat as BleManager, createBleManagerCompat as createBleManager } from './BleManagerCompatFactory';
9
+
10
+ // Export error handling utilities
11
+ export * from './errors/BleError';
12
+
13
+ // Export device wrapper for compatibility
14
+ export { DeviceWrapper as Device } from './compatibility/deviceWrapper';
15
+
16
+ // Export interfaces for TypeScript (but not runtime values)
17
+ export type {
18
+ BleManagerOptions,
19
+ ScanOptions,
20
+ ConnectionOptions,
21
+ NativeBleError,
22
+ NativeDevice,
23
+ NativeService,
24
+ NativeCharacteristic,
25
+ NativeDescriptor,
26
+ Subscription
27
+ } from './specs/types';
28
+
29
+ // Re-export react-native-ble-plx compatible API
30
+ export { fullUUID } from './utils/uuid';
@@ -0,0 +1,152 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+ import type {
3
+ State,
4
+ LogLevel,
5
+ UUID,
6
+ DeviceId,
7
+ TransactionId,
8
+ ConnectionPriority,
9
+ ScanOptions,
10
+ ConnectionOptions,
11
+ BleManagerOptions,
12
+ StateListener,
13
+ DeviceScanListener,
14
+ DeviceDisconnectedListener,
15
+ CharacteristicMonitorListener,
16
+ CharacteristicSubscriptionType,
17
+ NativeDevice,
18
+ NativeService,
19
+ NativeCharacteristic,
20
+ NativeDescriptor,
21
+ NativeBleError,
22
+ BleRestoredState,
23
+ Base64,
24
+ Subscription
25
+ } from './types';
26
+
27
+ export interface BleManager extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
28
+ // Lifecycle
29
+ destroy(): Promise<void>;
30
+
31
+ // Common operations
32
+ setLogLevel(logLevel: LogLevel): Promise<LogLevel>;
33
+ logLevel(): Promise<LogLevel>;
34
+ cancelTransaction(transactionId: TransactionId): Promise<void>;
35
+
36
+ // State management
37
+ enable(transactionId?: TransactionId): Promise<void>;
38
+ disable(transactionId?: TransactionId): Promise<void>;
39
+ state(): Promise<State>;
40
+ onStateChange(listener: StateListener, emitCurrentState?: boolean): Subscription;
41
+
42
+ // Device scanning
43
+ startDeviceScan(
44
+ uuids: UUID[] | null,
45
+ options: ScanOptions | null,
46
+ listener: DeviceScanListener
47
+ ): Promise<void>;
48
+ stopDeviceScan(): Promise<void>;
49
+
50
+ // Connection priority and RSSI/MTU requests
51
+ requestConnectionPriorityForDevice(
52
+ deviceIdentifier: DeviceId,
53
+ connectionPriority: ConnectionPriority,
54
+ transactionId?: TransactionId
55
+ ): Promise<NativeDevice>;
56
+
57
+ readRSSIForDevice(
58
+ deviceIdentifier: DeviceId,
59
+ transactionId?: TransactionId
60
+ ): Promise<NativeDevice>;
61
+
62
+ requestMTUForDevice(
63
+ deviceIdentifier: DeviceId,
64
+ mtu: number,
65
+ transactionId?: TransactionId
66
+ ): Promise<NativeDevice>;
67
+
68
+ // Connection management
69
+ devices(deviceIdentifiers: DeviceId[]): Promise<NativeDevice[]>;
70
+ connectedDevices(serviceUUIDs: UUID[]): Promise<NativeDevice[]>;
71
+ connectToDevice(
72
+ deviceIdentifier: DeviceId,
73
+ options?: ConnectionOptions
74
+ ): Promise<NativeDevice>;
75
+ cancelDeviceConnection(deviceIdentifier: DeviceId): Promise<NativeDevice>;
76
+ onDeviceDisconnected(
77
+ deviceIdentifier: DeviceId,
78
+ listener: DeviceDisconnectedListener
79
+ ): Subscription;
80
+ isDeviceConnected(deviceIdentifier: DeviceId): Promise<boolean>;
81
+
82
+ // Service and characteristic discovery
83
+ discoverAllServicesAndCharacteristicsForDevice(
84
+ deviceIdentifier: DeviceId,
85
+ transactionId?: TransactionId
86
+ ): Promise<NativeDevice>;
87
+
88
+ // Service operations
89
+ servicesForDevice(deviceIdentifier: DeviceId): Promise<NativeService[]>;
90
+
91
+ // Characteristic operations
92
+ characteristicsForDevice(
93
+ deviceIdentifier: DeviceId,
94
+ serviceUUID: UUID
95
+ ): Promise<NativeCharacteristic[]>;
96
+
97
+ readCharacteristicForDevice(
98
+ deviceIdentifier: DeviceId,
99
+ serviceUUID: UUID,
100
+ characteristicUUID: UUID,
101
+ transactionId?: TransactionId
102
+ ): Promise<NativeCharacteristic>;
103
+
104
+ writeCharacteristicWithResponseForDevice(
105
+ deviceIdentifier: DeviceId,
106
+ serviceUUID: UUID,
107
+ characteristicUUID: UUID,
108
+ base64Value: Base64,
109
+ transactionId?: TransactionId
110
+ ): Promise<NativeCharacteristic>;
111
+
112
+ writeCharacteristicWithoutResponseForDevice(
113
+ deviceIdentifier: DeviceId,
114
+ serviceUUID: UUID,
115
+ characteristicUUID: UUID,
116
+ base64Value: Base64,
117
+ transactionId?: TransactionId
118
+ ): Promise<NativeCharacteristic>;
119
+
120
+ monitorCharacteristicForDevice(
121
+ deviceIdentifier: DeviceId,
122
+ serviceUUID: UUID,
123
+ characteristicUUID: UUID,
124
+ listener: CharacteristicMonitorListener,
125
+ transactionId?: TransactionId,
126
+ subscriptionType?: CharacteristicSubscriptionType
127
+ ): Subscription;
128
+
129
+ // Descriptor operations
130
+ descriptorsForDevice(
131
+ deviceIdentifier: DeviceId,
132
+ serviceUUID: UUID,
133
+ characteristicUUID: UUID
134
+ ): Promise<NativeDescriptor[]>;
135
+
136
+ readDescriptorForDevice(
137
+ deviceIdentifier: DeviceId,
138
+ serviceUUID: UUID,
139
+ characteristicUUID: UUID,
140
+ descriptorUUID: UUID,
141
+ transactionId?: TransactionId
142
+ ): Promise<NativeDescriptor>;
143
+
144
+ writeDescriptorForDevice(
145
+ deviceIdentifier: DeviceId,
146
+ serviceUUID: UUID,
147
+ characteristicUUID: UUID,
148
+ descriptorUUID: UUID,
149
+ valueBase64: Base64,
150
+ transactionId?: TransactionId
151
+ ): Promise<NativeDescriptor>;
152
+ }
@@ -0,0 +1,61 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+ import type {
3
+ Identifier,
4
+ UUID,
5
+ DeviceId,
6
+ Base64,
7
+ TransactionId,
8
+ CharacteristicSubscriptionType,
9
+ NativeDescriptor,
10
+ CharacteristicMonitorListener,
11
+ Subscription
12
+ } from './types';
13
+
14
+ export interface Characteristic extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
15
+ // Characteristic properties
16
+ readonly id: Identifier;
17
+ readonly uuid: UUID;
18
+ readonly serviceID: Identifier;
19
+ readonly serviceUUID: UUID;
20
+ readonly deviceID: DeviceId;
21
+ readonly isReadable: boolean;
22
+ readonly isWritableWithResponse: boolean;
23
+ readonly isWritableWithoutResponse: boolean;
24
+ readonly isNotifiable: boolean;
25
+ readonly isNotifying: boolean;
26
+ readonly isIndicatable: boolean;
27
+ readonly value: Base64 | null;
28
+
29
+ // Characteristic operations
30
+ read(transactionId?: TransactionId): Promise<Characteristic>;
31
+
32
+ writeWithResponse(
33
+ valueBase64: Base64,
34
+ transactionId?: TransactionId
35
+ ): Promise<Characteristic>;
36
+
37
+ writeWithoutResponse(
38
+ valueBase64: Base64,
39
+ transactionId?: TransactionId
40
+ ): Promise<Characteristic>;
41
+
42
+ monitor(
43
+ listener: CharacteristicMonitorListener,
44
+ transactionId?: TransactionId,
45
+ subscriptionType?: CharacteristicSubscriptionType
46
+ ): Subscription;
47
+
48
+ // Descriptor operations
49
+ descriptors(): Promise<NativeDescriptor[]>;
50
+
51
+ readDescriptor(
52
+ descriptorUUID: UUID,
53
+ transactionId?: TransactionId
54
+ ): Promise<NativeDescriptor>;
55
+
56
+ writeDescriptor(
57
+ descriptorUUID: UUID,
58
+ valueBase64: Base64,
59
+ transactionId?: TransactionId
60
+ ): Promise<NativeDescriptor>;
61
+ }
@@ -0,0 +1,28 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+ import type {
3
+ Identifier,
4
+ UUID,
5
+ DeviceId,
6
+ Base64,
7
+ TransactionId
8
+ } from './types';
9
+
10
+ export interface Descriptor extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
11
+ // Descriptor properties
12
+ readonly id: Identifier;
13
+ readonly uuid: UUID;
14
+ readonly characteristicID: Identifier;
15
+ readonly characteristicUUID: UUID;
16
+ readonly serviceID: Identifier;
17
+ readonly serviceUUID: UUID;
18
+ readonly deviceID: DeviceId;
19
+ readonly value: Base64 | null;
20
+
21
+ // Descriptor operations
22
+ read(transactionId?: TransactionId): Promise<Descriptor>;
23
+
24
+ write(
25
+ valueBase64: Base64,
26
+ transactionId?: TransactionId
27
+ ): Promise<Descriptor>;
28
+ }
@@ -0,0 +1,104 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+ import type {
3
+ DeviceId,
4
+ UUID,
5
+ Base64,
6
+ TransactionId,
7
+ ConnectionPriority,
8
+ ConnectionOptions,
9
+ CharacteristicSubscriptionType,
10
+ ServiceDataEntry,
11
+ NativeDevice,
12
+ NativeService,
13
+ NativeCharacteristic,
14
+ NativeDescriptor,
15
+ DeviceDisconnectedListener,
16
+ CharacteristicMonitorListener,
17
+ Subscription
18
+ } from './types';
19
+
20
+ export interface Device extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
21
+ // Device properties
22
+ readonly id: DeviceId;
23
+ readonly deviceName?: string | null;
24
+ readonly rssi?: number | null;
25
+ readonly mtu: number;
26
+ readonly manufacturerData?: Base64 | null;
27
+ readonly rawScanRecord: Base64;
28
+ readonly serviceData?: ServiceDataEntry[] | null;
29
+ readonly serviceUUIDs?: UUID[] | null;
30
+ readonly localName?: string | null;
31
+ readonly txPowerLevel?: number | null;
32
+ readonly solicitedServiceUUIDs?: UUID[] | null;
33
+ readonly isConnectable?: boolean | null;
34
+ readonly overflowServiceUUIDs?: UUID[] | null;
35
+
36
+ // Connection management
37
+ requestConnectionPriority(
38
+ connectionPriority: ConnectionPriority,
39
+ transactionId?: TransactionId
40
+ ): Promise<NativeDevice>;
41
+
42
+ readRSSI(transactionId?: TransactionId): Promise<NativeDevice>;
43
+ requestMTU(mtu: number, transactionId?: TransactionId): Promise<NativeDevice>;
44
+ connect(options?: ConnectionOptions): Promise<NativeDevice>;
45
+ cancelConnection(): Promise<NativeDevice>;
46
+ isConnected(): Promise<boolean>;
47
+ onDisconnected(listener: DeviceDisconnectedListener): Subscription;
48
+
49
+ // Service discovery
50
+ discoverAllServicesAndCharacteristics(transactionId?: TransactionId): Promise<NativeDevice>;
51
+ services(): Promise<NativeService[]>;
52
+
53
+ // Characteristic operations
54
+ characteristicsForService(serviceUUID: UUID): Promise<NativeCharacteristic[]>;
55
+
56
+ readCharacteristicForService(
57
+ serviceUUID: UUID,
58
+ characteristicUUID: UUID,
59
+ transactionId?: TransactionId
60
+ ): Promise<NativeCharacteristic>;
61
+
62
+ writeCharacteristicWithResponseForService(
63
+ serviceUUID: UUID,
64
+ characteristicUUID: UUID,
65
+ valueBase64: Base64,
66
+ transactionId?: TransactionId
67
+ ): Promise<NativeCharacteristic>;
68
+
69
+ writeCharacteristicWithoutResponseForService(
70
+ serviceUUID: UUID,
71
+ characteristicUUID: UUID,
72
+ valueBase64: Base64,
73
+ transactionId?: TransactionId
74
+ ): Promise<NativeCharacteristic>;
75
+
76
+ monitorCharacteristicForService(
77
+ serviceUUID: UUID,
78
+ characteristicUUID: UUID,
79
+ listener: CharacteristicMonitorListener,
80
+ transactionId?: TransactionId,
81
+ subscriptionType?: CharacteristicSubscriptionType
82
+ ): Subscription;
83
+
84
+ // Descriptor operations
85
+ descriptorsForService(
86
+ serviceUUID: UUID,
87
+ characteristicUUID: UUID
88
+ ): Promise<NativeDescriptor[]>;
89
+
90
+ readDescriptorForService(
91
+ serviceUUID: UUID,
92
+ characteristicUUID: UUID,
93
+ descriptorUUID: UUID,
94
+ transactionId?: TransactionId
95
+ ): Promise<NativeDescriptor>;
96
+
97
+ writeDescriptorForService(
98
+ serviceUUID: UUID,
99
+ characteristicUUID: UUID,
100
+ descriptorUUID: UUID,
101
+ valueBase64: Base64,
102
+ transactionId?: TransactionId
103
+ ): Promise<NativeDescriptor>;
104
+ }
@@ -0,0 +1,64 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+ import type {
3
+ Identifier,
4
+ UUID,
5
+ DeviceId,
6
+ Base64,
7
+ TransactionId,
8
+ CharacteristicSubscriptionType,
9
+ NativeCharacteristic,
10
+ NativeDescriptor,
11
+ CharacteristicMonitorListener,
12
+ Subscription
13
+ } from './types';
14
+
15
+ export interface Service extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
16
+ // Service properties
17
+ readonly id: Identifier;
18
+ readonly uuid: UUID;
19
+ readonly deviceID: DeviceId;
20
+ readonly isPrimary: boolean;
21
+
22
+ // Characteristic operations
23
+ characteristics(): Promise<NativeCharacteristic[]>;
24
+
25
+ readCharacteristic(
26
+ characteristicUUID: UUID,
27
+ transactionId?: TransactionId
28
+ ): Promise<NativeCharacteristic>;
29
+
30
+ writeCharacteristicWithResponse(
31
+ characteristicUUID: UUID,
32
+ valueBase64: Base64,
33
+ transactionId?: TransactionId
34
+ ): Promise<NativeCharacteristic>;
35
+
36
+ writeCharacteristicWithoutResponse(
37
+ characteristicUUID: UUID,
38
+ valueBase64: Base64,
39
+ transactionId?: TransactionId
40
+ ): Promise<NativeCharacteristic>;
41
+
42
+ monitorCharacteristic(
43
+ characteristicUUID: UUID,
44
+ listener: CharacteristicMonitorListener,
45
+ transactionId?: TransactionId,
46
+ subscriptionType?: CharacteristicSubscriptionType
47
+ ): Subscription;
48
+
49
+ // Descriptor operations
50
+ descriptorsForCharacteristic(characteristicUUID: UUID): Promise<NativeDescriptor[]>;
51
+
52
+ readDescriptorForCharacteristic(
53
+ characteristicUUID: UUID,
54
+ descriptorUUID: UUID,
55
+ transactionId?: TransactionId
56
+ ): Promise<NativeDescriptor>;
57
+
58
+ writeDescriptorForCharacteristic(
59
+ characteristicUUID: UUID,
60
+ descriptorUUID: UUID,
61
+ valueBase64: Base64,
62
+ transactionId?: TransactionId
63
+ ): Promise<NativeDescriptor>;
64
+ }