munim-bluetooth 0.3.12 → 0.3.14
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.
|
@@ -82,9 +82,9 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
func getAdvertisingData() throws -> Promise<AdvertisingDataTypes> {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
let promise = Promise<AdvertisingDataTypes>()
|
|
86
|
+
promise.resolve(withResult: self.currentAdvertisingData ?? AdvertisingDataTypes())
|
|
87
|
+
return promise
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
func stopAdvertising() throws {
|
|
@@ -154,17 +154,17 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
154
154
|
// MARK: - Central/Manager Features
|
|
155
155
|
|
|
156
156
|
func isBluetoothEnabled() throws -> Promise<Bool> {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
157
|
+
let promise = Promise<Bool>()
|
|
158
|
+
let isEnabled = self.centralManager?.state == .poweredOn
|
|
159
|
+
promise.resolve(withResult: isEnabled ?? false)
|
|
160
|
+
return promise
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
func requestBluetoothPermission() throws -> Promise<Bool> {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
164
|
+
let promise = Promise<Bool>()
|
|
165
|
+
// In iOS, permissions are handled by CBPeripheralManager/CBCentralManager
|
|
166
|
+
promise.resolve(withResult: true)
|
|
167
|
+
return promise
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
func startScan(options: ScanOptions?) throws {
|
|
@@ -190,16 +190,16 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
func connect(deviceId: String) throws -> Promise<Void> {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
self.centralManager?.connect(peripheral, options: nil)
|
|
200
|
-
self.connectedPeripherals[deviceId] = peripheral
|
|
201
|
-
resolver.resolve(())
|
|
193
|
+
let promise = Promise<Void>()
|
|
194
|
+
guard let peripheral = self.discoveredPeripherals[deviceId] else {
|
|
195
|
+
promise.reject(withError: NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Device not found"]))
|
|
196
|
+
return promise
|
|
202
197
|
}
|
|
198
|
+
|
|
199
|
+
self.centralManager?.connect(peripheral, options: nil)
|
|
200
|
+
self.connectedPeripherals[deviceId] = peripheral
|
|
201
|
+
promise.resolve(withResult: ())
|
|
202
|
+
return promise
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
func disconnect(deviceId: String) throws {
|
|
@@ -209,27 +209,27 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
func discoverServices(deviceId: String) throws -> Promise<[GATTService]> {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
peripheral.discoverServices(nil)
|
|
219
|
-
resolver.resolve([])
|
|
212
|
+
let promise = Promise<[GATTService]>()
|
|
213
|
+
guard let peripheral = self.connectedPeripherals[deviceId] else {
|
|
214
|
+
promise.reject(withError: NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Device not connected"]))
|
|
215
|
+
return promise
|
|
220
216
|
}
|
|
217
|
+
|
|
218
|
+
peripheral.discoverServices(nil)
|
|
219
|
+
promise.resolve(withResult: [])
|
|
220
|
+
return promise
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
func readCharacteristic(deviceId: String, serviceUUID: String, characteristicUUID: String) throws -> Promise<CharacteristicValue> {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
224
|
+
let promise = Promise<CharacteristicValue>()
|
|
225
|
+
promise.reject(withError: NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Not implemented"]))
|
|
226
|
+
return promise
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
func writeCharacteristic(deviceId: String, serviceUUID: String, characteristicUUID: String, value: String, writeType: WriteType?) throws -> Promise<Void> {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
230
|
+
let promise = Promise<Void>()
|
|
231
|
+
promise.reject(withError: NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Not implemented"]))
|
|
232
|
+
return promise
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
func subscribeToCharacteristic(deviceId: String, serviceUUID: String, characteristicUUID: String) throws {
|
|
@@ -241,21 +241,21 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
func getConnectedDevices() throws -> Promise<[String]> {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
244
|
+
let promise = Promise<[String]>()
|
|
245
|
+
promise.resolve(withResult: Array(self.connectedPeripherals.keys))
|
|
246
|
+
return promise
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
func readRSSI(deviceId: String) throws -> Promise<Double> {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
peripheral.readRSSI()
|
|
257
|
-
resolver.resolve(0)
|
|
250
|
+
let promise = Promise<Double>()
|
|
251
|
+
guard let peripheral = self.connectedPeripherals[deviceId] else {
|
|
252
|
+
promise.reject(withError: NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Device not connected"]))
|
|
253
|
+
return promise
|
|
258
254
|
}
|
|
255
|
+
|
|
256
|
+
peripheral.readRSSI()
|
|
257
|
+
promise.resolve(withResult: 0)
|
|
258
|
+
return promise
|
|
259
259
|
}
|
|
260
260
|
|
|
261
261
|
func addListener(eventName: String) throws {
|
|
@@ -44,9 +44,11 @@ public extension HybridMunimBluetoothSpec_protocol {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/// See ``HybridMunimBluetoothSpec``
|
|
47
|
-
open class HybridMunimBluetoothSpec_base {
|
|
47
|
+
open class HybridMunimBluetoothSpec_base: NSObject {
|
|
48
48
|
private weak var cxxWrapper: HybridMunimBluetoothSpec_cxx? = nil
|
|
49
|
-
public init() {
|
|
49
|
+
public override init() {
|
|
50
|
+
super.init()
|
|
51
|
+
}
|
|
50
52
|
public func getCxxWrapper() -> HybridMunimBluetoothSpec_cxx {
|
|
51
53
|
#if DEBUG
|
|
52
54
|
guard self is any HybridMunimBluetoothSpec else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "munim-bluetooth",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.14",
|
|
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",
|