react-native-ble-nitro 1.0.0-alpha.1 → 1.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/BleManagerCompatFactory.d.ts +7 -6
- package/lib/BleManagerCompatFactory.js +3 -3
- package/lib/BleManagerFactory.d.ts +2 -2
- package/lib/compatibility/constants.d.ts +1 -1
- package/lib/compatibility/constants.js +1 -1
- package/lib/compatibility/deviceWrapper.d.ts +2 -2
- package/lib/compatibility/deviceWrapper.js +2 -2
- package/lib/compatibility/enums.d.ts +34 -39
- package/lib/compatibility/enums.js +126 -91
- package/lib/compatibility/index.d.ts +5 -4
- package/lib/compatibility/index.js +5 -5
- package/lib/compatibility/serviceData.d.ts +1 -1
- package/lib/errors/BleError.d.ts +2 -2
- package/lib/errors/BleError.js +1 -1
- package/lib/index.d.ts +9 -7
- package/lib/index.js +8 -6
- package/lib/specs/BleManager.nitro.d.ts +1 -1
- package/lib/specs/Characteristic.nitro.d.ts +1 -1
- package/lib/specs/Descriptor.nitro.d.ts +1 -1
- package/lib/specs/Device.nitro.d.ts +1 -1
- package/lib/specs/Service.nitro.d.ts +1 -1
- package/package.json +3 -2
- package/src/BleManagerCompatFactory.ts +12 -14
- package/src/BleManagerFactory.ts +2 -2
- package/src/__tests__/BleManager.test.ts +7 -7
- package/src/__tests__/compatibility/enums.test.ts +105 -94
- package/src/compatibility/constants.ts +1 -1
- package/src/compatibility/deviceWrapper.ts +4 -4
- package/src/compatibility/enums.ts +146 -116
- package/src/compatibility/index.ts +13 -5
- package/src/compatibility/serviceData.ts +1 -1
- package/src/errors/BleError.ts +2 -2
- package/src/index.ts +19 -7
- package/src/specs/BleManager.nitro.ts +1 -1
- package/src/specs/Characteristic.nitro.ts +1 -1
- package/src/specs/Descriptor.nitro.ts +1 -1
- package/src/specs/Device.nitro.ts +1 -1
- package/src/specs/Service.nitro.ts +1 -1
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* Creates BleManager instances with full react-native-ble-plx compatibility
|
|
5
5
|
* by wrapping the Nitro implementation with compatibility shims
|
|
6
6
|
*/
|
|
7
|
-
import type { BleManagerOptions, UUID, DeviceId, TransactionId, ConnectionPriority, ConnectionOptions, ScanOptions, NativeService, NativeCharacteristic, NativeDescriptor, LogLevel, Subscription } from './specs/types';
|
|
8
|
-
import { DeviceWrapper } from './compatibility/deviceWrapper';
|
|
7
|
+
import type { BleManagerOptions, UUID, DeviceId, TransactionId, ConnectionPriority, ConnectionOptions, ScanOptions, NativeService, NativeCharacteristic, NativeDescriptor, LogLevel, Subscription } from './specs/types.js';
|
|
8
|
+
import { DeviceWrapper } from './compatibility/deviceWrapper.js';
|
|
9
|
+
import { State as PlxState, LogLevel as PlxLogLevel } from './compatibility/enums.js';
|
|
9
10
|
/**
|
|
10
11
|
* BleManager wrapper that provides react-native-ble-plx compatibility
|
|
11
12
|
*/
|
|
@@ -13,13 +14,13 @@ export declare class BleManagerCompat {
|
|
|
13
14
|
private bleManager;
|
|
14
15
|
constructor(options?: BleManagerOptions);
|
|
15
16
|
destroy(): Promise<void>;
|
|
16
|
-
setLogLevel(logLevel: LogLevel | string): Promise<
|
|
17
|
-
logLevel(): Promise<
|
|
17
|
+
setLogLevel(logLevel: LogLevel | string): Promise<PlxLogLevel>;
|
|
18
|
+
logLevel(): Promise<PlxLogLevel>;
|
|
18
19
|
cancelTransaction(transactionId: TransactionId): Promise<void>;
|
|
19
20
|
enable(transactionId?: TransactionId): Promise<BleManagerCompat>;
|
|
20
21
|
disable(transactionId?: TransactionId): Promise<BleManagerCompat>;
|
|
21
|
-
state(): Promise<
|
|
22
|
-
onStateChange(listener: (newState:
|
|
22
|
+
state(): Promise<PlxState>;
|
|
23
|
+
onStateChange(listener: (newState: PlxState) => void, emitCurrentState?: boolean): Subscription;
|
|
23
24
|
startDeviceScan(uuids: UUID[] | null, options: ScanOptions | null, listener: (error: any | null, scannedDevice: DeviceWrapper | null) => void): Promise<void>;
|
|
24
25
|
stopDeviceScan(): Promise<void>;
|
|
25
26
|
connectToDevice(deviceIdentifier: DeviceId, options?: Partial<ConnectionOptions>): Promise<DeviceWrapper>;
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* Creates BleManager instances with full react-native-ble-plx compatibility
|
|
5
5
|
* by wrapping the Nitro implementation with compatibility shims
|
|
6
6
|
*/
|
|
7
|
-
import { createBleManager } from './BleManagerFactory';
|
|
8
|
-
import { DeviceWrapper } from './compatibility/deviceWrapper';
|
|
9
|
-
import { stateToString, logLevelToString, normalizeLogLevel, normalizeCharacteristicSubscriptionType } from './compatibility/enums';
|
|
7
|
+
import { createBleManager } from './BleManagerFactory.js';
|
|
8
|
+
import { DeviceWrapper } from './compatibility/deviceWrapper.js';
|
|
9
|
+
import { stateToString, logLevelToString, normalizeLogLevel, normalizeCharacteristicSubscriptionType } from './compatibility/enums.js';
|
|
10
10
|
/**
|
|
11
11
|
* BleManager wrapper that provides react-native-ble-plx compatibility
|
|
12
12
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { BleManager as BleManagerInterface } from './specs/BleManager.nitro';
|
|
2
|
-
import type { BleManagerOptions } from './specs/types';
|
|
1
|
+
import type { BleManager as BleManagerInterface } from './specs/BleManager.nitro.js';
|
|
2
|
+
import type { BleManagerOptions } from './specs/types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Creates a BleManager instance using Nitro Modules
|
|
5
5
|
* This function maintains compatibility with react-native-ble-plx's BleManager constructor
|
|
@@ -46,4 +46,4 @@ export declare const ConnectionPriority: {
|
|
|
46
46
|
readonly High: 1;
|
|
47
47
|
readonly LowPower: 2;
|
|
48
48
|
};
|
|
49
|
-
export { BleErrorCode, BleATTErrorCode, BleIOSErrorCode, BleAndroidErrorCode } from '../specs/types';
|
|
49
|
+
export { BleErrorCode, BleATTErrorCode, BleIOSErrorCode, BleAndroidErrorCode } from '../specs/types.js';
|
|
@@ -47,4 +47,4 @@ export const ConnectionPriority = {
|
|
|
47
47
|
LowPower: 2,
|
|
48
48
|
};
|
|
49
49
|
// Re-export all BLE error codes
|
|
50
|
-
export { BleErrorCode, BleATTErrorCode, BleIOSErrorCode, BleAndroidErrorCode } from '../specs/types';
|
|
50
|
+
export { BleErrorCode, BleATTErrorCode, BleIOSErrorCode, BleAndroidErrorCode } from '../specs/types.js';
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Wraps Nitro Device objects to provide the original react-native-ble-plx API
|
|
5
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';
|
|
6
|
+
import type { Device as NitroDevice } from '../specs/Device.nitro.js';
|
|
7
|
+
import type { UUID, Base64, DeviceId, TransactionId, ConnectionPriority, ConnectionOptions, NativeService, NativeCharacteristic, NativeDescriptor, Subscription } from '../specs/types.js';
|
|
8
8
|
/**
|
|
9
9
|
* Device wrapper that provides react-native-ble-plx compatibility
|
|
10
10
|
* Maps Nitro device properties to the expected API surface
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Wraps Nitro Device objects to provide the original react-native-ble-plx API
|
|
5
5
|
*/
|
|
6
|
-
import { serviceDataArrayToMap } from './serviceData';
|
|
7
|
-
import { normalizeCharacteristicSubscriptionType } from './enums';
|
|
6
|
+
import { serviceDataArrayToMap } from './serviceData.js';
|
|
7
|
+
import { normalizeCharacteristicSubscriptionType } from './enums.js';
|
|
8
8
|
/**
|
|
9
9
|
* Device wrapper that provides react-native-ble-plx compatibility
|
|
10
10
|
* Maps Nitro device properties to the expected API surface
|
|
@@ -1,43 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* React Native BLE Plx Compatible Enums and Types
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* These match the exact types from react-native-ble-plx for drop-in compatibility.
|
|
5
|
+
* This module provides conversion between Nitro's numeric enums and react-native-ble-plx types.
|
|
6
6
|
*/
|
|
7
|
-
import { State, LogLevel, CharacteristicSubscriptionType, RefreshGattMoment } from '../specs/types';
|
|
8
|
-
export declare
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
export declare
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
export declare
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
export declare function
|
|
32
|
-
export declare function
|
|
33
|
-
export declare function
|
|
34
|
-
export declare function
|
|
35
|
-
export declare function
|
|
36
|
-
export declare function
|
|
37
|
-
export declare function
|
|
38
|
-
export declare function stringToRefreshGattMoment(momentString: 'OnConnected'): RefreshGattMoment;
|
|
7
|
+
import { State as NitroState, LogLevel as NitroLogLevel, CharacteristicSubscriptionType as NitroCharacteristicSubscriptionType, RefreshGattMoment as NitroRefreshGattMoment } from '../specs/types.js';
|
|
8
|
+
export declare enum State {
|
|
9
|
+
Unknown = "Unknown",
|
|
10
|
+
Resetting = "Resetting",
|
|
11
|
+
Unsupported = "Unsupported",
|
|
12
|
+
Unauthorized = "Unauthorized",
|
|
13
|
+
PoweredOff = "PoweredOff",
|
|
14
|
+
PoweredOn = "PoweredOn"
|
|
15
|
+
}
|
|
16
|
+
export declare enum LogLevel {
|
|
17
|
+
None = "None",
|
|
18
|
+
Verbose = "Verbose",
|
|
19
|
+
Debug = "Debug",
|
|
20
|
+
Info = "Info",
|
|
21
|
+
Warning = "Warning",
|
|
22
|
+
Error = "Error"
|
|
23
|
+
}
|
|
24
|
+
export type CharacteristicSubscriptionType = 'notification' | 'indication';
|
|
25
|
+
export type RefreshGattMoment = 'OnConnected';
|
|
26
|
+
export declare function stateToString(state: NitroState): State;
|
|
27
|
+
export declare function logLevelToString(logLevel: NitroLogLevel): LogLevel;
|
|
28
|
+
export declare function characteristicSubscriptionTypeToString(type: NitroCharacteristicSubscriptionType): CharacteristicSubscriptionType;
|
|
29
|
+
export declare function refreshGattMomentToString(_moment: NitroRefreshGattMoment): RefreshGattMoment;
|
|
30
|
+
export declare function stringToState(stateString: State | string): NitroState;
|
|
31
|
+
export declare function stringToLogLevel(logLevelString: LogLevel | string): NitroLogLevel;
|
|
32
|
+
export declare function stringToCharacteristicSubscriptionType(typeString: CharacteristicSubscriptionType | string): NitroCharacteristicSubscriptionType;
|
|
33
|
+
export declare function stringToRefreshGattMoment(_momentString: RefreshGattMoment): NitroRefreshGattMoment;
|
|
34
|
+
export declare function normalizeState(state: NitroState | State | string): NitroState;
|
|
35
|
+
export declare function normalizeLogLevel(logLevel: NitroLogLevel | LogLevel | string): NitroLogLevel;
|
|
36
|
+
export declare function normalizeCharacteristicSubscriptionType(type: NitroCharacteristicSubscriptionType | CharacteristicSubscriptionType | string): NitroCharacteristicSubscriptionType;
|
|
37
|
+
export declare function normalizeRefreshGattMoment(_moment: NitroRefreshGattMoment | RefreshGattMoment | string): NitroRefreshGattMoment;
|
|
39
38
|
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;
|
|
@@ -1,124 +1,159 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* React Native BLE Plx Compatible Enums and Types
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* These match the exact types from react-native-ble-plx for drop-in compatibility.
|
|
5
|
+
* This module provides conversion between Nitro's numeric enums and react-native-ble-plx types.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
[
|
|
27
|
-
|
|
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
|
|
7
|
+
// Import Nitro's numeric enums with aliases to avoid naming conflicts
|
|
8
|
+
import { State as NitroState, LogLevel as NitroLogLevel, CharacteristicSubscriptionType as NitroCharacteristicSubscriptionType, RefreshGattMoment as NitroRefreshGattMoment, } from '../specs/types.js';
|
|
9
|
+
// Define exact string enums and types matching react-native-ble-plx
|
|
10
|
+
export var State;
|
|
11
|
+
(function (State) {
|
|
12
|
+
State["Unknown"] = "Unknown";
|
|
13
|
+
State["Resetting"] = "Resetting";
|
|
14
|
+
State["Unsupported"] = "Unsupported";
|
|
15
|
+
State["Unauthorized"] = "Unauthorized";
|
|
16
|
+
State["PoweredOff"] = "PoweredOff";
|
|
17
|
+
State["PoweredOn"] = "PoweredOn";
|
|
18
|
+
})(State || (State = {}));
|
|
19
|
+
export var LogLevel;
|
|
20
|
+
(function (LogLevel) {
|
|
21
|
+
LogLevel["None"] = "None";
|
|
22
|
+
LogLevel["Verbose"] = "Verbose";
|
|
23
|
+
LogLevel["Debug"] = "Debug";
|
|
24
|
+
LogLevel["Info"] = "Info";
|
|
25
|
+
LogLevel["Warning"] = "Warning";
|
|
26
|
+
LogLevel["Error"] = "Error";
|
|
27
|
+
})(LogLevel || (LogLevel = {}));
|
|
28
|
+
// Conversion functions from Nitro numeric enums to react-native-ble-plx string enums/types
|
|
51
29
|
export function stateToString(state) {
|
|
52
|
-
|
|
30
|
+
const mapping = {
|
|
31
|
+
[NitroState.Unknown]: State.Unknown,
|
|
32
|
+
[NitroState.Resetting]: State.Resetting,
|
|
33
|
+
[NitroState.Unsupported]: State.Unsupported,
|
|
34
|
+
[NitroState.Unauthorized]: State.Unauthorized,
|
|
35
|
+
[NitroState.PoweredOff]: State.PoweredOff,
|
|
36
|
+
[NitroState.PoweredOn]: State.PoweredOn,
|
|
37
|
+
};
|
|
38
|
+
return mapping[state] ?? State.Unknown;
|
|
53
39
|
}
|
|
40
|
+
export function logLevelToString(logLevel) {
|
|
41
|
+
const mapping = {
|
|
42
|
+
[NitroLogLevel.None]: LogLevel.None,
|
|
43
|
+
[NitroLogLevel.Verbose]: LogLevel.Verbose,
|
|
44
|
+
[NitroLogLevel.Debug]: LogLevel.Debug,
|
|
45
|
+
[NitroLogLevel.Info]: LogLevel.Info,
|
|
46
|
+
[NitroLogLevel.Warning]: LogLevel.Warning,
|
|
47
|
+
[NitroLogLevel.Error]: LogLevel.Error,
|
|
48
|
+
};
|
|
49
|
+
return mapping[logLevel] ?? LogLevel.None;
|
|
50
|
+
}
|
|
51
|
+
export function characteristicSubscriptionTypeToString(type) {
|
|
52
|
+
const mapping = {
|
|
53
|
+
[NitroCharacteristicSubscriptionType.Notification]: 'notification',
|
|
54
|
+
[NitroCharacteristicSubscriptionType.Indication]: 'indication',
|
|
55
|
+
};
|
|
56
|
+
return mapping[type] ?? 'notification';
|
|
57
|
+
}
|
|
58
|
+
export function refreshGattMomentToString(_moment) {
|
|
59
|
+
return 'OnConnected'; // Only one value exists
|
|
60
|
+
}
|
|
61
|
+
// Conversion functions from react-native-ble-plx string enums/types to Nitro numeric enums
|
|
54
62
|
export function stringToState(stateString) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
switch (stateString) {
|
|
64
|
+
case State.Unknown:
|
|
65
|
+
case 'Unknown':
|
|
66
|
+
return NitroState.Unknown;
|
|
67
|
+
case State.Resetting:
|
|
68
|
+
case 'Resetting':
|
|
69
|
+
return NitroState.Resetting;
|
|
70
|
+
case State.Unsupported:
|
|
71
|
+
case 'Unsupported':
|
|
72
|
+
return NitroState.Unsupported;
|
|
73
|
+
case State.Unauthorized:
|
|
74
|
+
case 'Unauthorized':
|
|
75
|
+
return NitroState.Unauthorized;
|
|
76
|
+
case State.PoweredOff:
|
|
77
|
+
case 'PoweredOff':
|
|
78
|
+
return NitroState.PoweredOff;
|
|
79
|
+
case State.PoweredOn:
|
|
80
|
+
case 'PoweredOn':
|
|
81
|
+
return NitroState.PoweredOn;
|
|
82
|
+
default:
|
|
83
|
+
return NitroState.Unknown;
|
|
61
84
|
}
|
|
62
|
-
return State.Unknown;
|
|
63
|
-
}
|
|
64
|
-
export function logLevelToString(logLevel) {
|
|
65
|
-
return LogLevelString[logLevel] ?? 'None';
|
|
66
85
|
}
|
|
67
86
|
export function stringToLogLevel(logLevelString) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
87
|
+
switch (logLevelString) {
|
|
88
|
+
case LogLevel.None:
|
|
89
|
+
case 'None':
|
|
90
|
+
return NitroLogLevel.None;
|
|
91
|
+
case LogLevel.Verbose:
|
|
92
|
+
case 'Verbose':
|
|
93
|
+
return NitroLogLevel.Verbose;
|
|
94
|
+
case LogLevel.Debug:
|
|
95
|
+
case 'Debug':
|
|
96
|
+
return NitroLogLevel.Debug;
|
|
97
|
+
case LogLevel.Info:
|
|
98
|
+
case 'Info':
|
|
99
|
+
return NitroLogLevel.Info;
|
|
100
|
+
case LogLevel.Warning:
|
|
101
|
+
case 'Warning':
|
|
102
|
+
return NitroLogLevel.Warning;
|
|
103
|
+
case LogLevel.Error:
|
|
104
|
+
case 'Error':
|
|
105
|
+
return NitroLogLevel.Error;
|
|
106
|
+
default:
|
|
107
|
+
return NitroLogLevel.None;
|
|
74
108
|
}
|
|
75
|
-
return LogLevel.None;
|
|
76
|
-
}
|
|
77
|
-
export function characteristicSubscriptionTypeToString(type) {
|
|
78
|
-
return CharacteristicSubscriptionTypeString[type] ?? 'notification';
|
|
79
109
|
}
|
|
80
110
|
export function stringToCharacteristicSubscriptionType(typeString) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return
|
|
86
|
-
|
|
111
|
+
switch (typeString) {
|
|
112
|
+
case 'notification':
|
|
113
|
+
return NitroCharacteristicSubscriptionType.Notification;
|
|
114
|
+
case 'indication':
|
|
115
|
+
return NitroCharacteristicSubscriptionType.Indication;
|
|
116
|
+
default:
|
|
117
|
+
return NitroCharacteristicSubscriptionType.Notification;
|
|
87
118
|
}
|
|
88
|
-
return CharacteristicSubscriptionType.Notification;
|
|
89
119
|
}
|
|
90
|
-
export function
|
|
91
|
-
return
|
|
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';
|
|
120
|
+
export function stringToRefreshGattMoment(_momentString) {
|
|
121
|
+
return NitroRefreshGattMoment.OnConnected;
|
|
99
122
|
}
|
|
100
123
|
// Generic converter that handles both string and numeric enum values
|
|
101
124
|
export function normalizeState(state) {
|
|
102
125
|
if (typeof state === 'string') {
|
|
103
126
|
return stringToState(state);
|
|
104
127
|
}
|
|
105
|
-
return
|
|
128
|
+
// If it's already a NitroState (numeric), return as-is
|
|
129
|
+
if (typeof state === 'number') {
|
|
130
|
+
return state;
|
|
131
|
+
}
|
|
132
|
+
// If it's a string State enum value, convert it
|
|
133
|
+
return stringToState(state);
|
|
106
134
|
}
|
|
107
135
|
export function normalizeLogLevel(logLevel) {
|
|
108
136
|
if (typeof logLevel === 'string') {
|
|
109
137
|
return stringToLogLevel(logLevel);
|
|
110
138
|
}
|
|
111
|
-
return
|
|
139
|
+
// If it's already a NitroLogLevel (numeric), return as-is
|
|
140
|
+
if (typeof logLevel === 'number') {
|
|
141
|
+
return logLevel;
|
|
142
|
+
}
|
|
143
|
+
// If it's a string LogLevel enum value, convert it
|
|
144
|
+
return stringToLogLevel(logLevel);
|
|
112
145
|
}
|
|
113
146
|
export function normalizeCharacteristicSubscriptionType(type) {
|
|
114
147
|
if (typeof type === 'string') {
|
|
115
148
|
return stringToCharacteristicSubscriptionType(type);
|
|
116
149
|
}
|
|
150
|
+
// If it's already a NitroCharacteristicSubscriptionType (numeric), return as-is
|
|
117
151
|
return type;
|
|
118
152
|
}
|
|
119
|
-
export function normalizeRefreshGattMoment(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
153
|
+
export function normalizeRefreshGattMoment(_moment) {
|
|
154
|
+
return NitroRefreshGattMoment.OnConnected; // Only one value exists
|
|
155
|
+
}
|
|
156
|
+
// Helper function to detect if a value is a string enum vs numeric enum
|
|
157
|
+
export function isStringEnumValue(value) {
|
|
158
|
+
return typeof value === 'string';
|
|
124
159
|
}
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* 100% API compatibility with react-native-ble-plx while working with
|
|
6
6
|
* Nitro's type system constraints.
|
|
7
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';
|
|
8
|
+
export * from './serviceData.js';
|
|
9
|
+
export * from './deviceWrapper.js';
|
|
10
|
+
export * from './constants.js';
|
|
11
|
+
export { stateToString, stringToState, logLevelToString, stringToLogLevel, characteristicSubscriptionTypeToString, stringToCharacteristicSubscriptionType, normalizeState, normalizeLogLevel, normalizeCharacteristicSubscriptionType, State, LogLevel } from './enums.js';
|
|
12
|
+
export type { CharacteristicSubscriptionType, RefreshGattMoment } from './enums.js';
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* 100% API compatibility with react-native-ble-plx while working with
|
|
6
6
|
* Nitro's type system constraints.
|
|
7
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';
|
|
8
|
+
export * from './serviceData.js';
|
|
9
|
+
export * from './deviceWrapper.js';
|
|
10
|
+
export * from './constants.js';
|
|
11
|
+
// Explicitly export enum utilities and enums to avoid conflicts
|
|
12
|
+
export { stateToString, stringToState, logLevelToString, stringToLogLevel, characteristicSubscriptionTypeToString, stringToCharacteristicSubscriptionType, normalizeState, normalizeLogLevel, normalizeCharacteristicSubscriptionType, State, LogLevel } from './enums.js';
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Provides conversion between Nitro's structured ServiceDataEntry[] format
|
|
5
5
|
* and the original { [uuid: string]: Base64 } format from react-native-ble-plx
|
|
6
6
|
*/
|
|
7
|
-
import type { ServiceDataEntry, UUID, Base64 } from '../specs/types';
|
|
7
|
+
import type { ServiceDataEntry, UUID, Base64 } from '../specs/types.js';
|
|
8
8
|
/**
|
|
9
9
|
* Convert ServiceDataEntry array to the original index signature format
|
|
10
10
|
*/
|
package/lib/errors/BleError.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BleErrorCode, BleATTErrorCode, BleIOSErrorCode, BleAndroidErrorCode } from '../specs/types';
|
|
2
|
-
import type { NativeBleError, BleErrorCodeMessageMapping } from '../specs/types';
|
|
1
|
+
import { BleErrorCode, BleATTErrorCode, BleIOSErrorCode, BleAndroidErrorCode } from '../specs/types.js';
|
|
2
|
+
import type { NativeBleError, BleErrorCodeMessageMapping } from '../specs/types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Default error messages for BLE error codes
|
|
5
5
|
* Maintains compatibility with react-native-ble-plx error messages
|
package/lib/errors/BleError.js
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
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 {
|
|
1
|
+
export * from './compatibility/constants.js';
|
|
2
|
+
export * from './utils/index.js';
|
|
3
|
+
export { BleManagerCompat as BleManager, createBleManagerCompat as createBleManager } from './BleManagerCompatFactory.js';
|
|
4
|
+
export * from './errors/BleError.js';
|
|
5
|
+
export { DeviceWrapper as Device } from './compatibility/deviceWrapper.js';
|
|
6
|
+
export type { BleManagerOptions, ScanOptions, ConnectionOptions, NativeBleError, NativeDevice, NativeService, NativeCharacteristic, NativeDescriptor, Subscription } from './specs/types.js';
|
|
7
|
+
export { State, LogLevel } from './compatibility/enums.js';
|
|
8
|
+
export type { CharacteristicSubscriptionType, RefreshGattMoment } from './compatibility/enums.js';
|
|
9
|
+
export { fullUUID } from './utils/uuid.js';
|
package/lib/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
// Export compatibility layer types and constants
|
|
2
|
-
export * from './compatibility/constants';
|
|
2
|
+
export * from './compatibility/constants.js';
|
|
3
3
|
// Export utility functions
|
|
4
|
-
export * from './utils';
|
|
4
|
+
export * from './utils/index.js';
|
|
5
5
|
// Export the main BleManager instance with compatibility wrapper
|
|
6
|
-
export { BleManagerCompat as BleManager, createBleManagerCompat as createBleManager } from './BleManagerCompatFactory';
|
|
6
|
+
export { BleManagerCompat as BleManager, createBleManagerCompat as createBleManager } from './BleManagerCompatFactory.js';
|
|
7
7
|
// Export error handling utilities
|
|
8
|
-
export * from './errors/BleError';
|
|
8
|
+
export * from './errors/BleError.js';
|
|
9
9
|
// Export device wrapper for compatibility
|
|
10
|
-
export { DeviceWrapper as Device } from './compatibility/deviceWrapper';
|
|
10
|
+
export { DeviceWrapper as Device } from './compatibility/deviceWrapper.js';
|
|
11
|
+
// Export react-native-ble-plx compatible enum types (drop-in replacement)
|
|
12
|
+
export { State, LogLevel } from './compatibility/enums.js';
|
|
11
13
|
// Re-export react-native-ble-plx compatible API
|
|
12
|
-
export { fullUUID } from './utils/uuid';
|
|
14
|
+
export { fullUUID } from './utils/uuid.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
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';
|
|
2
|
+
import type { State, LogLevel, UUID, DeviceId, TransactionId, ConnectionPriority, ScanOptions, ConnectionOptions, StateListener, DeviceScanListener, DeviceDisconnectedListener, CharacteristicMonitorListener, CharacteristicSubscriptionType, NativeDevice, NativeService, NativeCharacteristic, NativeDescriptor, Base64, Subscription } from './types.js';
|
|
3
3
|
export interface BleManager extends HybridObject<{
|
|
4
4
|
ios: 'swift';
|
|
5
5
|
android: 'kotlin';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
-
import type { Identifier, UUID, DeviceId, Base64, TransactionId, CharacteristicSubscriptionType, NativeDescriptor, CharacteristicMonitorListener, Subscription } from './types';
|
|
2
|
+
import type { Identifier, UUID, DeviceId, Base64, TransactionId, CharacteristicSubscriptionType, NativeDescriptor, CharacteristicMonitorListener, Subscription } from './types.js';
|
|
3
3
|
export interface Characteristic extends HybridObject<{
|
|
4
4
|
ios: 'swift';
|
|
5
5
|
android: 'kotlin';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
-
import type { Identifier, UUID, DeviceId, Base64, TransactionId } from './types';
|
|
2
|
+
import type { Identifier, UUID, DeviceId, Base64, TransactionId } from './types.js';
|
|
3
3
|
export interface Descriptor extends HybridObject<{
|
|
4
4
|
ios: 'swift';
|
|
5
5
|
android: 'kotlin';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
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';
|
|
2
|
+
import type { DeviceId, UUID, Base64, TransactionId, ConnectionPriority, ConnectionOptions, CharacteristicSubscriptionType, ServiceDataEntry, NativeDevice, NativeService, NativeCharacteristic, NativeDescriptor, DeviceDisconnectedListener, CharacteristicMonitorListener, Subscription } from './types.js';
|
|
3
3
|
export interface Device extends HybridObject<{
|
|
4
4
|
ios: 'swift';
|
|
5
5
|
android: 'kotlin';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
-
import type { Identifier, UUID, DeviceId, Base64, TransactionId, CharacteristicSubscriptionType, NativeCharacteristic, NativeDescriptor, CharacteristicMonitorListener, Subscription } from './types';
|
|
2
|
+
import type { Identifier, UUID, DeviceId, Base64, TransactionId, CharacteristicSubscriptionType, NativeCharacteristic, NativeDescriptor, CharacteristicMonitorListener, Subscription } from './types.js';
|
|
3
3
|
export interface Service extends HybridObject<{
|
|
4
4
|
ios: 'swift';
|
|
5
5
|
android: 'kotlin';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-ble-nitro",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-beta.0",
|
|
4
4
|
"description": "High-performance React Native BLE library built on Nitro Modules - drop-in replacement for react-native-ble-plx",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -9,10 +9,11 @@
|
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"react-native": "./src/index.ts",
|
|
12
|
+
"typescript": "./src/index.ts",
|
|
12
13
|
"import": "./lib/index.js",
|
|
13
14
|
"require": "./lib/index.js",
|
|
14
15
|
"types": "./lib/index.d.ts",
|
|
15
|
-
"default": "./
|
|
16
|
+
"default": "./src/index.ts"
|
|
16
17
|
},
|
|
17
18
|
"./plugin": {
|
|
18
19
|
"import": "./plugin/build/index.js",
|