munim-bluetooth 0.1.0 → 0.2.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/README.md +497 -4
- package/android/src/main/AndroidManifest.xml +18 -0
- package/android/src/main/java/com/munimbluetooth/HybridMunimBluetooth.kt +700 -3
- package/ios/HybridMunimBluetooth.swift +622 -3
- package/lib/commonjs/index.js +247 -2
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +227 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/index.d.ts +161 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/munim-bluetooth.nitro.d.ts +193 -1
- package/lib/typescript/src/specs/munim-bluetooth.nitro.d.ts.map +1 -1
- package/package.json +5 -2
- package/src/index.ts +287 -3
- package/src/specs/munim-bluetooth.nitro.ts +266 -3
|
@@ -1,8 +1,200 @@
|
|
|
1
1
|
import { type HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
export interface AdvertisingDataTypes {
|
|
3
|
+
flags?: number;
|
|
4
|
+
incompleteServiceUUIDs16?: string[];
|
|
5
|
+
completeServiceUUIDs16?: string[];
|
|
6
|
+
incompleteServiceUUIDs32?: string[];
|
|
7
|
+
completeServiceUUIDs32?: string[];
|
|
8
|
+
incompleteServiceUUIDs128?: string[];
|
|
9
|
+
completeServiceUUIDs128?: string[];
|
|
10
|
+
shortenedLocalName?: string;
|
|
11
|
+
completeLocalName?: string;
|
|
12
|
+
txPowerLevel?: number;
|
|
13
|
+
serviceSolicitationUUIDs16?: string[];
|
|
14
|
+
serviceSolicitationUUIDs128?: string[];
|
|
15
|
+
serviceData16?: Array<{
|
|
16
|
+
uuid: string;
|
|
17
|
+
data: string;
|
|
18
|
+
}>;
|
|
19
|
+
serviceData32?: Array<{
|
|
20
|
+
uuid: string;
|
|
21
|
+
data: string;
|
|
22
|
+
}>;
|
|
23
|
+
serviceData128?: Array<{
|
|
24
|
+
uuid: string;
|
|
25
|
+
data: string;
|
|
26
|
+
}>;
|
|
27
|
+
appearance?: number;
|
|
28
|
+
serviceSolicitationUUIDs32?: string[];
|
|
29
|
+
manufacturerData?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface BLEDevice {
|
|
32
|
+
id: string;
|
|
33
|
+
name?: string;
|
|
34
|
+
rssi?: number;
|
|
35
|
+
advertisingData?: AdvertisingDataTypes;
|
|
36
|
+
serviceUUIDs?: string[];
|
|
37
|
+
isConnectable?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface ScanOptions {
|
|
40
|
+
serviceUUIDs?: string[];
|
|
41
|
+
allowDuplicates?: boolean;
|
|
42
|
+
scanMode?: 'lowPower' | 'balanced' | 'lowLatency';
|
|
43
|
+
}
|
|
44
|
+
export interface GATTService {
|
|
45
|
+
uuid: string;
|
|
46
|
+
characteristics: Array<{
|
|
47
|
+
uuid: string;
|
|
48
|
+
properties: string[];
|
|
49
|
+
value?: string;
|
|
50
|
+
}>;
|
|
51
|
+
}
|
|
52
|
+
export interface CharacteristicValue {
|
|
53
|
+
value: string;
|
|
54
|
+
serviceUUID: string;
|
|
55
|
+
characteristicUUID: string;
|
|
56
|
+
}
|
|
2
57
|
export interface MunimBluetooth extends HybridObject<{
|
|
3
58
|
ios: 'swift';
|
|
4
59
|
android: 'kotlin';
|
|
5
60
|
}> {
|
|
6
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Start advertising as a Bluetooth peripheral with supported advertising data.
|
|
63
|
+
*
|
|
64
|
+
* @param options - An object with serviceUUIDs (string[]) and supported advertising data types.
|
|
65
|
+
* This must be a plain JS object (no Maps/Sets/functions).
|
|
66
|
+
*/
|
|
67
|
+
startAdvertising(options: {
|
|
68
|
+
serviceUUIDs: string[];
|
|
69
|
+
localName?: string;
|
|
70
|
+
manufacturerData?: string;
|
|
71
|
+
advertisingData?: AdvertisingDataTypes;
|
|
72
|
+
}): void;
|
|
73
|
+
/**
|
|
74
|
+
* Update advertising data while advertising is active.
|
|
75
|
+
*
|
|
76
|
+
* @param advertisingData - The new advertising data to use.
|
|
77
|
+
*/
|
|
78
|
+
updateAdvertisingData(advertisingData: AdvertisingDataTypes): void;
|
|
79
|
+
/**
|
|
80
|
+
* Get current advertising data.
|
|
81
|
+
*
|
|
82
|
+
* @returns Promise resolving to current advertising data.
|
|
83
|
+
*/
|
|
84
|
+
getAdvertisingData(): Promise<AdvertisingDataTypes>;
|
|
85
|
+
/**
|
|
86
|
+
* Stop BLE advertising.
|
|
87
|
+
*/
|
|
88
|
+
stopAdvertising(): void;
|
|
89
|
+
/**
|
|
90
|
+
* Set GATT services and characteristics for the Bluetooth peripheral.
|
|
91
|
+
*
|
|
92
|
+
* @param services - An array of service objects, each with a uuid and an array of characteristics.
|
|
93
|
+
* This must be serializable to a plain JS array (no Maps/Sets/functions).
|
|
94
|
+
*/
|
|
95
|
+
setServices(services: GATTService[]): void;
|
|
96
|
+
/**
|
|
97
|
+
* Check if Bluetooth is enabled on the device.
|
|
98
|
+
*
|
|
99
|
+
* @returns Promise resolving to true if Bluetooth is enabled, false otherwise.
|
|
100
|
+
*/
|
|
101
|
+
isBluetoothEnabled(): Promise<boolean>;
|
|
102
|
+
/**
|
|
103
|
+
* Request Bluetooth permissions (Android) or check authorization status (iOS).
|
|
104
|
+
*
|
|
105
|
+
* @returns Promise resolving to true if permissions are granted, false otherwise.
|
|
106
|
+
*/
|
|
107
|
+
requestBluetoothPermission(): Promise<boolean>;
|
|
108
|
+
/**
|
|
109
|
+
* Start scanning for BLE devices.
|
|
110
|
+
*
|
|
111
|
+
* @param options - Optional scan configuration including service UUIDs to filter by.
|
|
112
|
+
*/
|
|
113
|
+
startScan(options?: ScanOptions): void;
|
|
114
|
+
/**
|
|
115
|
+
* Stop scanning for BLE devices.
|
|
116
|
+
*/
|
|
117
|
+
stopScan(): void;
|
|
118
|
+
/**
|
|
119
|
+
* Connect to a BLE device.
|
|
120
|
+
*
|
|
121
|
+
* @param deviceId - The unique identifier of the device to connect to.
|
|
122
|
+
* @returns Promise resolving when connection is established or rejected.
|
|
123
|
+
*/
|
|
124
|
+
connect(deviceId: string): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Disconnect from a BLE device.
|
|
127
|
+
*
|
|
128
|
+
* @param deviceId - The unique identifier of the device to disconnect from.
|
|
129
|
+
*/
|
|
130
|
+
disconnect(deviceId: string): void;
|
|
131
|
+
/**
|
|
132
|
+
* Discover GATT services for a connected device.
|
|
133
|
+
*
|
|
134
|
+
* @param deviceId - The unique identifier of the connected device.
|
|
135
|
+
* @returns Promise resolving to array of discovered services.
|
|
136
|
+
*/
|
|
137
|
+
discoverServices(deviceId: string): Promise<GATTService[]>;
|
|
138
|
+
/**
|
|
139
|
+
* Read a characteristic value from a connected device.
|
|
140
|
+
*
|
|
141
|
+
* @param deviceId - The unique identifier of the connected device.
|
|
142
|
+
* @param serviceUUID - The UUID of the service containing the characteristic.
|
|
143
|
+
* @param characteristicUUID - The UUID of the characteristic to read.
|
|
144
|
+
* @returns Promise resolving to the characteristic value.
|
|
145
|
+
*/
|
|
146
|
+
readCharacteristic(deviceId: string, serviceUUID: string, characteristicUUID: string): Promise<CharacteristicValue>;
|
|
147
|
+
/**
|
|
148
|
+
* Write a value to a characteristic on a connected device.
|
|
149
|
+
*
|
|
150
|
+
* @param deviceId - The unique identifier of the connected device.
|
|
151
|
+
* @param serviceUUID - The UUID of the service containing the characteristic.
|
|
152
|
+
* @param characteristicUUID - The UUID of the characteristic to write.
|
|
153
|
+
* @param value - The value to write (hex string).
|
|
154
|
+
* @param writeType - Optional write type: 'write' or 'writeWithoutResponse'. Defaults to 'write'.
|
|
155
|
+
* @returns Promise resolving when write is complete.
|
|
156
|
+
*/
|
|
157
|
+
writeCharacteristic(deviceId: string, serviceUUID: string, characteristicUUID: string, value: string, writeType?: 'write' | 'writeWithoutResponse'): Promise<void>;
|
|
158
|
+
/**
|
|
159
|
+
* Subscribe to notifications/indications from a characteristic.
|
|
160
|
+
*
|
|
161
|
+
* @param deviceId - The unique identifier of the connected device.
|
|
162
|
+
* @param serviceUUID - The UUID of the service containing the characteristic.
|
|
163
|
+
* @param characteristicUUID - The UUID of the characteristic to subscribe to.
|
|
164
|
+
*/
|
|
165
|
+
subscribeToCharacteristic(deviceId: string, serviceUUID: string, characteristicUUID: string): void;
|
|
166
|
+
/**
|
|
167
|
+
* Unsubscribe from notifications/indications from a characteristic.
|
|
168
|
+
*
|
|
169
|
+
* @param deviceId - The unique identifier of the connected device.
|
|
170
|
+
* @param serviceUUID - The UUID of the service containing the characteristic.
|
|
171
|
+
* @param characteristicUUID - The UUID of the characteristic to unsubscribe from.
|
|
172
|
+
*/
|
|
173
|
+
unsubscribeFromCharacteristic(deviceId: string, serviceUUID: string, characteristicUUID: string): void;
|
|
174
|
+
/**
|
|
175
|
+
* Get list of currently connected devices.
|
|
176
|
+
*
|
|
177
|
+
* @returns Promise resolving to array of connected device IDs.
|
|
178
|
+
*/
|
|
179
|
+
getConnectedDevices(): Promise<string[]>;
|
|
180
|
+
/**
|
|
181
|
+
* Read RSSI (signal strength) for a connected device.
|
|
182
|
+
*
|
|
183
|
+
* @param deviceId - The unique identifier of the connected device.
|
|
184
|
+
* @returns Promise resolving to RSSI value in dBm.
|
|
185
|
+
*/
|
|
186
|
+
readRSSI(deviceId: string): Promise<number>;
|
|
187
|
+
/**
|
|
188
|
+
* Add an event listener.
|
|
189
|
+
*
|
|
190
|
+
* @param eventName - The name of the event to listen for.
|
|
191
|
+
*/
|
|
192
|
+
addListener(eventName: string): void;
|
|
193
|
+
/**
|
|
194
|
+
* Remove event listeners.
|
|
195
|
+
*
|
|
196
|
+
* @param count - Number of listeners to remove.
|
|
197
|
+
*/
|
|
198
|
+
removeListeners(count: number): void;
|
|
7
199
|
}
|
|
8
200
|
//# sourceMappingURL=munim-bluetooth.nitro.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"munim-bluetooth.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/munim-bluetooth.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"munim-bluetooth.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/munim-bluetooth.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAG9D,MAAM,WAAW,oBAAoB;IAEnC,KAAK,CAAC,EAAE,MAAM,CAAA;IAGd,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAA;IACnC,sBAAsB,CAAC,EAAE,MAAM,EAAE,CAAA;IACjC,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAA;IACnC,sBAAsB,CAAC,EAAE,MAAM,EAAE,CAAA;IACjC,yBAAyB,CAAC,EAAE,MAAM,EAAE,CAAA;IACpC,uBAAuB,CAAC,EAAE,MAAM,EAAE,CAAA;IAGlC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAG1B,YAAY,CAAC,EAAE,MAAM,CAAA;IAGrB,0BAA0B,CAAC,EAAE,MAAM,EAAE,CAAA;IACrC,2BAA2B,CAAC,EAAE,MAAM,EAAE,CAAA;IAGtC,aAAa,CAAC,EAAE,KAAK,CAAC;QACpB,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,EAAE,MAAM,CAAA;KACb,CAAC,CAAA;IACF,aAAa,CAAC,EAAE,KAAK,CAAC;QACpB,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,EAAE,MAAM,CAAA;KACb,CAAC,CAAA;IACF,cAAc,CAAC,EAAE,KAAK,CAAC;QACrB,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,EAAE,MAAM,CAAA;KACb,CAAC,CAAA;IAGF,UAAU,CAAC,EAAE,MAAM,CAAA;IAGnB,0BAA0B,CAAC,EAAE,MAAM,EAAE,CAAA;IAGrC,gBAAgB,CAAC,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BAAkB,EAAE,MAAM,GACzB,IAAI,CAAA;IAEP;;;;OAIG;IACH,mBAAmB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;IAExC;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAI3C;;;;OAIG;IACH,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IAEpC;;;;OAIG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CACrC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "munim-bluetooth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "munim-bluetooth is a react native package for all your Bluetooth, BLE, and BLE pheripheral needs",
|
|
5
5
|
"main": "./lib/commonjs/index.js",
|
|
6
6
|
"module": "./lib/module/index.js",
|
|
@@ -42,7 +42,10 @@
|
|
|
42
42
|
"workspaces": [
|
|
43
43
|
"example"
|
|
44
44
|
],
|
|
45
|
-
"repository":
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "https://github.com/munimtechnologies/munim-bluetooth.git"
|
|
48
|
+
},
|
|
46
49
|
"author": "sheehanmunim",
|
|
47
50
|
"license": "MIT",
|
|
48
51
|
"bugs": "https://github.com/munimtechnologies/munim-bluetooth/issues",
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,289 @@
|
|
|
1
1
|
import { NitroModules } from 'react-native-nitro-modules'
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
MunimBluetooth as MunimBluetoothSpec,
|
|
4
|
+
AdvertisingDataTypes,
|
|
5
|
+
BLEDevice,
|
|
6
|
+
ScanOptions,
|
|
7
|
+
GATTService,
|
|
8
|
+
CharacteristicValue,
|
|
9
|
+
} from './specs/munim-bluetooth.nitro'
|
|
3
10
|
|
|
4
|
-
|
|
5
|
-
NitroModules.createHybridObject<MunimBluetoothSpec>('MunimBluetooth')
|
|
11
|
+
const MunimBluetooth =
|
|
12
|
+
NitroModules.createHybridObject<MunimBluetoothSpec>('MunimBluetooth')
|
|
13
|
+
|
|
14
|
+
// ========== Peripheral Features ==========
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Start advertising as a Bluetooth peripheral with supported advertising data.
|
|
18
|
+
*
|
|
19
|
+
* @param options - An object with serviceUUIDs (string[]) and supported advertising data types.
|
|
20
|
+
*/
|
|
21
|
+
export function startAdvertising(options: {
|
|
22
|
+
serviceUUIDs: string[];
|
|
23
|
+
localName?: string;
|
|
24
|
+
manufacturerData?: string;
|
|
25
|
+
advertisingData?: AdvertisingDataTypes;
|
|
26
|
+
}): void {
|
|
27
|
+
return MunimBluetooth.startAdvertising(options)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Update advertising data while advertising is active.
|
|
32
|
+
*
|
|
33
|
+
* @param advertisingData - The new advertising data to use.
|
|
34
|
+
*/
|
|
35
|
+
export function updateAdvertisingData(
|
|
36
|
+
advertisingData: AdvertisingDataTypes
|
|
37
|
+
): void {
|
|
38
|
+
return MunimBluetooth.updateAdvertisingData(advertisingData)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Get current advertising data.
|
|
43
|
+
*
|
|
44
|
+
* @returns Promise resolving to current advertising data.
|
|
45
|
+
*/
|
|
46
|
+
export function getAdvertisingData(): Promise<AdvertisingDataTypes> {
|
|
47
|
+
return MunimBluetooth.getAdvertisingData()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Stop BLE advertising.
|
|
52
|
+
*/
|
|
53
|
+
export function stopAdvertising(): void {
|
|
54
|
+
return MunimBluetooth.stopAdvertising()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Set GATT services and characteristics for the Bluetooth peripheral.
|
|
59
|
+
*
|
|
60
|
+
* @param services - An array of service objects, each with a uuid and an array of characteristics.
|
|
61
|
+
*/
|
|
62
|
+
export function setServices(services: GATTService[]): void {
|
|
63
|
+
return MunimBluetooth.setServices(services)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ========== Central/Manager Features ==========
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Check if Bluetooth is enabled on the device.
|
|
70
|
+
*
|
|
71
|
+
* @returns Promise resolving to true if Bluetooth is enabled, false otherwise.
|
|
72
|
+
*/
|
|
73
|
+
export function isBluetoothEnabled(): Promise<boolean> {
|
|
74
|
+
return MunimBluetooth.isBluetoothEnabled()
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Request Bluetooth permissions (Android) or check authorization status (iOS).
|
|
79
|
+
*
|
|
80
|
+
* @returns Promise resolving to true if permissions are granted, false otherwise.
|
|
81
|
+
*/
|
|
82
|
+
export function requestBluetoothPermission(): Promise<boolean> {
|
|
83
|
+
return MunimBluetooth.requestBluetoothPermission()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Start scanning for BLE devices.
|
|
88
|
+
*
|
|
89
|
+
* @param options - Optional scan configuration including service UUIDs to filter by.
|
|
90
|
+
*/
|
|
91
|
+
export function startScan(options?: ScanOptions): void {
|
|
92
|
+
return MunimBluetooth.startScan(options)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Stop scanning for BLE devices.
|
|
97
|
+
*/
|
|
98
|
+
export function stopScan(): void {
|
|
99
|
+
return MunimBluetooth.stopScan()
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Connect to a BLE device.
|
|
104
|
+
*
|
|
105
|
+
* @param deviceId - The unique identifier of the device to connect to.
|
|
106
|
+
* @returns Promise resolving when connection is established or rejected.
|
|
107
|
+
*/
|
|
108
|
+
export function connect(deviceId: string): Promise<void> {
|
|
109
|
+
return MunimBluetooth.connect(deviceId)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Disconnect from a BLE device.
|
|
114
|
+
*
|
|
115
|
+
* @param deviceId - The unique identifier of the device to disconnect from.
|
|
116
|
+
*/
|
|
117
|
+
export function disconnect(deviceId: string): void {
|
|
118
|
+
return MunimBluetooth.disconnect(deviceId)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Discover GATT services for a connected device.
|
|
123
|
+
*
|
|
124
|
+
* @param deviceId - The unique identifier of the connected device.
|
|
125
|
+
* @returns Promise resolving to array of discovered services.
|
|
126
|
+
*/
|
|
127
|
+
export function discoverServices(deviceId: string): Promise<GATTService[]> {
|
|
128
|
+
return MunimBluetooth.discoverServices(deviceId)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Read a characteristic value from a connected device.
|
|
133
|
+
*
|
|
134
|
+
* @param deviceId - The unique identifier of the connected device.
|
|
135
|
+
* @param serviceUUID - The UUID of the service containing the characteristic.
|
|
136
|
+
* @param characteristicUUID - The UUID of the characteristic to read.
|
|
137
|
+
* @returns Promise resolving to the characteristic value.
|
|
138
|
+
*/
|
|
139
|
+
export function readCharacteristic(
|
|
140
|
+
deviceId: string,
|
|
141
|
+
serviceUUID: string,
|
|
142
|
+
characteristicUUID: string
|
|
143
|
+
): Promise<CharacteristicValue> {
|
|
144
|
+
return MunimBluetooth.readCharacteristic(
|
|
145
|
+
deviceId,
|
|
146
|
+
serviceUUID,
|
|
147
|
+
characteristicUUID
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Write a value to a characteristic on a connected device.
|
|
153
|
+
*
|
|
154
|
+
* @param deviceId - The unique identifier of the connected device.
|
|
155
|
+
* @param serviceUUID - The UUID of the service containing the characteristic.
|
|
156
|
+
* @param characteristicUUID - The UUID of the characteristic to write.
|
|
157
|
+
* @param value - The value to write (hex string).
|
|
158
|
+
* @param writeType - Optional write type: 'write' or 'writeWithoutResponse'. Defaults to 'write'.
|
|
159
|
+
* @returns Promise resolving when write is complete.
|
|
160
|
+
*/
|
|
161
|
+
export function writeCharacteristic(
|
|
162
|
+
deviceId: string,
|
|
163
|
+
serviceUUID: string,
|
|
164
|
+
characteristicUUID: string,
|
|
165
|
+
value: string,
|
|
166
|
+
writeType?: 'write' | 'writeWithoutResponse'
|
|
167
|
+
): Promise<void> {
|
|
168
|
+
return MunimBluetooth.writeCharacteristic(
|
|
169
|
+
deviceId,
|
|
170
|
+
serviceUUID,
|
|
171
|
+
characteristicUUID,
|
|
172
|
+
value,
|
|
173
|
+
writeType
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Subscribe to notifications/indications from a characteristic.
|
|
179
|
+
*
|
|
180
|
+
* @param deviceId - The unique identifier of the connected device.
|
|
181
|
+
* @param serviceUUID - The UUID of the service containing the characteristic.
|
|
182
|
+
* @param characteristicUUID - The UUID of the characteristic to subscribe to.
|
|
183
|
+
*/
|
|
184
|
+
export function subscribeToCharacteristic(
|
|
185
|
+
deviceId: string,
|
|
186
|
+
serviceUUID: string,
|
|
187
|
+
characteristicUUID: string
|
|
188
|
+
): void {
|
|
189
|
+
return MunimBluetooth.subscribeToCharacteristic(
|
|
190
|
+
deviceId,
|
|
191
|
+
serviceUUID,
|
|
192
|
+
characteristicUUID
|
|
193
|
+
)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Unsubscribe from notifications/indications from a characteristic.
|
|
198
|
+
*
|
|
199
|
+
* @param deviceId - The unique identifier of the connected device.
|
|
200
|
+
* @param serviceUUID - The UUID of the service containing the characteristic.
|
|
201
|
+
* @param characteristicUUID - The UUID of the characteristic to unsubscribe from.
|
|
202
|
+
*/
|
|
203
|
+
export function unsubscribeFromCharacteristic(
|
|
204
|
+
deviceId: string,
|
|
205
|
+
serviceUUID: string,
|
|
206
|
+
characteristicUUID: string
|
|
207
|
+
): void {
|
|
208
|
+
return MunimBluetooth.unsubscribeFromCharacteristic(
|
|
209
|
+
deviceId,
|
|
210
|
+
serviceUUID,
|
|
211
|
+
characteristicUUID
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Get list of currently connected devices.
|
|
217
|
+
*
|
|
218
|
+
* @returns Promise resolving to array of connected device IDs.
|
|
219
|
+
*/
|
|
220
|
+
export function getConnectedDevices(): Promise<string[]> {
|
|
221
|
+
return MunimBluetooth.getConnectedDevices()
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Read RSSI (signal strength) for a connected device.
|
|
226
|
+
*
|
|
227
|
+
* @param deviceId - The unique identifier of the connected device.
|
|
228
|
+
* @returns Promise resolving to RSSI value in dBm.
|
|
229
|
+
*/
|
|
230
|
+
export function readRSSI(deviceId: string): Promise<number> {
|
|
231
|
+
return MunimBluetooth.readRSSI(deviceId)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// ========== Event Management ==========
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Add an event listener.
|
|
238
|
+
*
|
|
239
|
+
* @param eventName - The name of the event to listen for.
|
|
240
|
+
*/
|
|
241
|
+
export function addListener(eventName: string): void {
|
|
242
|
+
return MunimBluetooth.addListener(eventName)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Remove event listeners.
|
|
247
|
+
*
|
|
248
|
+
* @param count - Number of listeners to remove.
|
|
249
|
+
*/
|
|
250
|
+
export function removeListeners(count: number): void {
|
|
251
|
+
return MunimBluetooth.removeListeners(count)
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// ========== Type Exports ==========
|
|
255
|
+
|
|
256
|
+
export type {
|
|
257
|
+
AdvertisingDataTypes,
|
|
258
|
+
BLEDevice,
|
|
259
|
+
ScanOptions,
|
|
260
|
+
GATTService,
|
|
261
|
+
CharacteristicValue,
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Default export for convenience
|
|
265
|
+
export default {
|
|
266
|
+
// Peripheral
|
|
267
|
+
startAdvertising,
|
|
268
|
+
stopAdvertising,
|
|
269
|
+
updateAdvertisingData,
|
|
270
|
+
getAdvertisingData,
|
|
271
|
+
setServices,
|
|
272
|
+
// Central
|
|
273
|
+
isBluetoothEnabled,
|
|
274
|
+
requestBluetoothPermission,
|
|
275
|
+
startScan,
|
|
276
|
+
stopScan,
|
|
277
|
+
connect,
|
|
278
|
+
disconnect,
|
|
279
|
+
discoverServices,
|
|
280
|
+
readCharacteristic,
|
|
281
|
+
writeCharacteristic,
|
|
282
|
+
subscribeToCharacteristic,
|
|
283
|
+
unsubscribeFromCharacteristic,
|
|
284
|
+
getConnectedDevices,
|
|
285
|
+
readRSSI,
|
|
286
|
+
// Events
|
|
287
|
+
addListener,
|
|
288
|
+
removeListeners,
|
|
289
|
+
}
|