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,43 @@
1
+ /**
2
+ * Enum compatibility layer
3
+ *
4
+ * Provides conversion between Nitro's numeric enums and the original
5
+ * string-based enums from react-native-ble-plx
6
+ */
7
+ import { State, LogLevel, CharacteristicSubscriptionType, RefreshGattMoment } from '../specs/types';
8
+ export declare const StateString: {
9
+ readonly 0: "Unknown";
10
+ readonly 1: "Resetting";
11
+ readonly 2: "Unsupported";
12
+ readonly 3: "Unauthorized";
13
+ readonly 4: "PoweredOff";
14
+ readonly 5: "PoweredOn";
15
+ };
16
+ export declare const LogLevelString: {
17
+ readonly 0: "None";
18
+ readonly 1: "Verbose";
19
+ readonly 2: "Debug";
20
+ readonly 3: "Info";
21
+ readonly 4: "Warning";
22
+ readonly 5: "Error";
23
+ };
24
+ export declare const CharacteristicSubscriptionTypeString: {
25
+ readonly 0: "notification";
26
+ readonly 1: "indication";
27
+ };
28
+ export declare const RefreshGattMomentString: {
29
+ readonly 0: "OnConnected";
30
+ };
31
+ export declare function stateToString(state: State): string;
32
+ export declare function stringToState(stateString: string): State;
33
+ export declare function logLevelToString(logLevel: LogLevel): string;
34
+ export declare function stringToLogLevel(logLevelString: string): LogLevel;
35
+ export declare function characteristicSubscriptionTypeToString(type: CharacteristicSubscriptionType): string;
36
+ export declare function stringToCharacteristicSubscriptionType(typeString: string): CharacteristicSubscriptionType;
37
+ export declare function refreshGattMomentToString(moment: RefreshGattMoment): 'OnConnected';
38
+ export declare function stringToRefreshGattMoment(momentString: 'OnConnected'): RefreshGattMoment;
39
+ export declare function isStringEnumValue(value: any): boolean;
40
+ export declare function normalizeState(state: State | string): State;
41
+ export declare function normalizeLogLevel(logLevel: LogLevel | string): LogLevel;
42
+ export declare function normalizeCharacteristicSubscriptionType(type: CharacteristicSubscriptionType | 'notification' | 'indication'): CharacteristicSubscriptionType;
43
+ export declare function normalizeRefreshGattMoment(moment: RefreshGattMoment | 'OnConnected'): RefreshGattMoment;
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Enum compatibility layer
3
+ *
4
+ * Provides conversion between Nitro's numeric enums and the original
5
+ * string-based enums from react-native-ble-plx
6
+ */
7
+ import { State, LogLevel, CharacteristicSubscriptionType, RefreshGattMoment, } from '../specs/types';
8
+ // String mappings for backward compatibility
9
+ export const StateString = {
10
+ [State.Unknown]: 'Unknown',
11
+ [State.Resetting]: 'Resetting',
12
+ [State.Unsupported]: 'Unsupported',
13
+ [State.Unauthorized]: 'Unauthorized',
14
+ [State.PoweredOff]: 'PoweredOff',
15
+ [State.PoweredOn]: 'PoweredOn',
16
+ };
17
+ export const LogLevelString = {
18
+ [LogLevel.None]: 'None',
19
+ [LogLevel.Verbose]: 'Verbose',
20
+ [LogLevel.Debug]: 'Debug',
21
+ [LogLevel.Info]: 'Info',
22
+ [LogLevel.Warning]: 'Warning',
23
+ [LogLevel.Error]: 'Error',
24
+ };
25
+ export const CharacteristicSubscriptionTypeString = {
26
+ [CharacteristicSubscriptionType.Notification]: 'notification',
27
+ [CharacteristicSubscriptionType.Indication]: 'indication',
28
+ };
29
+ export const RefreshGattMomentString = {
30
+ [RefreshGattMoment.OnConnected]: 'OnConnected',
31
+ };
32
+ // Reverse mappings for converting strings back to numeric enums
33
+ const StringToState = {};
34
+ const StringToLogLevel = {};
35
+ const StringToCharacteristicSubscriptionType = {};
36
+ const StringToRefreshGattMoment = {};
37
+ // Build reverse mappings
38
+ Object.entries(StateString).forEach(([num, str]) => {
39
+ StringToState[str] = parseInt(num);
40
+ });
41
+ Object.entries(LogLevelString).forEach(([num, str]) => {
42
+ StringToLogLevel[str] = parseInt(num);
43
+ });
44
+ Object.entries(CharacteristicSubscriptionTypeString).forEach(([num, str]) => {
45
+ StringToCharacteristicSubscriptionType[str] = parseInt(num);
46
+ });
47
+ Object.entries(RefreshGattMomentString).forEach(([num, str]) => {
48
+ StringToRefreshGattMoment[str] = parseInt(num);
49
+ });
50
+ // Conversion functions
51
+ export function stateToString(state) {
52
+ return StateString[state] ?? 'Unknown';
53
+ }
54
+ export function stringToState(stateString) {
55
+ // Handle case insensitive lookup
56
+ const lowerString = stateString.toLowerCase();
57
+ for (const [key, value] of Object.entries(StringToState)) {
58
+ if (key.toLowerCase() === lowerString) {
59
+ return value;
60
+ }
61
+ }
62
+ return State.Unknown;
63
+ }
64
+ export function logLevelToString(logLevel) {
65
+ return LogLevelString[logLevel] ?? 'None';
66
+ }
67
+ export function stringToLogLevel(logLevelString) {
68
+ // Handle case insensitive lookup
69
+ const lowerString = logLevelString.toLowerCase();
70
+ for (const [key, value] of Object.entries(StringToLogLevel)) {
71
+ if (key.toLowerCase() === lowerString) {
72
+ return value;
73
+ }
74
+ }
75
+ return LogLevel.None;
76
+ }
77
+ export function characteristicSubscriptionTypeToString(type) {
78
+ return CharacteristicSubscriptionTypeString[type] ?? 'notification';
79
+ }
80
+ export function stringToCharacteristicSubscriptionType(typeString) {
81
+ // Handle case insensitive lookup
82
+ const lowerString = typeString.toLowerCase();
83
+ for (const [key, value] of Object.entries(StringToCharacteristicSubscriptionType)) {
84
+ if (key.toLowerCase() === lowerString) {
85
+ return value;
86
+ }
87
+ }
88
+ return CharacteristicSubscriptionType.Notification;
89
+ }
90
+ export function refreshGattMomentToString(moment) {
91
+ return RefreshGattMomentString[moment];
92
+ }
93
+ export function stringToRefreshGattMoment(momentString) {
94
+ return StringToRefreshGattMoment[momentString] ?? RefreshGattMoment.OnConnected;
95
+ }
96
+ // Helper function to detect if a value is a string enum vs numeric enum
97
+ export function isStringEnumValue(value) {
98
+ return typeof value === 'string';
99
+ }
100
+ // Generic converter that handles both string and numeric enum values
101
+ export function normalizeState(state) {
102
+ if (typeof state === 'string') {
103
+ return stringToState(state);
104
+ }
105
+ return state;
106
+ }
107
+ export function normalizeLogLevel(logLevel) {
108
+ if (typeof logLevel === 'string') {
109
+ return stringToLogLevel(logLevel);
110
+ }
111
+ return logLevel;
112
+ }
113
+ export function normalizeCharacteristicSubscriptionType(type) {
114
+ if (typeof type === 'string') {
115
+ return stringToCharacteristicSubscriptionType(type);
116
+ }
117
+ return type;
118
+ }
119
+ export function normalizeRefreshGattMoment(moment) {
120
+ if (typeof moment === 'string') {
121
+ return stringToRefreshGattMoment(moment);
122
+ }
123
+ return moment;
124
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Compatibility layer for react-native-ble-nitro
3
+ *
4
+ * This module provides compatibility shims and converters to maintain
5
+ * 100% API compatibility with react-native-ble-plx while working with
6
+ * Nitro's type system constraints.
7
+ */
8
+ export * from './serviceData';
9
+ export * from './deviceWrapper';
10
+ export * from './constants';
11
+ export { stateToString, stringToState, logLevelToString, stringToLogLevel, characteristicSubscriptionTypeToString, stringToCharacteristicSubscriptionType, normalizeState, normalizeLogLevel, normalizeCharacteristicSubscriptionType, } from './enums';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Compatibility layer for react-native-ble-nitro
3
+ *
4
+ * This module provides compatibility shims and converters to maintain
5
+ * 100% API compatibility with react-native-ble-plx while working with
6
+ * Nitro's type system constraints.
7
+ */
8
+ export * from './serviceData';
9
+ export * from './deviceWrapper';
10
+ export * from './constants';
11
+ // Explicitly export enum utilities to avoid conflicts
12
+ export { stateToString, stringToState, logLevelToString, stringToLogLevel, characteristicSubscriptionTypeToString, stringToCharacteristicSubscriptionType, normalizeState, normalizeLogLevel, normalizeCharacteristicSubscriptionType, } from './enums';
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Service Data compatibility layer
3
+ *
4
+ * Provides conversion between Nitro's structured ServiceDataEntry[] format
5
+ * and the original { [uuid: string]: Base64 } format from react-native-ble-plx
6
+ */
7
+ import type { ServiceDataEntry, UUID, Base64 } from '../specs/types';
8
+ /**
9
+ * Convert ServiceDataEntry array to the original index signature format
10
+ */
11
+ export declare function serviceDataArrayToMap(entries: ServiceDataEntry[] | null): {
12
+ [uuid: string]: Base64;
13
+ } | null;
14
+ /**
15
+ * Convert the original index signature format to ServiceDataEntry array
16
+ */
17
+ export declare function serviceDataMapToArray(map: {
18
+ [uuid: string]: Base64;
19
+ } | null): ServiceDataEntry[] | null;
20
+ /**
21
+ * Merge two service data maps (used in device updates)
22
+ */
23
+ export declare function mergeServiceDataMaps(existing: {
24
+ [uuid: string]: Base64;
25
+ } | null, updates: {
26
+ [uuid: string]: Base64;
27
+ } | null): {
28
+ [uuid: string]: Base64;
29
+ } | null;
30
+ /**
31
+ * Merge two service data arrays (used in native updates)
32
+ */
33
+ export declare function mergeServiceDataArrays(existing: ServiceDataEntry[] | null, updates: ServiceDataEntry[] | null): ServiceDataEntry[] | null;
34
+ /**
35
+ * Check if service data contains a specific service UUID
36
+ */
37
+ export declare function hasServiceUUID(serviceData: {
38
+ [uuid: string]: Base64;
39
+ } | null, uuid: UUID): boolean;
40
+ /**
41
+ * Get service data for a specific UUID
42
+ */
43
+ export declare function getServiceData(serviceData: {
44
+ [uuid: string]: Base64;
45
+ } | null, uuid: UUID): Base64 | null;
46
+ /**
47
+ * Get all service UUIDs from service data
48
+ */
49
+ export declare function getServiceUUIDs(serviceData: {
50
+ [uuid: string]: Base64;
51
+ } | null): UUID[];
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Service Data compatibility layer
3
+ *
4
+ * Provides conversion between Nitro's structured ServiceDataEntry[] format
5
+ * and the original { [uuid: string]: Base64 } format from react-native-ble-plx
6
+ */
7
+ /**
8
+ * Convert ServiceDataEntry array to the original index signature format
9
+ */
10
+ export function serviceDataArrayToMap(entries) {
11
+ if (!entries || entries.length === 0) {
12
+ return null;
13
+ }
14
+ const result = {};
15
+ entries.forEach(entry => {
16
+ result[entry.uuid] = entry.data;
17
+ });
18
+ return result;
19
+ }
20
+ /**
21
+ * Convert the original index signature format to ServiceDataEntry array
22
+ */
23
+ export function serviceDataMapToArray(map) {
24
+ if (!map || Object.keys(map).length === 0) {
25
+ return null;
26
+ }
27
+ return Object.entries(map).map(([uuid, data]) => ({
28
+ uuid: uuid,
29
+ data,
30
+ }));
31
+ }
32
+ /**
33
+ * Merge two service data maps (used in device updates)
34
+ */
35
+ export function mergeServiceDataMaps(existing, updates) {
36
+ if (!existing && !updates)
37
+ return null;
38
+ if (!existing)
39
+ return updates;
40
+ if (!updates)
41
+ return existing;
42
+ return { ...existing, ...updates };
43
+ }
44
+ /**
45
+ * Merge two service data arrays (used in native updates)
46
+ */
47
+ export function mergeServiceDataArrays(existing, updates) {
48
+ const existingMap = serviceDataArrayToMap(existing);
49
+ const updatesMap = serviceDataArrayToMap(updates);
50
+ const mergedMap = mergeServiceDataMaps(existingMap, updatesMap);
51
+ return serviceDataMapToArray(mergedMap);
52
+ }
53
+ /**
54
+ * Check if service data contains a specific service UUID
55
+ */
56
+ export function hasServiceUUID(serviceData, uuid) {
57
+ return serviceData ? uuid in serviceData : false;
58
+ }
59
+ /**
60
+ * Get service data for a specific UUID
61
+ */
62
+ export function getServiceData(serviceData, uuid) {
63
+ return serviceData?.[uuid] || null;
64
+ }
65
+ /**
66
+ * Get all service UUIDs from service data
67
+ */
68
+ export function getServiceUUIDs(serviceData) {
69
+ return serviceData ? Object.keys(serviceData) : [];
70
+ }
@@ -0,0 +1,59 @@
1
+ import { BleErrorCode, BleATTErrorCode, BleIOSErrorCode, BleAndroidErrorCode } from '../specs/types';
2
+ import type { NativeBleError, BleErrorCodeMessageMapping } from '../specs/types';
3
+ /**
4
+ * Default error messages for BLE error codes
5
+ * Maintains compatibility with react-native-ble-plx error messages
6
+ */
7
+ declare const BleErrorCodeMessage: BleErrorCodeMessageMapping;
8
+ /**
9
+ * BleError class that maintains 100% compatibility with react-native-ble-plx
10
+ * Contains additional properties for platform-independent error handling
11
+ */
12
+ export declare class BleError extends Error {
13
+ /**
14
+ * Platform independent error code
15
+ */
16
+ readonly errorCode: BleErrorCode;
17
+ /**
18
+ * Platform independent error code related to ATT errors
19
+ */
20
+ readonly attErrorCode: BleATTErrorCode | null;
21
+ /**
22
+ * iOS specific error code (if not an ATT error)
23
+ */
24
+ readonly iosErrorCode: BleIOSErrorCode | null;
25
+ /**
26
+ * Android specific error code (if not an ATT error)
27
+ */
28
+ readonly androidErrorCode: BleAndroidErrorCode | null;
29
+ /**
30
+ * Platform specific error message
31
+ */
32
+ readonly reason: string | null;
33
+ /**
34
+ * Device ID associated with error (if applicable)
35
+ */
36
+ readonly deviceID?: string;
37
+ /**
38
+ * Service UUID associated with error (if applicable)
39
+ */
40
+ readonly serviceUUID?: string;
41
+ /**
42
+ * Characteristic UUID associated with error (if applicable)
43
+ */
44
+ readonly characteristicUUID?: string;
45
+ /**
46
+ * Descriptor UUID associated with error (if applicable)
47
+ */
48
+ readonly descriptorUUID?: string;
49
+ /**
50
+ * Internal error message for debugging
51
+ */
52
+ readonly internalMessage?: string;
53
+ constructor(nativeBleError: NativeBleError | string, errorMessageMapping?: BleErrorCodeMessageMapping);
54
+ /**
55
+ * Returns a string representation of the error with all relevant information
56
+ */
57
+ toString(): string;
58
+ }
59
+ export { BleErrorCodeMessage };
@@ -0,0 +1,120 @@
1
+ import { BleErrorCode } from '../specs/types';
2
+ /**
3
+ * Default error messages for BLE error codes
4
+ * Maintains compatibility with react-native-ble-plx error messages
5
+ */
6
+ const BleErrorCodeMessage = {
7
+ [BleErrorCode.UnknownError]: 'Unknown error occurred',
8
+ [BleErrorCode.BluetoothManagerDestroyed]: 'BLE Manager was destroyed',
9
+ [BleErrorCode.OperationCancelled]: 'Operation was cancelled',
10
+ [BleErrorCode.OperationTimedOut]: 'Operation timed out',
11
+ [BleErrorCode.OperationStartFailed]: 'Operation could not be started',
12
+ [BleErrorCode.InvalidIdentifiers]: 'Invalid identifiers provided',
13
+ [BleErrorCode.BluetoothUnsupported]: 'Bluetooth is not supported on this device',
14
+ [BleErrorCode.BluetoothUnauthorized]: 'App is not authorized to use Bluetooth',
15
+ [BleErrorCode.BluetoothPoweredOff]: 'Bluetooth is powered off',
16
+ [BleErrorCode.BluetoothInUnknownState]: 'Bluetooth is in unknown state',
17
+ [BleErrorCode.BluetoothResetting]: 'Bluetooth is resetting',
18
+ [BleErrorCode.BluetoothStateChangeFailed]: 'Bluetooth state change failed',
19
+ [BleErrorCode.DeviceConnectionFailed]: 'Device connection failed',
20
+ [BleErrorCode.DeviceDisconnected]: 'Device was disconnected',
21
+ [BleErrorCode.DeviceRSSIReadFailed]: 'Failed to read RSSI',
22
+ [BleErrorCode.DeviceAlreadyConnected]: 'Device is already connected',
23
+ [BleErrorCode.DeviceNotFound]: 'Device not found',
24
+ [BleErrorCode.DeviceNotConnected]: 'Device is not connected',
25
+ [BleErrorCode.DeviceMTUChangeFailed]: 'Failed to change MTU',
26
+ [BleErrorCode.ServicesDiscoveryFailed]: 'Services discovery failed',
27
+ [BleErrorCode.IncludedServicesDiscoveryFailed]: 'Included services discovery failed',
28
+ [BleErrorCode.ServiceNotFound]: 'Service not found',
29
+ [BleErrorCode.ServicesNotDiscovered]: 'Services not discovered',
30
+ [BleErrorCode.CharacteristicsDiscoveryFailed]: 'Characteristics discovery failed',
31
+ [BleErrorCode.CharacteristicWriteFailed]: 'Characteristic write failed',
32
+ [BleErrorCode.CharacteristicReadFailed]: 'Characteristic read failed',
33
+ [BleErrorCode.CharacteristicNotifyChangeFailed]: 'Failed to change characteristic notification state',
34
+ [BleErrorCode.CharacteristicNotFound]: 'Characteristic not found',
35
+ [BleErrorCode.CharacteristicsNotDiscovered]: 'Characteristics not discovered',
36
+ [BleErrorCode.CharacteristicInvalidDataFormat]: 'Invalid characteristic data format',
37
+ [BleErrorCode.DescriptorsDiscoveryFailed]: 'Descriptors discovery failed',
38
+ [BleErrorCode.DescriptorWriteFailed]: 'Descriptor write failed',
39
+ [BleErrorCode.DescriptorReadFailed]: 'Descriptor read failed',
40
+ [BleErrorCode.DescriptorNotFound]: 'Descriptor not found',
41
+ [BleErrorCode.DescriptorsNotDiscovered]: 'Descriptors not discovered',
42
+ [BleErrorCode.DescriptorInvalidDataFormat]: 'Invalid descriptor data format',
43
+ [BleErrorCode.DescriptorWriteNotAllowed]: 'Descriptor write not allowed',
44
+ [BleErrorCode.ScanStartFailed]: 'Failed to start scan',
45
+ [BleErrorCode.LocationServicesDisabled]: 'Location services are disabled'
46
+ };
47
+ /**
48
+ * BleError class that maintains 100% compatibility with react-native-ble-plx
49
+ * Contains additional properties for platform-independent error handling
50
+ */
51
+ export class BleError extends Error {
52
+ constructor(nativeBleError, errorMessageMapping = BleErrorCodeMessage) {
53
+ if (typeof nativeBleError === 'string') {
54
+ // Simple string error case
55
+ super(nativeBleError);
56
+ this.errorCode = BleErrorCode.UnknownError;
57
+ this.attErrorCode = null;
58
+ this.iosErrorCode = null;
59
+ this.androidErrorCode = null;
60
+ this.reason = nativeBleError;
61
+ return;
62
+ }
63
+ // Native BLE error case
64
+ const errorMessage = errorMessageMapping[nativeBleError.errorCode] || 'Unknown BLE error';
65
+ super(errorMessage);
66
+ this.errorCode = nativeBleError.errorCode;
67
+ this.attErrorCode = nativeBleError.attErrorCode;
68
+ this.iosErrorCode = nativeBleError.iosErrorCode;
69
+ this.androidErrorCode = nativeBleError.androidErrorCode;
70
+ this.reason = nativeBleError.reason;
71
+ if (nativeBleError.deviceID !== undefined)
72
+ this.deviceID = nativeBleError.deviceID;
73
+ if (nativeBleError.serviceUUID !== undefined)
74
+ this.serviceUUID = nativeBleError.serviceUUID;
75
+ if (nativeBleError.characteristicUUID !== undefined)
76
+ this.characteristicUUID = nativeBleError.characteristicUUID;
77
+ if (nativeBleError.descriptorUUID !== undefined)
78
+ this.descriptorUUID = nativeBleError.descriptorUUID;
79
+ if (nativeBleError.internalMessage !== undefined)
80
+ this.internalMessage = nativeBleError.internalMessage;
81
+ // Set proper prototype chain
82
+ Object.setPrototypeOf(this, BleError.prototype);
83
+ this.name = 'BleError';
84
+ }
85
+ /**
86
+ * Returns a string representation of the error with all relevant information
87
+ */
88
+ toString() {
89
+ const parts = [
90
+ `BleError: ${this.message}`,
91
+ `Error code: ${this.errorCode}`
92
+ ];
93
+ if (this.attErrorCode !== null) {
94
+ parts.push(`ATT error code: ${this.attErrorCode}`);
95
+ }
96
+ if (this.iosErrorCode !== null) {
97
+ parts.push(`iOS error code: ${this.iosErrorCode}`);
98
+ }
99
+ if (this.androidErrorCode !== null) {
100
+ parts.push(`Android error code: ${this.androidErrorCode}`);
101
+ }
102
+ if (this.reason) {
103
+ parts.push(`Reason: ${this.reason}`);
104
+ }
105
+ if (this.deviceID) {
106
+ parts.push(`Device ID: ${this.deviceID}`);
107
+ }
108
+ if (this.serviceUUID) {
109
+ parts.push(`Service UUID: ${this.serviceUUID}`);
110
+ }
111
+ if (this.characteristicUUID) {
112
+ parts.push(`Characteristic UUID: ${this.characteristicUUID}`);
113
+ }
114
+ if (this.descriptorUUID) {
115
+ parts.push(`Descriptor UUID: ${this.descriptorUUID}`);
116
+ }
117
+ return parts.join(', ');
118
+ }
119
+ }
120
+ export { BleErrorCodeMessage };
package/lib/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export * from './compatibility/constants';
2
+ export * from './utils';
3
+ export { BleManagerCompat as BleManager, createBleManagerCompat as createBleManager } from './BleManagerCompatFactory';
4
+ export * from './errors/BleError';
5
+ export { DeviceWrapper as Device } from './compatibility/deviceWrapper';
6
+ export type { BleManagerOptions, ScanOptions, ConnectionOptions, NativeBleError, NativeDevice, NativeService, NativeCharacteristic, NativeDescriptor, Subscription } from './specs/types';
7
+ export { fullUUID } from './utils/uuid';
package/lib/index.js ADDED
@@ -0,0 +1,12 @@
1
+ // Export compatibility layer types and constants
2
+ export * from './compatibility/constants';
3
+ // Export utility functions
4
+ export * from './utils';
5
+ // Export the main BleManager instance with compatibility wrapper
6
+ export { BleManagerCompat as BleManager, createBleManagerCompat as createBleManager } from './BleManagerCompatFactory';
7
+ // Export error handling utilities
8
+ export * from './errors/BleError';
9
+ // Export device wrapper for compatibility
10
+ export { DeviceWrapper as Device } from './compatibility/deviceWrapper';
11
+ // Re-export react-native-ble-plx compatible API
12
+ export { fullUUID } from './utils/uuid';
@@ -0,0 +1,36 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+ import type { State, LogLevel, UUID, DeviceId, TransactionId, ConnectionPriority, ScanOptions, ConnectionOptions, StateListener, DeviceScanListener, DeviceDisconnectedListener, CharacteristicMonitorListener, CharacteristicSubscriptionType, NativeDevice, NativeService, NativeCharacteristic, NativeDescriptor, Base64, Subscription } from './types';
3
+ export interface BleManager extends HybridObject<{
4
+ ios: 'swift';
5
+ android: 'kotlin';
6
+ }> {
7
+ destroy(): Promise<void>;
8
+ setLogLevel(logLevel: LogLevel): Promise<LogLevel>;
9
+ logLevel(): Promise<LogLevel>;
10
+ cancelTransaction(transactionId: TransactionId): Promise<void>;
11
+ enable(transactionId?: TransactionId): Promise<void>;
12
+ disable(transactionId?: TransactionId): Promise<void>;
13
+ state(): Promise<State>;
14
+ onStateChange(listener: StateListener, emitCurrentState?: boolean): Subscription;
15
+ startDeviceScan(uuids: UUID[] | null, options: ScanOptions | null, listener: DeviceScanListener): Promise<void>;
16
+ stopDeviceScan(): Promise<void>;
17
+ requestConnectionPriorityForDevice(deviceIdentifier: DeviceId, connectionPriority: ConnectionPriority, transactionId?: TransactionId): Promise<NativeDevice>;
18
+ readRSSIForDevice(deviceIdentifier: DeviceId, transactionId?: TransactionId): Promise<NativeDevice>;
19
+ requestMTUForDevice(deviceIdentifier: DeviceId, mtu: number, transactionId?: TransactionId): Promise<NativeDevice>;
20
+ devices(deviceIdentifiers: DeviceId[]): Promise<NativeDevice[]>;
21
+ connectedDevices(serviceUUIDs: UUID[]): Promise<NativeDevice[]>;
22
+ connectToDevice(deviceIdentifier: DeviceId, options?: ConnectionOptions): Promise<NativeDevice>;
23
+ cancelDeviceConnection(deviceIdentifier: DeviceId): Promise<NativeDevice>;
24
+ onDeviceDisconnected(deviceIdentifier: DeviceId, listener: DeviceDisconnectedListener): Subscription;
25
+ isDeviceConnected(deviceIdentifier: DeviceId): Promise<boolean>;
26
+ discoverAllServicesAndCharacteristicsForDevice(deviceIdentifier: DeviceId, transactionId?: TransactionId): Promise<NativeDevice>;
27
+ servicesForDevice(deviceIdentifier: DeviceId): Promise<NativeService[]>;
28
+ characteristicsForDevice(deviceIdentifier: DeviceId, serviceUUID: UUID): Promise<NativeCharacteristic[]>;
29
+ readCharacteristicForDevice(deviceIdentifier: DeviceId, serviceUUID: UUID, characteristicUUID: UUID, transactionId?: TransactionId): Promise<NativeCharacteristic>;
30
+ writeCharacteristicWithResponseForDevice(deviceIdentifier: DeviceId, serviceUUID: UUID, characteristicUUID: UUID, base64Value: Base64, transactionId?: TransactionId): Promise<NativeCharacteristic>;
31
+ writeCharacteristicWithoutResponseForDevice(deviceIdentifier: DeviceId, serviceUUID: UUID, characteristicUUID: UUID, base64Value: Base64, transactionId?: TransactionId): Promise<NativeCharacteristic>;
32
+ monitorCharacteristicForDevice(deviceIdentifier: DeviceId, serviceUUID: UUID, characteristicUUID: UUID, listener: CharacteristicMonitorListener, transactionId?: TransactionId, subscriptionType?: CharacteristicSubscriptionType): Subscription;
33
+ descriptorsForDevice(deviceIdentifier: DeviceId, serviceUUID: UUID, characteristicUUID: UUID): Promise<NativeDescriptor[]>;
34
+ readDescriptorForDevice(deviceIdentifier: DeviceId, serviceUUID: UUID, characteristicUUID: UUID, descriptorUUID: UUID, transactionId?: TransactionId): Promise<NativeDescriptor>;
35
+ writeDescriptorForDevice(deviceIdentifier: DeviceId, serviceUUID: UUID, characteristicUUID: UUID, descriptorUUID: UUID, valueBase64: Base64, transactionId?: TransactionId): Promise<NativeDescriptor>;
36
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+ import type { Identifier, UUID, DeviceId, Base64, TransactionId, CharacteristicSubscriptionType, NativeDescriptor, CharacteristicMonitorListener, Subscription } from './types';
3
+ export interface Characteristic extends HybridObject<{
4
+ ios: 'swift';
5
+ android: 'kotlin';
6
+ }> {
7
+ readonly id: Identifier;
8
+ readonly uuid: UUID;
9
+ readonly serviceID: Identifier;
10
+ readonly serviceUUID: UUID;
11
+ readonly deviceID: DeviceId;
12
+ readonly isReadable: boolean;
13
+ readonly isWritableWithResponse: boolean;
14
+ readonly isWritableWithoutResponse: boolean;
15
+ readonly isNotifiable: boolean;
16
+ readonly isNotifying: boolean;
17
+ readonly isIndicatable: boolean;
18
+ readonly value: Base64 | null;
19
+ read(transactionId?: TransactionId): Promise<Characteristic>;
20
+ writeWithResponse(valueBase64: Base64, transactionId?: TransactionId): Promise<Characteristic>;
21
+ writeWithoutResponse(valueBase64: Base64, transactionId?: TransactionId): Promise<Characteristic>;
22
+ monitor(listener: CharacteristicMonitorListener, transactionId?: TransactionId, subscriptionType?: CharacteristicSubscriptionType): Subscription;
23
+ descriptors(): Promise<NativeDescriptor[]>;
24
+ readDescriptor(descriptorUUID: UUID, transactionId?: TransactionId): Promise<NativeDescriptor>;
25
+ writeDescriptor(descriptorUUID: UUID, valueBase64: Base64, transactionId?: TransactionId): Promise<NativeDescriptor>;
26
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+ import type { Identifier, UUID, DeviceId, Base64, TransactionId } from './types';
3
+ export interface Descriptor extends HybridObject<{
4
+ ios: 'swift';
5
+ android: 'kotlin';
6
+ }> {
7
+ readonly id: Identifier;
8
+ readonly uuid: UUID;
9
+ readonly characteristicID: Identifier;
10
+ readonly characteristicUUID: UUID;
11
+ readonly serviceID: Identifier;
12
+ readonly serviceUUID: UUID;
13
+ readonly deviceID: DeviceId;
14
+ readonly value: Base64 | null;
15
+ read(transactionId?: TransactionId): Promise<Descriptor>;
16
+ write(valueBase64: Base64, transactionId?: TransactionId): Promise<Descriptor>;
17
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,37 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+ import type { DeviceId, UUID, Base64, TransactionId, ConnectionPriority, ConnectionOptions, CharacteristicSubscriptionType, ServiceDataEntry, NativeDevice, NativeService, NativeCharacteristic, NativeDescriptor, DeviceDisconnectedListener, CharacteristicMonitorListener, Subscription } from './types';
3
+ export interface Device extends HybridObject<{
4
+ ios: 'swift';
5
+ android: 'kotlin';
6
+ }> {
7
+ readonly id: DeviceId;
8
+ readonly deviceName?: string | null;
9
+ readonly rssi?: number | null;
10
+ readonly mtu: number;
11
+ readonly manufacturerData?: Base64 | null;
12
+ readonly rawScanRecord: Base64;
13
+ readonly serviceData?: ServiceDataEntry[] | null;
14
+ readonly serviceUUIDs?: UUID[] | null;
15
+ readonly localName?: string | null;
16
+ readonly txPowerLevel?: number | null;
17
+ readonly solicitedServiceUUIDs?: UUID[] | null;
18
+ readonly isConnectable?: boolean | null;
19
+ readonly overflowServiceUUIDs?: UUID[] | null;
20
+ requestConnectionPriority(connectionPriority: ConnectionPriority, transactionId?: TransactionId): Promise<NativeDevice>;
21
+ readRSSI(transactionId?: TransactionId): Promise<NativeDevice>;
22
+ requestMTU(mtu: number, transactionId?: TransactionId): Promise<NativeDevice>;
23
+ connect(options?: ConnectionOptions): Promise<NativeDevice>;
24
+ cancelConnection(): Promise<NativeDevice>;
25
+ isConnected(): Promise<boolean>;
26
+ onDisconnected(listener: DeviceDisconnectedListener): Subscription;
27
+ discoverAllServicesAndCharacteristics(transactionId?: TransactionId): Promise<NativeDevice>;
28
+ services(): Promise<NativeService[]>;
29
+ characteristicsForService(serviceUUID: UUID): Promise<NativeCharacteristic[]>;
30
+ readCharacteristicForService(serviceUUID: UUID, characteristicUUID: UUID, transactionId?: TransactionId): Promise<NativeCharacteristic>;
31
+ writeCharacteristicWithResponseForService(serviceUUID: UUID, characteristicUUID: UUID, valueBase64: Base64, transactionId?: TransactionId): Promise<NativeCharacteristic>;
32
+ writeCharacteristicWithoutResponseForService(serviceUUID: UUID, characteristicUUID: UUID, valueBase64: Base64, transactionId?: TransactionId): Promise<NativeCharacteristic>;
33
+ monitorCharacteristicForService(serviceUUID: UUID, characteristicUUID: UUID, listener: CharacteristicMonitorListener, transactionId?: TransactionId, subscriptionType?: CharacteristicSubscriptionType): Subscription;
34
+ descriptorsForService(serviceUUID: UUID, characteristicUUID: UUID): Promise<NativeDescriptor[]>;
35
+ readDescriptorForService(serviceUUID: UUID, characteristicUUID: UUID, descriptorUUID: UUID, transactionId?: TransactionId): Promise<NativeDescriptor>;
36
+ writeDescriptorForService(serviceUUID: UUID, characteristicUUID: UUID, descriptorUUID: UUID, valueBase64: Base64, transactionId?: TransactionId): Promise<NativeDescriptor>;
37
+ }
@@ -0,0 +1 @@
1
+ export {};