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,191 @@
1
+ /**
2
+ * BleManager Compatibility Factory
3
+ *
4
+ * Creates BleManager instances with full react-native-ble-plx compatibility
5
+ * by wrapping the Nitro implementation with compatibility shims
6
+ */
7
+ import { createBleManager } from './BleManagerFactory';
8
+ import { DeviceWrapper } from './compatibility/deviceWrapper';
9
+ import { stateToString, logLevelToString, normalizeLogLevel, normalizeCharacteristicSubscriptionType } from './compatibility/enums';
10
+ /**
11
+ * BleManager wrapper that provides react-native-ble-plx compatibility
12
+ */
13
+ export class BleManagerCompat {
14
+ constructor(options) {
15
+ this.bleManager = createBleManager(options);
16
+ }
17
+ // Lifecycle
18
+ async destroy() {
19
+ return await this.bleManager.destroy();
20
+ }
21
+ // Common operations with compatibility
22
+ async setLogLevel(logLevel) {
23
+ const normalizedLogLevel = normalizeLogLevel(logLevel);
24
+ const result = await this.bleManager.setLogLevel(normalizedLogLevel);
25
+ return logLevelToString(result);
26
+ }
27
+ async logLevel() {
28
+ const result = await this.bleManager.logLevel();
29
+ return logLevelToString(result);
30
+ }
31
+ async cancelTransaction(transactionId) {
32
+ return await this.bleManager.cancelTransaction(transactionId);
33
+ }
34
+ // State management with string conversion
35
+ async enable(transactionId) {
36
+ await this.bleManager.enable(transactionId);
37
+ return this;
38
+ }
39
+ async disable(transactionId) {
40
+ await this.bleManager.disable(transactionId);
41
+ return this;
42
+ }
43
+ async state() {
44
+ const result = await this.bleManager.state();
45
+ return stateToString(result);
46
+ }
47
+ onStateChange(listener, emitCurrentState) {
48
+ return this.bleManager.onStateChange((state) => {
49
+ listener(stateToString(state));
50
+ }, emitCurrentState);
51
+ }
52
+ // Device scanning with compatibility wrappers
53
+ async startDeviceScan(uuids, options, listener) {
54
+ return await this.bleManager.startDeviceScan(uuids, options, (error, device) => {
55
+ listener(error, device ? new DeviceWrapper(this.createDeviceFromNative(device)) : null);
56
+ });
57
+ }
58
+ async stopDeviceScan() {
59
+ return await this.bleManager.stopDeviceScan();
60
+ }
61
+ // Connection management
62
+ async connectToDevice(deviceIdentifier, options) {
63
+ // Provide defaults for Nitro's required fields
64
+ const connectionOptions = {
65
+ autoConnect: options?.autoConnect ?? false,
66
+ requestMTU: options?.requestMTU ?? 23,
67
+ timeout: options?.timeout ?? 0,
68
+ };
69
+ const result = await this.bleManager.connectToDevice(deviceIdentifier, connectionOptions);
70
+ return new DeviceWrapper(this.createDeviceFromNative(result));
71
+ }
72
+ async cancelDeviceConnection(deviceIdentifier) {
73
+ const result = await this.bleManager.cancelDeviceConnection(deviceIdentifier);
74
+ return new DeviceWrapper(this.createDeviceFromNative(result));
75
+ }
76
+ async isDeviceConnected(deviceIdentifier) {
77
+ return await this.bleManager.isDeviceConnected(deviceIdentifier);
78
+ }
79
+ onDeviceDisconnected(deviceIdentifier, listener) {
80
+ return this.bleManager.onDeviceDisconnected(deviceIdentifier, (error, device) => {
81
+ listener(error, device ? new DeviceWrapper(this.createDeviceFromNative(device)) : null);
82
+ });
83
+ }
84
+ // Device discovery
85
+ async devices(deviceIdentifiers) {
86
+ const result = await this.bleManager.devices(deviceIdentifiers);
87
+ return result.map(device => new DeviceWrapper(this.createDeviceFromNative(device)));
88
+ }
89
+ async connectedDevices(serviceUUIDs) {
90
+ const result = await this.bleManager.connectedDevices(serviceUUIDs);
91
+ return result.map(device => new DeviceWrapper(this.createDeviceFromNative(device)));
92
+ }
93
+ // RSSI and MTU operations
94
+ async readRSSIForDevice(deviceIdentifier, transactionId) {
95
+ const result = await this.bleManager.readRSSIForDevice(deviceIdentifier, transactionId);
96
+ return new DeviceWrapper(this.createDeviceFromNative(result));
97
+ }
98
+ async requestMTUForDevice(deviceIdentifier, mtu, transactionId) {
99
+ const result = await this.bleManager.requestMTUForDevice(deviceIdentifier, mtu, transactionId);
100
+ return new DeviceWrapper(this.createDeviceFromNative(result));
101
+ }
102
+ async requestConnectionPriorityForDevice(deviceIdentifier, connectionPriority, transactionId) {
103
+ const result = await this.bleManager.requestConnectionPriorityForDevice(deviceIdentifier, connectionPriority, transactionId);
104
+ return new DeviceWrapper(this.createDeviceFromNative(result));
105
+ }
106
+ // Service discovery
107
+ async discoverAllServicesAndCharacteristicsForDevice(deviceIdentifier, transactionId) {
108
+ const result = await this.bleManager.discoverAllServicesAndCharacteristicsForDevice(deviceIdentifier, transactionId);
109
+ return new DeviceWrapper(this.createDeviceFromNative(result));
110
+ }
111
+ // Service operations
112
+ async servicesForDevice(deviceIdentifier) {
113
+ return await this.bleManager.servicesForDevice(deviceIdentifier);
114
+ }
115
+ // Characteristic operations
116
+ async characteristicsForDevice(deviceIdentifier, serviceUUID) {
117
+ return await this.bleManager.characteristicsForDevice(deviceIdentifier, serviceUUID);
118
+ }
119
+ async readCharacteristicForDevice(deviceIdentifier, serviceUUID, characteristicUUID, transactionId) {
120
+ return await this.bleManager.readCharacteristicForDevice(deviceIdentifier, serviceUUID, characteristicUUID, transactionId);
121
+ }
122
+ async writeCharacteristicWithResponseForDevice(deviceIdentifier, serviceUUID, characteristicUUID, base64Value, transactionId) {
123
+ return await this.bleManager.writeCharacteristicWithResponseForDevice(deviceIdentifier, serviceUUID, characteristicUUID, base64Value, transactionId);
124
+ }
125
+ async writeCharacteristicWithoutResponseForDevice(deviceIdentifier, serviceUUID, characteristicUUID, base64Value, transactionId) {
126
+ return await this.bleManager.writeCharacteristicWithoutResponseForDevice(deviceIdentifier, serviceUUID, characteristicUUID, base64Value, transactionId);
127
+ }
128
+ monitorCharacteristicForDevice(deviceIdentifier, serviceUUID, characteristicUUID, listener, transactionId, subscriptionType) {
129
+ const nitroSubscriptionType = subscriptionType
130
+ ? normalizeCharacteristicSubscriptionType(subscriptionType)
131
+ : undefined;
132
+ return this.bleManager.monitorCharacteristicForDevice(deviceIdentifier, serviceUUID, characteristicUUID, listener, transactionId, nitroSubscriptionType);
133
+ }
134
+ // Descriptor operations
135
+ async descriptorsForDevice(deviceIdentifier, serviceUUID, characteristicUUID) {
136
+ return await this.bleManager.descriptorsForDevice(deviceIdentifier, serviceUUID, characteristicUUID);
137
+ }
138
+ async readDescriptorForDevice(deviceIdentifier, serviceUUID, characteristicUUID, descriptorUUID, transactionId) {
139
+ return await this.bleManager.readDescriptorForDevice(deviceIdentifier, serviceUUID, characteristicUUID, descriptorUUID, transactionId);
140
+ }
141
+ async writeDescriptorForDevice(deviceIdentifier, serviceUUID, characteristicUUID, descriptorUUID, valueBase64, transactionId) {
142
+ return await this.bleManager.writeDescriptorForDevice(deviceIdentifier, serviceUUID, characteristicUUID, descriptorUUID, valueBase64, transactionId);
143
+ }
144
+ /**
145
+ * Helper method to create a Device wrapper from NativeDevice data
146
+ * This is a temporary method until we have proper Device Nitro objects
147
+ */
148
+ createDeviceFromNative(nativeDevice) {
149
+ // This is a placeholder - in the actual implementation, we'd need to create
150
+ // proper Nitro Device objects, but for now we'll work with the native data
151
+ return {
152
+ id: nativeDevice.id,
153
+ deviceName: nativeDevice.name,
154
+ rssi: nativeDevice.rssi,
155
+ mtu: nativeDevice.mtu,
156
+ manufacturerData: nativeDevice.manufacturerData,
157
+ rawScanRecord: nativeDevice.rawScanRecord,
158
+ serviceData: nativeDevice.serviceData,
159
+ serviceUUIDs: nativeDevice.serviceUUIDs,
160
+ localName: nativeDevice.localName,
161
+ txPowerLevel: nativeDevice.txPowerLevel,
162
+ solicitedServiceUUIDs: nativeDevice.solicitedServiceUUIDs,
163
+ isConnectable: nativeDevice.isConnectable,
164
+ overflowServiceUUIDs: nativeDevice.overflowServiceUUIDs,
165
+ // Add placeholder methods - these would be implemented in the actual Device class
166
+ requestConnectionPriority: async () => this.createDeviceFromNative(nativeDevice),
167
+ readRSSI: async () => this.createDeviceFromNative(nativeDevice),
168
+ requestMTU: async () => this.createDeviceFromNative(nativeDevice),
169
+ connect: async () => this.createDeviceFromNative(nativeDevice),
170
+ cancelConnection: async () => this.createDeviceFromNative(nativeDevice),
171
+ isConnected: async () => false,
172
+ onDisconnected: () => ({ remove: () => { } }),
173
+ discoverAllServicesAndCharacteristics: async () => this.createDeviceFromNative(nativeDevice),
174
+ services: async () => [],
175
+ characteristicsForService: async () => [],
176
+ readCharacteristicForService: async () => ({}),
177
+ writeCharacteristicWithResponseForService: async () => ({}),
178
+ writeCharacteristicWithoutResponseForService: async () => ({}),
179
+ monitorCharacteristicForService: () => ({ remove: () => { } }),
180
+ descriptorsForService: async () => [],
181
+ readDescriptorForService: async () => ({}),
182
+ writeDescriptorForService: async () => ({}),
183
+ };
184
+ }
185
+ }
186
+ /**
187
+ * Factory function to create a compatibility BleManager
188
+ */
189
+ export function createBleManagerCompat(options) {
190
+ return new BleManagerCompat(options);
191
+ }
@@ -0,0 +1,12 @@
1
+ import type { BleManager as BleManagerInterface } from './specs/BleManager.nitro';
2
+ import type { BleManagerOptions } from './specs/types';
3
+ /**
4
+ * Creates a BleManager instance using Nitro Modules
5
+ * This function maintains compatibility with react-native-ble-plx's BleManager constructor
6
+ */
7
+ export declare function createBleManager(options?: BleManagerOptions): BleManagerInterface;
8
+ /**
9
+ * Legacy compatibility: Export a BleManager constructor function
10
+ * This maintains compatibility with code that imports { BleManager } from 'react-native-ble-plx'
11
+ */
12
+ export declare const BleManager: any;
@@ -0,0 +1,22 @@
1
+ import { NitroModules } from 'react-native-nitro-modules';
2
+ /**
3
+ * Creates a BleManager instance using Nitro Modules
4
+ * This function maintains compatibility with react-native-ble-plx's BleManager constructor
5
+ */
6
+ export function createBleManager(options) {
7
+ const BleManagerModule = NitroModules.createHybridObject('BleManager');
8
+ if (!BleManagerModule) {
9
+ throw new Error('Failed to create BleManager: Nitro module not found. ' +
10
+ 'Make sure react-native-ble-nitro is properly installed and linked.');
11
+ }
12
+ // If options are provided, we could initialize with them
13
+ // For now, we return the module directly as Nitro handles the native initialization
14
+ return BleManagerModule;
15
+ }
16
+ /**
17
+ * Legacy compatibility: Export a BleManager constructor function
18
+ * This maintains compatibility with code that imports { BleManager } from 'react-native-ble-plx'
19
+ */
20
+ export const BleManager = function (options) {
21
+ return createBleManager(options);
22
+ };
@@ -0,0 +1,49 @@
1
+ /**
2
+ * React-native-ble-plx compatibility constants
3
+ *
4
+ * Re-exports all constants and types to maintain API compatibility
5
+ */
6
+ export declare const State: {
7
+ readonly Unknown: "Unknown";
8
+ readonly Resetting: "Resetting";
9
+ readonly Unsupported: "Unsupported";
10
+ readonly Unauthorized: "Unauthorized";
11
+ readonly PoweredOff: "PoweredOff";
12
+ readonly PoweredOn: "PoweredOn";
13
+ };
14
+ export declare const LogLevel: {
15
+ readonly None: "None";
16
+ readonly Verbose: "Verbose";
17
+ readonly Debug: "Debug";
18
+ readonly Info: "Info";
19
+ readonly Warning: "Warning";
20
+ readonly Error: "Error";
21
+ };
22
+ export type StateString = typeof State[keyof typeof State];
23
+ export type LogLevelString = typeof LogLevel[keyof typeof LogLevel];
24
+ export declare const CharacteristicSubscriptionType: {
25
+ readonly Notification: "notification";
26
+ readonly Indication: "indication";
27
+ };
28
+ export type CharacteristicSubscriptionTypeString = typeof CharacteristicSubscriptionType[keyof typeof CharacteristicSubscriptionType];
29
+ export declare const RefreshGattMoment: {
30
+ readonly OnConnected: "OnConnected";
31
+ };
32
+ export type RefreshGattMomentString = typeof RefreshGattMoment[keyof typeof RefreshGattMoment];
33
+ export declare const ScanMode: {
34
+ readonly Opportunistic: -1;
35
+ readonly LowPower: 0;
36
+ readonly Balanced: 1;
37
+ readonly LowLatency: 2;
38
+ };
39
+ export declare const ScanCallbackType: {
40
+ readonly AllMatches: 1;
41
+ readonly FirstMatch: 2;
42
+ readonly MatchLost: 4;
43
+ };
44
+ export declare const ConnectionPriority: {
45
+ readonly Balanced: 0;
46
+ readonly High: 1;
47
+ readonly LowPower: 2;
48
+ };
49
+ export { BleErrorCode, BleATTErrorCode, BleIOSErrorCode, BleAndroidErrorCode } from '../specs/types';
@@ -0,0 +1,50 @@
1
+ /**
2
+ * React-native-ble-plx compatibility constants
3
+ *
4
+ * Re-exports all constants and types to maintain API compatibility
5
+ */
6
+ // Re-export original string-based constants for backward compatibility
7
+ export const State = {
8
+ Unknown: 'Unknown',
9
+ Resetting: 'Resetting',
10
+ Unsupported: 'Unsupported',
11
+ Unauthorized: 'Unauthorized',
12
+ PoweredOff: 'PoweredOff',
13
+ PoweredOn: 'PoweredOn',
14
+ };
15
+ export const LogLevel = {
16
+ None: 'None',
17
+ Verbose: 'Verbose',
18
+ Debug: 'Debug',
19
+ Info: 'Info',
20
+ Warning: 'Warning',
21
+ Error: 'Error',
22
+ };
23
+ // Subscription type constants
24
+ export const CharacteristicSubscriptionType = {
25
+ Notification: 'notification',
26
+ Indication: 'indication',
27
+ };
28
+ // Connection options constants
29
+ export const RefreshGattMoment = {
30
+ OnConnected: 'OnConnected',
31
+ };
32
+ // Scan mode constants (these remain numeric as in original)
33
+ export const ScanMode = {
34
+ Opportunistic: -1,
35
+ LowPower: 0,
36
+ Balanced: 1,
37
+ LowLatency: 2,
38
+ };
39
+ export const ScanCallbackType = {
40
+ AllMatches: 1,
41
+ FirstMatch: 2,
42
+ MatchLost: 4,
43
+ };
44
+ export const ConnectionPriority = {
45
+ Balanced: 0,
46
+ High: 1,
47
+ LowPower: 2,
48
+ };
49
+ // Re-export all BLE error codes
50
+ export { BleErrorCode, BleATTErrorCode, BleIOSErrorCode, BleAndroidErrorCode } from '../specs/types';
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Device wrapper for compatibility
3
+ *
4
+ * Wraps Nitro Device objects to provide the original react-native-ble-plx API
5
+ */
6
+ import type { Device as NitroDevice } from '../specs/Device.nitro';
7
+ import type { UUID, Base64, DeviceId, TransactionId, ConnectionPriority, ConnectionOptions, NativeService, NativeCharacteristic, NativeDescriptor, Subscription } from '../specs/types';
8
+ /**
9
+ * Device wrapper that provides react-native-ble-plx compatibility
10
+ * Maps Nitro device properties to the expected API surface
11
+ */
12
+ export declare class DeviceWrapper {
13
+ private nitroDevice;
14
+ constructor(nitroDevice: NitroDevice | any);
15
+ get id(): DeviceId;
16
+ get name(): string | null;
17
+ get rssi(): number | null;
18
+ get mtu(): number;
19
+ get manufacturerData(): Base64 | null;
20
+ get rawScanRecord(): Base64;
21
+ get serviceData(): {
22
+ [uuid: string]: Base64;
23
+ } | null;
24
+ get serviceUUIDs(): UUID[] | null;
25
+ get localName(): string | null;
26
+ get txPowerLevel(): number | null;
27
+ get solicitedServiceUUIDs(): UUID[] | null;
28
+ get isConnectable(): boolean | null;
29
+ get overflowServiceUUIDs(): UUID[] | null;
30
+ requestConnectionPriority(connectionPriority: ConnectionPriority, transactionId?: TransactionId): Promise<DeviceWrapper>;
31
+ readRSSI(transactionId?: TransactionId): Promise<DeviceWrapper>;
32
+ requestMTU(mtu: number, transactionId?: TransactionId): Promise<DeviceWrapper>;
33
+ connect(options?: Partial<ConnectionOptions>): Promise<DeviceWrapper>;
34
+ cancelConnection(): Promise<DeviceWrapper>;
35
+ isConnected(): Promise<boolean>;
36
+ onDisconnected(listener: (error: any | null, device: DeviceWrapper) => void): Subscription;
37
+ discoverAllServicesAndCharacteristics(transactionId?: TransactionId): Promise<DeviceWrapper>;
38
+ services(): Promise<ServiceWrapper[]>;
39
+ characteristicsForService(serviceUUID: UUID): Promise<CharacteristicWrapper[]>;
40
+ readCharacteristicForService(serviceUUID: UUID, characteristicUUID: UUID, transactionId?: TransactionId): Promise<CharacteristicWrapper>;
41
+ writeCharacteristicWithResponseForService(serviceUUID: UUID, characteristicUUID: UUID, valueBase64: Base64, transactionId?: TransactionId): Promise<CharacteristicWrapper>;
42
+ writeCharacteristicWithoutResponseForService(serviceUUID: UUID, characteristicUUID: UUID, valueBase64: Base64, transactionId?: TransactionId): Promise<CharacteristicWrapper>;
43
+ monitorCharacteristicForService(serviceUUID: UUID, characteristicUUID: UUID, listener: (error: any | null, characteristic: CharacteristicWrapper | null) => void, transactionId?: TransactionId, subscriptionType?: 'notification' | 'indication'): Subscription;
44
+ descriptorsForService(serviceUUID: UUID, characteristicUUID: UUID): Promise<DescriptorWrapper[]>;
45
+ readDescriptorForService(serviceUUID: UUID, characteristicUUID: UUID, descriptorUUID: UUID, transactionId?: TransactionId): Promise<DescriptorWrapper>;
46
+ writeDescriptorForService(serviceUUID: UUID, characteristicUUID: UUID, descriptorUUID: UUID, valueBase64: Base64, transactionId?: TransactionId): Promise<DescriptorWrapper>;
47
+ }
48
+ /**
49
+ * Service wrapper for compatibility
50
+ */
51
+ export declare class ServiceWrapper {
52
+ private nativeService;
53
+ private nitroDevice;
54
+ constructor(nativeService: NativeService, nitroDevice: NitroDevice);
55
+ get id(): number;
56
+ get uuid(): UUID;
57
+ get deviceID(): DeviceId;
58
+ get isPrimary(): boolean;
59
+ characteristics(): Promise<CharacteristicWrapper[]>;
60
+ readCharacteristic(characteristicUUID: UUID, transactionId?: TransactionId): Promise<CharacteristicWrapper>;
61
+ }
62
+ /**
63
+ * Characteristic wrapper for compatibility
64
+ */
65
+ export declare class CharacteristicWrapper {
66
+ private nativeCharacteristic;
67
+ private nitroDevice;
68
+ constructor(nativeCharacteristic: NativeCharacteristic, nitroDevice: NitroDevice);
69
+ get id(): number;
70
+ get uuid(): UUID;
71
+ get serviceID(): number;
72
+ get serviceUUID(): UUID;
73
+ get deviceID(): DeviceId;
74
+ get isReadable(): boolean;
75
+ get isWritableWithResponse(): boolean;
76
+ get isWritableWithoutResponse(): boolean;
77
+ get isNotifiable(): boolean;
78
+ get isNotifying(): boolean;
79
+ get isIndicatable(): boolean;
80
+ get value(): Base64 | null;
81
+ read(transactionId?: TransactionId): Promise<CharacteristicWrapper>;
82
+ }
83
+ /**
84
+ * Descriptor wrapper for compatibility
85
+ */
86
+ export declare class DescriptorWrapper {
87
+ private nativeDescriptor;
88
+ private nitroDevice;
89
+ constructor(nativeDescriptor: NativeDescriptor, nitroDevice: NitroDevice);
90
+ get id(): number;
91
+ get uuid(): UUID;
92
+ get characteristicID(): number;
93
+ get characteristicUUID(): UUID;
94
+ get serviceID(): number;
95
+ get serviceUUID(): UUID;
96
+ get deviceID(): DeviceId;
97
+ get value(): Base64 | null;
98
+ read(transactionId?: TransactionId): Promise<DescriptorWrapper>;
99
+ }
@@ -0,0 +1,259 @@
1
+ /**
2
+ * Device wrapper for compatibility
3
+ *
4
+ * Wraps Nitro Device objects to provide the original react-native-ble-plx API
5
+ */
6
+ import { serviceDataArrayToMap } from './serviceData';
7
+ import { normalizeCharacteristicSubscriptionType } from './enums';
8
+ /**
9
+ * Device wrapper that provides react-native-ble-plx compatibility
10
+ * Maps Nitro device properties to the expected API surface
11
+ */
12
+ export class DeviceWrapper {
13
+ constructor(nitroDevice) {
14
+ this.nitroDevice = nitroDevice;
15
+ }
16
+ // Device identification
17
+ get id() {
18
+ return this.nitroDevice.id;
19
+ }
20
+ // Map deviceName back to name for compatibility
21
+ get name() {
22
+ return this.nitroDevice.deviceName || null;
23
+ }
24
+ get rssi() {
25
+ return this.nitroDevice.rssi || null;
26
+ }
27
+ get mtu() {
28
+ return this.nitroDevice.mtu;
29
+ }
30
+ // Advertisement data
31
+ get manufacturerData() {
32
+ return this.nitroDevice.manufacturerData || null;
33
+ }
34
+ get rawScanRecord() {
35
+ return this.nitroDevice.rawScanRecord;
36
+ }
37
+ // Convert ServiceDataEntry[] back to { [uuid: string]: Base64 }
38
+ get serviceData() {
39
+ return serviceDataArrayToMap(this.nitroDevice.serviceData || null);
40
+ }
41
+ get serviceUUIDs() {
42
+ return this.nitroDevice.serviceUUIDs || null;
43
+ }
44
+ get localName() {
45
+ return this.nitroDevice.localName || null;
46
+ }
47
+ get txPowerLevel() {
48
+ return this.nitroDevice.txPowerLevel || null;
49
+ }
50
+ get solicitedServiceUUIDs() {
51
+ return this.nitroDevice.solicitedServiceUUIDs || null;
52
+ }
53
+ get isConnectable() {
54
+ return this.nitroDevice.isConnectable || null;
55
+ }
56
+ get overflowServiceUUIDs() {
57
+ return this.nitroDevice.overflowServiceUUIDs || null;
58
+ }
59
+ // Connection management methods
60
+ async requestConnectionPriority(connectionPriority, transactionId) {
61
+ const result = await this.nitroDevice.requestConnectionPriority(connectionPriority, transactionId);
62
+ return new DeviceWrapper(result);
63
+ }
64
+ async readRSSI(transactionId) {
65
+ const result = await this.nitroDevice.readRSSI(transactionId);
66
+ return new DeviceWrapper(result);
67
+ }
68
+ async requestMTU(mtu, transactionId) {
69
+ const result = await this.nitroDevice.requestMTU(mtu, transactionId);
70
+ return new DeviceWrapper(result);
71
+ }
72
+ async connect(options) {
73
+ // Provide defaults for required fields in Nitro interface
74
+ const connectionOptions = {
75
+ autoConnect: options?.autoConnect ?? false,
76
+ requestMTU: options?.requestMTU ?? 23,
77
+ timeout: options?.timeout ?? 0,
78
+ };
79
+ const result = await this.nitroDevice.connect(connectionOptions);
80
+ return new DeviceWrapper(result);
81
+ }
82
+ async cancelConnection() {
83
+ const result = await this.nitroDevice.cancelConnection();
84
+ return new DeviceWrapper(result);
85
+ }
86
+ async isConnected() {
87
+ return await this.nitroDevice.isConnected();
88
+ }
89
+ onDisconnected(listener) {
90
+ return this.nitroDevice.onDisconnected((error, device) => {
91
+ listener(error, new DeviceWrapper(device));
92
+ });
93
+ }
94
+ // Service discovery
95
+ async discoverAllServicesAndCharacteristics(transactionId) {
96
+ const result = await this.nitroDevice.discoverAllServicesAndCharacteristics(transactionId);
97
+ return new DeviceWrapper(result);
98
+ }
99
+ async services() {
100
+ const services = await this.nitroDevice.services();
101
+ return services.map((service) => new ServiceWrapper(service, this.nitroDevice));
102
+ }
103
+ // Characteristic operations
104
+ async characteristicsForService(serviceUUID) {
105
+ const characteristics = await this.nitroDevice.characteristicsForService(serviceUUID);
106
+ return characteristics.map((char) => new CharacteristicWrapper(char, this.nitroDevice));
107
+ }
108
+ async readCharacteristicForService(serviceUUID, characteristicUUID, transactionId) {
109
+ const result = await this.nitroDevice.readCharacteristicForService(serviceUUID, characteristicUUID, transactionId);
110
+ return new CharacteristicWrapper(result, this.nitroDevice);
111
+ }
112
+ async writeCharacteristicWithResponseForService(serviceUUID, characteristicUUID, valueBase64, transactionId) {
113
+ const result = await this.nitroDevice.writeCharacteristicWithResponseForService(serviceUUID, characteristicUUID, valueBase64, transactionId);
114
+ return new CharacteristicWrapper(result, this.nitroDevice);
115
+ }
116
+ async writeCharacteristicWithoutResponseForService(serviceUUID, characteristicUUID, valueBase64, transactionId) {
117
+ const result = await this.nitroDevice.writeCharacteristicWithoutResponseForService(serviceUUID, characteristicUUID, valueBase64, transactionId);
118
+ return new CharacteristicWrapper(result, this.nitroDevice);
119
+ }
120
+ monitorCharacteristicForService(serviceUUID, characteristicUUID, listener, transactionId, subscriptionType) {
121
+ const nitroSubscriptionType = subscriptionType
122
+ ? normalizeCharacteristicSubscriptionType(subscriptionType)
123
+ : undefined;
124
+ return this.nitroDevice.monitorCharacteristicForService(serviceUUID, characteristicUUID, (error, characteristic) => {
125
+ listener(error, characteristic ? new CharacteristicWrapper(characteristic, this.nitroDevice) : null);
126
+ }, transactionId, nitroSubscriptionType);
127
+ }
128
+ // Descriptor operations
129
+ async descriptorsForService(serviceUUID, characteristicUUID) {
130
+ const descriptors = await this.nitroDevice.descriptorsForService(serviceUUID, characteristicUUID);
131
+ return descriptors.map((desc) => new DescriptorWrapper(desc, this.nitroDevice));
132
+ }
133
+ async readDescriptorForService(serviceUUID, characteristicUUID, descriptorUUID, transactionId) {
134
+ const result = await this.nitroDevice.readDescriptorForService(serviceUUID, characteristicUUID, descriptorUUID, transactionId);
135
+ return new DescriptorWrapper(result, this.nitroDevice);
136
+ }
137
+ async writeDescriptorForService(serviceUUID, characteristicUUID, descriptorUUID, valueBase64, transactionId) {
138
+ const result = await this.nitroDevice.writeDescriptorForService(serviceUUID, characteristicUUID, descriptorUUID, valueBase64, transactionId);
139
+ return new DescriptorWrapper(result, this.nitroDevice);
140
+ }
141
+ }
142
+ /**
143
+ * Service wrapper for compatibility
144
+ */
145
+ export class ServiceWrapper {
146
+ constructor(nativeService, nitroDevice) {
147
+ this.nativeService = nativeService;
148
+ this.nitroDevice = nitroDevice;
149
+ }
150
+ get id() {
151
+ return this.nativeService.id;
152
+ }
153
+ get uuid() {
154
+ return this.nativeService.uuid;
155
+ }
156
+ get deviceID() {
157
+ return this.nativeService.deviceID;
158
+ }
159
+ get isPrimary() {
160
+ return this.nativeService.isPrimary;
161
+ }
162
+ // Delegate to device methods
163
+ async characteristics() {
164
+ const device = new DeviceWrapper(this.nitroDevice);
165
+ return await device.characteristicsForService(this.uuid);
166
+ }
167
+ async readCharacteristic(characteristicUUID, transactionId) {
168
+ const device = new DeviceWrapper(this.nitroDevice);
169
+ return await device.readCharacteristicForService(this.uuid, characteristicUUID, transactionId);
170
+ }
171
+ }
172
+ /**
173
+ * Characteristic wrapper for compatibility
174
+ */
175
+ export class CharacteristicWrapper {
176
+ constructor(nativeCharacteristic, nitroDevice) {
177
+ this.nativeCharacteristic = nativeCharacteristic;
178
+ this.nitroDevice = nitroDevice;
179
+ }
180
+ get id() {
181
+ return this.nativeCharacteristic.id;
182
+ }
183
+ get uuid() {
184
+ return this.nativeCharacteristic.uuid;
185
+ }
186
+ get serviceID() {
187
+ return this.nativeCharacteristic.serviceID;
188
+ }
189
+ get serviceUUID() {
190
+ return this.nativeCharacteristic.serviceUUID;
191
+ }
192
+ get deviceID() {
193
+ return this.nativeCharacteristic.deviceID;
194
+ }
195
+ get isReadable() {
196
+ return this.nativeCharacteristic.isReadable;
197
+ }
198
+ get isWritableWithResponse() {
199
+ return this.nativeCharacteristic.isWritableWithResponse;
200
+ }
201
+ get isWritableWithoutResponse() {
202
+ return this.nativeCharacteristic.isWritableWithoutResponse;
203
+ }
204
+ get isNotifiable() {
205
+ return this.nativeCharacteristic.isNotifiable;
206
+ }
207
+ get isNotifying() {
208
+ return this.nativeCharacteristic.isNotifying;
209
+ }
210
+ get isIndicatable() {
211
+ return this.nativeCharacteristic.isIndicatable;
212
+ }
213
+ get value() {
214
+ return this.nativeCharacteristic.value;
215
+ }
216
+ // Delegate to device methods
217
+ async read(transactionId) {
218
+ const device = new DeviceWrapper(this.nitroDevice);
219
+ return await device.readCharacteristicForService(this.serviceUUID, this.uuid, transactionId);
220
+ }
221
+ }
222
+ /**
223
+ * Descriptor wrapper for compatibility
224
+ */
225
+ export class DescriptorWrapper {
226
+ constructor(nativeDescriptor, nitroDevice) {
227
+ this.nativeDescriptor = nativeDescriptor;
228
+ this.nitroDevice = nitroDevice;
229
+ }
230
+ get id() {
231
+ return this.nativeDescriptor.id;
232
+ }
233
+ get uuid() {
234
+ return this.nativeDescriptor.uuid;
235
+ }
236
+ get characteristicID() {
237
+ return this.nativeDescriptor.characteristicID;
238
+ }
239
+ get characteristicUUID() {
240
+ return this.nativeDescriptor.characteristicUUID;
241
+ }
242
+ get serviceID() {
243
+ return this.nativeDescriptor.serviceID;
244
+ }
245
+ get serviceUUID() {
246
+ return this.nativeDescriptor.serviceUUID;
247
+ }
248
+ get deviceID() {
249
+ return this.nativeDescriptor.deviceID;
250
+ }
251
+ get value() {
252
+ return this.nativeDescriptor.value;
253
+ }
254
+ // Delegate to device methods
255
+ async read(transactionId) {
256
+ const device = new DeviceWrapper(this.nitroDevice);
257
+ return await device.readDescriptorForService(this.serviceUUID, this.characteristicUUID, this.uuid, transactionId);
258
+ }
259
+ }