munim-bluetooth 0.1.0 → 0.2.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.
- package/README.md +769 -15
- 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,5 +1,268 @@
|
|
|
1
1
|
import { type HybridObject } from 'react-native-nitro-modules'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
// BLE Advertising Data Types - Only Platform-Supported Types
|
|
4
|
+
export interface AdvertisingDataTypes {
|
|
5
|
+
// 0x01 - Flags (partial support)
|
|
6
|
+
flags?: number
|
|
7
|
+
|
|
8
|
+
// 0x02-0x07 - Service UUIDs (fully supported)
|
|
9
|
+
incompleteServiceUUIDs16?: string[]
|
|
10
|
+
completeServiceUUIDs16?: string[]
|
|
11
|
+
incompleteServiceUUIDs32?: string[]
|
|
12
|
+
completeServiceUUIDs32?: string[]
|
|
13
|
+
incompleteServiceUUIDs128?: string[]
|
|
14
|
+
completeServiceUUIDs128?: string[]
|
|
15
|
+
|
|
16
|
+
// 0x08-0x09 - Local Name (fully supported)
|
|
17
|
+
shortenedLocalName?: string
|
|
18
|
+
completeLocalName?: string
|
|
19
|
+
|
|
20
|
+
// 0x0A - Tx Power Level (fully supported)
|
|
21
|
+
txPowerLevel?: number
|
|
22
|
+
|
|
23
|
+
// 0x14-0x15 - Service Solicitation (fully supported)
|
|
24
|
+
serviceSolicitationUUIDs16?: string[]
|
|
25
|
+
serviceSolicitationUUIDs128?: string[]
|
|
26
|
+
|
|
27
|
+
// 0x16, 0x20, 0x21 - Service Data (fully supported)
|
|
28
|
+
serviceData16?: Array<{
|
|
29
|
+
uuid: string
|
|
30
|
+
data: string
|
|
31
|
+
}>
|
|
32
|
+
serviceData32?: Array<{
|
|
33
|
+
uuid: string
|
|
34
|
+
data: string
|
|
35
|
+
}>
|
|
36
|
+
serviceData128?: Array<{
|
|
37
|
+
uuid: string
|
|
38
|
+
data: string
|
|
39
|
+
}>
|
|
40
|
+
|
|
41
|
+
// 0x19 - Appearance (partial support)
|
|
42
|
+
appearance?: number
|
|
43
|
+
|
|
44
|
+
// 0x1F - Service Solicitation (32-bit) (fully supported)
|
|
45
|
+
serviceSolicitationUUIDs32?: string[]
|
|
46
|
+
|
|
47
|
+
// 0xFF - Manufacturer Specific Data (fully supported)
|
|
48
|
+
manufacturerData?: string
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// BLE Device information
|
|
52
|
+
export interface BLEDevice {
|
|
53
|
+
id: string
|
|
54
|
+
name?: string
|
|
55
|
+
rssi?: number
|
|
56
|
+
advertisingData?: AdvertisingDataTypes
|
|
57
|
+
serviceUUIDs?: string[]
|
|
58
|
+
isConnectable?: boolean
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Scan options
|
|
62
|
+
export interface ScanOptions {
|
|
63
|
+
serviceUUIDs?: string[]
|
|
64
|
+
allowDuplicates?: boolean
|
|
65
|
+
scanMode?: 'lowPower' | 'balanced' | 'lowLatency'
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// GATT Service
|
|
69
|
+
export interface GATTService {
|
|
70
|
+
uuid: string
|
|
71
|
+
characteristics: Array<{
|
|
72
|
+
uuid: string
|
|
73
|
+
properties: string[]
|
|
74
|
+
value?: string
|
|
75
|
+
}>
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Characteristic value
|
|
79
|
+
export interface CharacteristicValue {
|
|
80
|
+
value: string
|
|
81
|
+
serviceUUID: string
|
|
82
|
+
characteristicUUID: string
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface MunimBluetooth
|
|
86
|
+
extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
|
|
87
|
+
// ========== Peripheral Features ==========
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Start advertising as a Bluetooth peripheral with supported advertising data.
|
|
91
|
+
*
|
|
92
|
+
* @param options - An object with serviceUUIDs (string[]) and supported advertising data types.
|
|
93
|
+
* This must be a plain JS object (no Maps/Sets/functions).
|
|
94
|
+
*/
|
|
95
|
+
startAdvertising(options: {
|
|
96
|
+
serviceUUIDs: string[]
|
|
97
|
+
localName?: string
|
|
98
|
+
manufacturerData?: string
|
|
99
|
+
advertisingData?: AdvertisingDataTypes
|
|
100
|
+
}): void
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Update advertising data while advertising is active.
|
|
104
|
+
*
|
|
105
|
+
* @param advertisingData - The new advertising data to use.
|
|
106
|
+
*/
|
|
107
|
+
updateAdvertisingData(advertisingData: AdvertisingDataTypes): void
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Get current advertising data.
|
|
111
|
+
*
|
|
112
|
+
* @returns Promise resolving to current advertising data.
|
|
113
|
+
*/
|
|
114
|
+
getAdvertisingData(): Promise<AdvertisingDataTypes>
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Stop BLE advertising.
|
|
118
|
+
*/
|
|
119
|
+
stopAdvertising(): void
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Set GATT services and characteristics for the Bluetooth peripheral.
|
|
123
|
+
*
|
|
124
|
+
* @param services - An array of service objects, each with a uuid and an array of characteristics.
|
|
125
|
+
* This must be serializable to a plain JS array (no Maps/Sets/functions).
|
|
126
|
+
*/
|
|
127
|
+
setServices(services: GATTService[]): void
|
|
128
|
+
|
|
129
|
+
// ========== Central/Manager Features ==========
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Check if Bluetooth is enabled on the device.
|
|
133
|
+
*
|
|
134
|
+
* @returns Promise resolving to true if Bluetooth is enabled, false otherwise.
|
|
135
|
+
*/
|
|
136
|
+
isBluetoothEnabled(): Promise<boolean>
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Request Bluetooth permissions (Android) or check authorization status (iOS).
|
|
140
|
+
*
|
|
141
|
+
* @returns Promise resolving to true if permissions are granted, false otherwise.
|
|
142
|
+
*/
|
|
143
|
+
requestBluetoothPermission(): Promise<boolean>
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Start scanning for BLE devices.
|
|
147
|
+
*
|
|
148
|
+
* @param options - Optional scan configuration including service UUIDs to filter by.
|
|
149
|
+
*/
|
|
150
|
+
startScan(options?: ScanOptions): void
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Stop scanning for BLE devices.
|
|
154
|
+
*/
|
|
155
|
+
stopScan(): void
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Connect to a BLE device.
|
|
159
|
+
*
|
|
160
|
+
* @param deviceId - The unique identifier of the device to connect to.
|
|
161
|
+
* @returns Promise resolving when connection is established or rejected.
|
|
162
|
+
*/
|
|
163
|
+
connect(deviceId: string): Promise<void>
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Disconnect from a BLE device.
|
|
167
|
+
*
|
|
168
|
+
* @param deviceId - The unique identifier of the device to disconnect from.
|
|
169
|
+
*/
|
|
170
|
+
disconnect(deviceId: string): void
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Discover GATT services for a connected device.
|
|
174
|
+
*
|
|
175
|
+
* @param deviceId - The unique identifier of the connected device.
|
|
176
|
+
* @returns Promise resolving to array of discovered services.
|
|
177
|
+
*/
|
|
178
|
+
discoverServices(deviceId: string): Promise<GATTService[]>
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Read a characteristic value from a connected device.
|
|
182
|
+
*
|
|
183
|
+
* @param deviceId - The unique identifier of the connected device.
|
|
184
|
+
* @param serviceUUID - The UUID of the service containing the characteristic.
|
|
185
|
+
* @param characteristicUUID - The UUID of the characteristic to read.
|
|
186
|
+
* @returns Promise resolving to the characteristic value.
|
|
187
|
+
*/
|
|
188
|
+
readCharacteristic(
|
|
189
|
+
deviceId: string,
|
|
190
|
+
serviceUUID: string,
|
|
191
|
+
characteristicUUID: string
|
|
192
|
+
): Promise<CharacteristicValue>
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Write a value to a characteristic on a connected device.
|
|
196
|
+
*
|
|
197
|
+
* @param deviceId - The unique identifier of the connected device.
|
|
198
|
+
* @param serviceUUID - The UUID of the service containing the characteristic.
|
|
199
|
+
* @param characteristicUUID - The UUID of the characteristic to write.
|
|
200
|
+
* @param value - The value to write (hex string).
|
|
201
|
+
* @param writeType - Optional write type: 'write' or 'writeWithoutResponse'. Defaults to 'write'.
|
|
202
|
+
* @returns Promise resolving when write is complete.
|
|
203
|
+
*/
|
|
204
|
+
writeCharacteristic(
|
|
205
|
+
deviceId: string,
|
|
206
|
+
serviceUUID: string,
|
|
207
|
+
characteristicUUID: string,
|
|
208
|
+
value: string,
|
|
209
|
+
writeType?: 'write' | 'writeWithoutResponse'
|
|
210
|
+
): Promise<void>
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Subscribe to notifications/indications from a characteristic.
|
|
214
|
+
*
|
|
215
|
+
* @param deviceId - The unique identifier of the connected device.
|
|
216
|
+
* @param serviceUUID - The UUID of the service containing the characteristic.
|
|
217
|
+
* @param characteristicUUID - The UUID of the characteristic to subscribe to.
|
|
218
|
+
*/
|
|
219
|
+
subscribeToCharacteristic(
|
|
220
|
+
deviceId: string,
|
|
221
|
+
serviceUUID: string,
|
|
222
|
+
characteristicUUID: string
|
|
223
|
+
): void
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Unsubscribe from notifications/indications from a characteristic.
|
|
227
|
+
*
|
|
228
|
+
* @param deviceId - The unique identifier of the connected device.
|
|
229
|
+
* @param serviceUUID - The UUID of the service containing the characteristic.
|
|
230
|
+
* @param characteristicUUID - The UUID of the characteristic to unsubscribe from.
|
|
231
|
+
*/
|
|
232
|
+
unsubscribeFromCharacteristic(
|
|
233
|
+
deviceId: string,
|
|
234
|
+
serviceUUID: string,
|
|
235
|
+
characteristicUUID: string
|
|
236
|
+
): void
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Get list of currently connected devices.
|
|
240
|
+
*
|
|
241
|
+
* @returns Promise resolving to array of connected device IDs.
|
|
242
|
+
*/
|
|
243
|
+
getConnectedDevices(): Promise<string[]>
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Read RSSI (signal strength) for a connected device.
|
|
247
|
+
*
|
|
248
|
+
* @param deviceId - The unique identifier of the connected device.
|
|
249
|
+
* @returns Promise resolving to RSSI value in dBm.
|
|
250
|
+
*/
|
|
251
|
+
readRSSI(deviceId: string): Promise<number>
|
|
252
|
+
|
|
253
|
+
// ========== Event Management ==========
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Add an event listener.
|
|
257
|
+
*
|
|
258
|
+
* @param eventName - The name of the event to listen for.
|
|
259
|
+
*/
|
|
260
|
+
addListener(eventName: string): void
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Remove event listeners.
|
|
264
|
+
*
|
|
265
|
+
* @param count - Number of listeners to remove.
|
|
266
|
+
*/
|
|
267
|
+
removeListeners(count: number): void
|
|
268
|
+
}
|