munim-bluetooth 0.3.10 → 0.3.11
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/ios/HybridMunimBluetooth.swift +21 -21
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@ import CoreBluetooth
|
|
|
10
10
|
import NitroModules
|
|
11
11
|
import React
|
|
12
12
|
|
|
13
|
-
class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
13
|
+
class HybridMunimBluetooth: NSObject, HybridMunimBluetoothSpec {
|
|
14
14
|
// Peripheral Manager
|
|
15
15
|
private var peripheralManager: CBPeripheralManager?
|
|
16
16
|
private var peripheralServices: [CBMutableService] = []
|
|
@@ -32,7 +32,7 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
32
32
|
|
|
33
33
|
// MARK: - Peripheral Features
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
func startAdvertising(options: AdvertisingOptions) throws {
|
|
36
36
|
guard let peripheralManager = peripheralManager,
|
|
37
37
|
peripheralManager.state == .poweredOn else {
|
|
38
38
|
throw NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Bluetooth is not powered on"])
|
|
@@ -66,7 +66,7 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
66
66
|
peripheralManager.startAdvertising(advertisingData as? [String: Any])
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
func updateAdvertisingData(advertisingData: AdvertisingDataTypes) throws {
|
|
70
70
|
guard let peripheralManager = peripheralManager,
|
|
71
71
|
peripheralManager.state == .poweredOn else {
|
|
72
72
|
throw NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Bluetooth is not powered on"])
|
|
@@ -81,18 +81,18 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
81
81
|
peripheralManager.startAdvertising(newAdvertisingData as? [String: Any])
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
func getAdvertisingData() throws -> Promise<AdvertisingDataTypes> {
|
|
85
85
|
return Promise { resolver in
|
|
86
86
|
resolver.resolve(self.currentAdvertisingData ?? AdvertisingDataTypes())
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
func stopAdvertising() throws {
|
|
91
91
|
peripheralManager?.stopAdvertising()
|
|
92
92
|
currentAdvertisingData = nil
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
func setServices(services: [GATTService]) throws {
|
|
96
96
|
peripheralServices.removeAll()
|
|
97
97
|
|
|
98
98
|
for service in services {
|
|
@@ -153,21 +153,21 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
153
153
|
|
|
154
154
|
// MARK: - Central/Manager Features
|
|
155
155
|
|
|
156
|
-
|
|
156
|
+
func isBluetoothEnabled() throws -> Promise<Bool> {
|
|
157
157
|
return Promise { resolver in
|
|
158
158
|
let isEnabled = self.centralManager?.state == .poweredOn
|
|
159
159
|
resolver.resolve(isEnabled ?? false)
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
|
|
163
|
+
func requestBluetoothPermission() throws -> Promise<Bool> {
|
|
164
164
|
return Promise { resolver in
|
|
165
165
|
// In iOS, permissions are handled by CBPeripheralManager/CBCentralManager
|
|
166
166
|
resolver.resolve(true)
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
|
|
170
|
+
func startScan(options: ScanOptions?) throws {
|
|
171
171
|
guard let centralManager = centralManager,
|
|
172
172
|
centralManager.state == .poweredOn else {
|
|
173
173
|
throw NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Bluetooth is not powered on"])
|
|
@@ -184,12 +184,12 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
184
184
|
centralManager.scanForPeripherals(withServices: nil, options: scanOptions as [String : Any])
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
|
|
187
|
+
func stopScan() throws {
|
|
188
188
|
centralManager?.stopScan()
|
|
189
189
|
isScanning = false
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
|
|
192
|
+
func connect(deviceId: String) throws -> Promise<Void> {
|
|
193
193
|
return Promise { resolver in
|
|
194
194
|
guard let peripheral = self.discoveredPeripherals[deviceId] else {
|
|
195
195
|
resolver.reject(NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Device not found"]))
|
|
@@ -202,13 +202,13 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
|
|
205
|
+
func disconnect(deviceId: String) throws {
|
|
206
206
|
guard let peripheral = connectedPeripherals[deviceId] else { return }
|
|
207
207
|
centralManager?.cancelPeripheralConnection(peripheral)
|
|
208
208
|
connectedPeripherals.removeValue(forKey: deviceId)
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
-
|
|
211
|
+
func discoverServices(deviceId: String) throws -> Promise<[GATTService]> {
|
|
212
212
|
return Promise { resolver in
|
|
213
213
|
guard let peripheral = self.connectedPeripherals[deviceId] else {
|
|
214
214
|
resolver.reject(NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Device not connected"]))
|
|
@@ -220,33 +220,33 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
-
|
|
223
|
+
func readCharacteristic(deviceId: String, serviceUUID: String, characteristicUUID: String) throws -> Promise<CharacteristicValue> {
|
|
224
224
|
return Promise { resolver in
|
|
225
225
|
resolver.reject(NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Not implemented"]))
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
|
|
229
|
+
func writeCharacteristic(deviceId: String, serviceUUID: String, characteristicUUID: String, value: String, writeType: WriteType?) throws -> Promise<Void> {
|
|
230
230
|
return Promise { resolver in
|
|
231
231
|
resolver.reject(NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Not implemented"]))
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
-
|
|
235
|
+
func subscribeToCharacteristic(deviceId: String, serviceUUID: String, characteristicUUID: String) throws {
|
|
236
236
|
// Not implemented
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
-
|
|
239
|
+
func unsubscribeFromCharacteristic(deviceId: String, serviceUUID: String, characteristicUUID: String) throws {
|
|
240
240
|
// Not implemented
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
-
|
|
243
|
+
func getConnectedDevices() throws -> Promise<[String]> {
|
|
244
244
|
return Promise { resolver in
|
|
245
245
|
resolver.resolve(Array(self.connectedPeripherals.keys))
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
-
|
|
249
|
+
func readRSSI(deviceId: String) throws -> Promise<Double> {
|
|
250
250
|
return Promise { resolver in
|
|
251
251
|
guard let peripheral = self.connectedPeripherals[deviceId] else {
|
|
252
252
|
resolver.reject(NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Device not connected"]))
|
|
@@ -258,11 +258,11 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
-
|
|
261
|
+
func addListener(eventName: String) throws {
|
|
262
262
|
// Event management
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
-
|
|
265
|
+
func removeListeners(count: Double) throws {
|
|
266
266
|
// Event management
|
|
267
267
|
}
|
|
268
268
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "munim-bluetooth",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.11",
|
|
4
4
|
"description": "A comprehensive React Native library for all your Bluetooth Low Energy (BLE) needs, supporting both peripheral and central roles with Expo support",
|
|
5
5
|
"main": "./lib/commonjs/index.js",
|
|
6
6
|
"module": "./lib/module/index.js",
|