react-native-bluebreeze 0.0.8 → 0.0.9
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/BlueBreezeImpl.swift +177 -122
- package/ios/Bluebreeze.h +3 -1
- package/ios/Bluebreeze.mm +79 -100
- package/package.json +1 -1
package/ios/BlueBreezeImpl.swift
CHANGED
|
@@ -15,7 +15,168 @@ struct BlueBreezeError : Error {
|
|
|
15
15
|
|
|
16
16
|
@objc public class BlueBreezeImpl: NSObject {
|
|
17
17
|
var disposeBag: Set<AnyCancellable> = []
|
|
18
|
+
var disposeBagDevices: [UUID: Set<AnyCancellable>] = [:]
|
|
19
|
+
var disposeBagServices: [UUID: [BBUUID: [BBUUID: Set<AnyCancellable>]]] = [:]
|
|
20
|
+
|
|
18
21
|
let manager = BBManager()
|
|
22
|
+
|
|
23
|
+
var stateObserve: ((String) -> Void)?
|
|
24
|
+
var authorizationObserve: ((String) -> Void)?
|
|
25
|
+
var scanResultsObserve: (([String: Any]) -> Void)?
|
|
26
|
+
var scanEnabledObserve: ((Bool) -> Void)?
|
|
27
|
+
var devicesObserve: (([[String: Any]]) -> Void)?
|
|
28
|
+
var deviceConnectionStatusObserve: ((String, String) -> Void)?
|
|
29
|
+
var deviceServicesObserve: ((String, [[String: Any]]) -> Void)?
|
|
30
|
+
var deviceMTUObserve: ((String, Int) -> Void)?
|
|
31
|
+
var deviceCharacteristicDataObserve: ((String, String, String, Array<UInt8>) -> Void)?
|
|
32
|
+
var deviceCharacteristicNotifyEnabledObserve: ((String, String, String, Bool) -> Void)?
|
|
33
|
+
|
|
34
|
+
@objc public func subscribe(
|
|
35
|
+
stateObserve: (@escaping (String) -> Void),
|
|
36
|
+
authorizationObserve: (@escaping (String) -> Void),
|
|
37
|
+
scanEnabledObserve: (@escaping (Bool) -> Void),
|
|
38
|
+
scanResultsObserve: (@escaping ([String: Any]) -> Void),
|
|
39
|
+
devicesObserve: (@escaping ([[String: Any]]) -> Void),
|
|
40
|
+
deviceConnectionStatusObserve: (@escaping (String, String) -> Void),
|
|
41
|
+
deviceServicesObserve: (@escaping (String, [[String: Any]]) -> Void),
|
|
42
|
+
deviceMTUObserve: (@escaping (String, Int) -> Void),
|
|
43
|
+
deviceCharacteristicDataObserve: (@escaping (String, String, String, Array<UInt8>) -> Void),
|
|
44
|
+
deviceCharacteristicNotifyEnabledObserve: (@escaping (String, String, String, Bool) -> Void)
|
|
45
|
+
) {
|
|
46
|
+
self.stateObserve = stateObserve
|
|
47
|
+
self.authorizationObserve = authorizationObserve
|
|
48
|
+
self.scanEnabledObserve = scanEnabledObserve
|
|
49
|
+
self.scanResultsObserve = scanResultsObserve
|
|
50
|
+
self.devicesObserve = devicesObserve
|
|
51
|
+
self.deviceConnectionStatusObserve = deviceConnectionStatusObserve
|
|
52
|
+
self.deviceServicesObserve = deviceServicesObserve
|
|
53
|
+
self.deviceMTUObserve = deviceMTUObserve
|
|
54
|
+
self.deviceCharacteristicDataObserve = deviceCharacteristicDataObserve
|
|
55
|
+
self.deviceCharacteristicNotifyEnabledObserve = deviceCharacteristicNotifyEnabledObserve
|
|
56
|
+
|
|
57
|
+
manager.state
|
|
58
|
+
.receive(on: DispatchQueue.main)
|
|
59
|
+
.sink { self.stateObserve?($0.toJs) }
|
|
60
|
+
.store(in: &disposeBag)
|
|
61
|
+
|
|
62
|
+
manager.authorizationStatus
|
|
63
|
+
.receive(on: DispatchQueue.main)
|
|
64
|
+
.sink { self.authorizationObserve?($0.toJs) }
|
|
65
|
+
.store(in: &disposeBag)
|
|
66
|
+
|
|
67
|
+
manager.scanEnabled
|
|
68
|
+
.receive(on: DispatchQueue.main)
|
|
69
|
+
.sink { self.scanEnabledObserve?($0) }
|
|
70
|
+
.store(in: &disposeBag)
|
|
71
|
+
|
|
72
|
+
manager.scanResults
|
|
73
|
+
.receive(on: DispatchQueue.main)
|
|
74
|
+
.sink { self.scanResultsObserve?($0.toJs) }
|
|
75
|
+
.store(in: &disposeBag)
|
|
76
|
+
|
|
77
|
+
manager.devices
|
|
78
|
+
.receive(on: DispatchQueue.main)
|
|
79
|
+
.sink {
|
|
80
|
+
$0.forEach { (id, device) in
|
|
81
|
+
self.subscribeDevice(device)
|
|
82
|
+
}
|
|
83
|
+
self.devicesObserve?($0.values.map { $0.toJs })
|
|
84
|
+
}
|
|
85
|
+
.store(in: &disposeBag)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private func subscribeDevice(_ device: BBDevice) {
|
|
89
|
+
guard disposeBagDevices[device.id] == nil else {
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
disposeBagDevices[device.id] = []
|
|
94
|
+
|
|
95
|
+
device.connectionStatus
|
|
96
|
+
.receive(on: DispatchQueue.main)
|
|
97
|
+
.sink { self.deviceConnectionStatusObserve?(device.id.toJs, $0.toJs) }
|
|
98
|
+
.store(in: &disposeBagDevices[device.id]!)
|
|
99
|
+
|
|
100
|
+
device.services
|
|
101
|
+
.receive(on: DispatchQueue.main)
|
|
102
|
+
.sink {
|
|
103
|
+
self.subscribeServices(device, $0)
|
|
104
|
+
self.deviceServicesObserve?(device.id.toJs, $0.toJs)
|
|
105
|
+
}
|
|
106
|
+
.store(in: &disposeBagDevices[device.id]!)
|
|
107
|
+
|
|
108
|
+
device.mtu
|
|
109
|
+
.receive(on: DispatchQueue.main)
|
|
110
|
+
.sink { self.deviceMTUObserve?(device.id.toJs, $0) }
|
|
111
|
+
.store(in: &disposeBagDevices[device.id]!)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private func subscribeServices(_ device: BBDevice, _ services: [BBUUID: [BBCharacteristic]]) {
|
|
115
|
+
// Clean up device data by removing missing services
|
|
116
|
+
disposeBagServices[device.id] =
|
|
117
|
+
disposeBagServices[device.id]?.filter({ key, value in
|
|
118
|
+
services[key] != nil
|
|
119
|
+
}) ?? [:]
|
|
120
|
+
|
|
121
|
+
// Init all existing services
|
|
122
|
+
services.forEach { serviceId, value in
|
|
123
|
+
// Clean up service data by removing missing characteristics
|
|
124
|
+
disposeBagServices[device.id]![serviceId] =
|
|
125
|
+
disposeBagServices[device.id]![serviceId]?.filter({ key, _ in
|
|
126
|
+
value.first(where: { $0.id == key }) != nil
|
|
127
|
+
}) ?? [:]
|
|
128
|
+
|
|
129
|
+
// Init all existing characteristics
|
|
130
|
+
value.forEach { characteristic in
|
|
131
|
+
guard disposeBagServices[device.id]![serviceId]![characteristic.id] == nil else {
|
|
132
|
+
return
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
disposeBagServices[device.id]![serviceId]![characteristic.id] = []
|
|
136
|
+
|
|
137
|
+
characteristic.isNotifying
|
|
138
|
+
.receive(on: DispatchQueue.main)
|
|
139
|
+
.sink {
|
|
140
|
+
self.deviceCharacteristicNotifyEnabledObserve?(
|
|
141
|
+
device.id.toJs,
|
|
142
|
+
serviceId.toJs,
|
|
143
|
+
characteristic.id.toJs,
|
|
144
|
+
$0
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
.store(in: &disposeBagServices[device.id]![serviceId]![characteristic.id]!)
|
|
148
|
+
|
|
149
|
+
characteristic.data
|
|
150
|
+
.receive(on: DispatchQueue.main)
|
|
151
|
+
.sink {
|
|
152
|
+
self.deviceCharacteristicDataObserve?(
|
|
153
|
+
device.id.toJs,
|
|
154
|
+
serviceId.toJs,
|
|
155
|
+
characteristic.id.toJs,
|
|
156
|
+
$0.toJs
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
.store(in: &disposeBagServices[device.id]![serviceId]![characteristic.id]!)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
@objc public func unsubscribe() {
|
|
165
|
+
disposeBagServices = [:]
|
|
166
|
+
disposeBagDevices = [:]
|
|
167
|
+
disposeBag = []
|
|
168
|
+
|
|
169
|
+
self.stateObserve = nil
|
|
170
|
+
self.authorizationObserve = nil
|
|
171
|
+
self.scanEnabledObserve = nil
|
|
172
|
+
self.scanResultsObserve = nil
|
|
173
|
+
self.devicesObserve = nil
|
|
174
|
+
self.deviceConnectionStatusObserve = nil
|
|
175
|
+
self.deviceServicesObserve = nil
|
|
176
|
+
self.deviceMTUObserve = nil
|
|
177
|
+
self.deviceCharacteristicDataObserve = nil
|
|
178
|
+
self.deviceCharacteristicNotifyEnabledObserve = nil
|
|
179
|
+
}
|
|
19
180
|
|
|
20
181
|
// MARK: - State
|
|
21
182
|
|
|
@@ -23,26 +184,12 @@ struct BlueBreezeError : Error {
|
|
|
23
184
|
return manager.state.value.toJs
|
|
24
185
|
}
|
|
25
186
|
|
|
26
|
-
@objc public func stateObserve(onChanged: @escaping (String) -> Void) {
|
|
27
|
-
manager.state
|
|
28
|
-
.receive(on: DispatchQueue.main)
|
|
29
|
-
.sink { onChanged($0.toJs) }
|
|
30
|
-
.store(in: &disposeBag)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
187
|
// MARK: - Authorization
|
|
34
188
|
|
|
35
189
|
@objc public func authorizationStatus() -> String {
|
|
36
190
|
return manager.authorizationStatus.value.toJs
|
|
37
191
|
}
|
|
38
192
|
|
|
39
|
-
@objc public func authorizationStatusObserve(onChanged: @escaping (String) -> Void) {
|
|
40
|
-
manager.authorizationStatus
|
|
41
|
-
.receive(on: DispatchQueue.main)
|
|
42
|
-
.sink { onChanged($0.toJs) }
|
|
43
|
-
.store(in: &disposeBag)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
193
|
@objc public func authorizationRequest() {
|
|
47
194
|
manager.authorizationRequest()
|
|
48
195
|
}
|
|
@@ -56,20 +203,6 @@ struct BlueBreezeError : Error {
|
|
|
56
203
|
@objc public func scanEnabled() -> Bool {
|
|
57
204
|
return manager.scanEnabled.value
|
|
58
205
|
}
|
|
59
|
-
|
|
60
|
-
@objc public func scanResultsObserve(onChanged: @escaping ([String: Any]) -> Void) {
|
|
61
|
-
return manager.scanResults
|
|
62
|
-
.receive(on: DispatchQueue.main)
|
|
63
|
-
.sink { onChanged($0.toJs) }
|
|
64
|
-
.store(in: &disposeBag)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
@objc public func scanEnabledObserve(onChanged: @escaping (Bool) -> Void) {
|
|
68
|
-
return manager.scanEnabled
|
|
69
|
-
.receive(on: DispatchQueue.main)
|
|
70
|
-
.sink { onChanged($0) }
|
|
71
|
-
.store(in: &disposeBag)
|
|
72
|
-
}
|
|
73
206
|
|
|
74
207
|
@objc public func scanStart(_ ids: [String]?) {
|
|
75
208
|
let serviceUuids = ids?.map { BBUUID(string: $0) }
|
|
@@ -86,13 +219,6 @@ struct BlueBreezeError : Error {
|
|
|
86
219
|
return manager.devices.value.values.map { $0.toJs }
|
|
87
220
|
}
|
|
88
221
|
|
|
89
|
-
@objc public func devicesObserve(onChanged: @escaping ([[String: Any]]) -> Void) {
|
|
90
|
-
return manager.devices
|
|
91
|
-
.receive(on: DispatchQueue.main)
|
|
92
|
-
.sink { onChanged($0.values.map { $0.toJs }) }
|
|
93
|
-
.store(in: &disposeBag)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
222
|
// MARK: - Device services
|
|
97
223
|
|
|
98
224
|
@objc public func deviceServices(id: String) -> [[String: Any]] {
|
|
@@ -107,21 +233,6 @@ struct BlueBreezeError : Error {
|
|
|
107
233
|
return device.services.value.toJs
|
|
108
234
|
}
|
|
109
235
|
|
|
110
|
-
@objc public func deviceServicesObserve(id: String, onChanged: @escaping ([[String: Any]]) -> Void) {
|
|
111
|
-
guard let uuid = UUID(uuidString: id) else {
|
|
112
|
-
return
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
guard let device = manager.devices.value[uuid] else {
|
|
116
|
-
return
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return device.services
|
|
120
|
-
.receive(on: DispatchQueue.main)
|
|
121
|
-
.sink { onChanged($0.toJs) }
|
|
122
|
-
.store(in: &disposeBag)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
236
|
// MARK: - Device connection status
|
|
126
237
|
|
|
127
238
|
@objc public func deviceConnectionStatus(id: String) -> String {
|
|
@@ -136,21 +247,6 @@ struct BlueBreezeError : Error {
|
|
|
136
247
|
return device.connectionStatus.value.toJs
|
|
137
248
|
}
|
|
138
249
|
|
|
139
|
-
@objc public func deviceConnectionStatusObserve(id: String, onChanged: @escaping (String) -> Void) {
|
|
140
|
-
guard let uuid = UUID(uuidString: id) else {
|
|
141
|
-
return
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
guard let device = manager.devices.value[uuid] else {
|
|
145
|
-
return
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return device.connectionStatus
|
|
149
|
-
.receive(on: DispatchQueue.main)
|
|
150
|
-
.sink { onChanged($0.toJs) }
|
|
151
|
-
.store(in: &disposeBag)
|
|
152
|
-
}
|
|
153
|
-
|
|
154
250
|
// MARK: - Device MTU
|
|
155
251
|
|
|
156
252
|
@objc public func deviceMTU(id: String) -> Int {
|
|
@@ -165,21 +261,6 @@ struct BlueBreezeError : Error {
|
|
|
165
261
|
return device.mtu.value
|
|
166
262
|
}
|
|
167
263
|
|
|
168
|
-
@objc public func deviceMTUObserve(id: String, onChanged: @escaping (Int) -> Void) {
|
|
169
|
-
guard let uuid = UUID(uuidString: id) else {
|
|
170
|
-
return
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
guard let device = manager.devices.value[uuid] else {
|
|
174
|
-
return
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return device.mtu
|
|
178
|
-
.receive(on: DispatchQueue.main)
|
|
179
|
-
.sink { onChanged($0) }
|
|
180
|
-
.store(in: &disposeBag)
|
|
181
|
-
}
|
|
182
|
-
|
|
183
264
|
// MARK: - Device operations
|
|
184
265
|
|
|
185
266
|
@objc public func deviceConnect(id: String) async throws {
|
|
@@ -245,26 +326,7 @@ struct BlueBreezeError : Error {
|
|
|
245
326
|
return []
|
|
246
327
|
}
|
|
247
328
|
|
|
248
|
-
return characteristic.data.value.
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
@objc public func deviceCharacteristicDataObserve(id: String, serviceId: String, characteristicId: String, onChanged: @escaping (Array<UInt8>) -> Void) {
|
|
252
|
-
guard let uuid = UUID(uuidString: id) else {
|
|
253
|
-
return
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
guard let device = manager.devices.value[uuid] else {
|
|
257
|
-
return
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
guard let characteristic = device.getCharacteristic(serviceId: serviceId, characteristicId: characteristicId) else {
|
|
261
|
-
return
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
return characteristic.data
|
|
265
|
-
.receive(on: DispatchQueue.main)
|
|
266
|
-
.sink { onChanged($0.export) }
|
|
267
|
-
.store(in: &disposeBag)
|
|
329
|
+
return characteristic.data.value.toJs
|
|
268
330
|
}
|
|
269
331
|
|
|
270
332
|
// MARK: - Device notify enabled
|
|
@@ -285,25 +347,6 @@ struct BlueBreezeError : Error {
|
|
|
285
347
|
return characteristic.isNotifying.value
|
|
286
348
|
}
|
|
287
349
|
|
|
288
|
-
@objc public func deviceCharacteristicNotifyEnabledObserve(id: String, serviceId: String, characteristicId: String, onChanged: @escaping (Bool) -> Void) {
|
|
289
|
-
guard let uuid = UUID(uuidString: id) else {
|
|
290
|
-
return
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
guard let device = manager.devices.value[uuid] else {
|
|
294
|
-
return
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
guard let characteristic = device.getCharacteristic(serviceId: serviceId, characteristicId: characteristicId) else {
|
|
298
|
-
return
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
return characteristic.isNotifying
|
|
302
|
-
.receive(on: DispatchQueue.main)
|
|
303
|
-
.sink { onChanged($0) }
|
|
304
|
-
.store(in: &disposeBag)
|
|
305
|
-
}
|
|
306
|
-
|
|
307
350
|
// MARK: - Device operations
|
|
308
351
|
|
|
309
352
|
@objc public func deviceCharacteristicRead(id: String, serviceId: String, characteristicId: String) async throws -> Array<UInt8> {
|
|
@@ -320,7 +363,7 @@ struct BlueBreezeError : Error {
|
|
|
320
363
|
}
|
|
321
364
|
|
|
322
365
|
let data = try await characteristic.read()
|
|
323
|
-
return data?.
|
|
366
|
+
return data?.toJs ?? []
|
|
324
367
|
}
|
|
325
368
|
|
|
326
369
|
@objc public func deviceCharacteristicWrite(id: String, serviceId: String, characteristicId: String, data: Array<UInt8>, withResponse: Bool) async throws {
|
|
@@ -384,6 +427,18 @@ extension BBDevice {
|
|
|
384
427
|
|
|
385
428
|
// MARK: - Exporters
|
|
386
429
|
|
|
430
|
+
extension UUID {
|
|
431
|
+
var toJs: String {
|
|
432
|
+
return uuidString
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
extension BBUUID {
|
|
437
|
+
var toJs: String {
|
|
438
|
+
return uuidString
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
387
442
|
extension BBAuthorization {
|
|
388
443
|
var toJs: String {
|
|
389
444
|
switch self {
|
|
@@ -428,7 +483,7 @@ extension BBScanResult {
|
|
|
428
483
|
"advertisedServices": advertisedServices.map(\.uuidString),
|
|
429
484
|
"manufacturerId": manufacturerId as Any,
|
|
430
485
|
"manufacturerName": manufacturerName as Any,
|
|
431
|
-
"manufacturerData": manufacturerData?.
|
|
486
|
+
"manufacturerData": manufacturerData?.toJs as Any,
|
|
432
487
|
]
|
|
433
488
|
}
|
|
434
489
|
}
|
|
@@ -480,7 +535,7 @@ extension [BBUUID: [BBCharacteristic]] {
|
|
|
480
535
|
}
|
|
481
536
|
|
|
482
537
|
extension Data {
|
|
483
|
-
var
|
|
538
|
+
var toJs: Array<UInt8> {
|
|
484
539
|
map { $0 }
|
|
485
540
|
}
|
|
486
541
|
}
|
package/ios/Bluebreeze.h
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
|
|
2
|
+
#import <React/RCTInitializing.h>
|
|
3
|
+
#import <React/RCTInvalidating.h>
|
|
2
4
|
#import "generated/RNBlueBreezeSpec/RNBlueBreezeSpec.h"
|
|
3
5
|
|
|
4
|
-
@interface BlueBreeze : NativeBlueBreezeSpecBase <NativeBlueBreezeSpec>
|
|
6
|
+
@interface BlueBreeze : NativeBlueBreezeSpecBase <NativeBlueBreezeSpec, RCTInitializing, RCTInvalidating>
|
|
5
7
|
|
|
6
8
|
@end
|
package/ios/Bluebreeze.mm
CHANGED
|
@@ -14,111 +14,86 @@
|
|
|
14
14
|
self = [super init];
|
|
15
15
|
if (self) {
|
|
16
16
|
impl = [BlueBreezeImpl new];
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
[impl stateObserveOnChanged:^(NSString * _Nonnull status) {
|
|
26
|
-
if (self->_eventEmitterCallback != nil) {
|
|
27
|
-
[self emitStateEmitter:status];
|
|
28
|
-
}
|
|
29
|
-
}];
|
|
17
|
+
}
|
|
18
|
+
return self;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// MARK: - Initialization and deinitialization
|
|
22
|
+
|
|
23
|
+
typedef void (^EmitterCallback)();
|
|
30
24
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
- (void)wrapEventEmitter:(EmitterCallback)callback {
|
|
26
|
+
if (self->_eventEmitterCallback != nil) {
|
|
27
|
+
callback();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
- (void)initialize {
|
|
32
|
+
[impl subscribeWithStateObserve:^(NSString * _Nonnull status) {
|
|
33
|
+
[self wrapEventEmitter:^{
|
|
34
|
+
[self emitStateEmitter:status];
|
|
35
35
|
}];
|
|
36
|
-
|
|
37
|
-
[
|
|
38
|
-
|
|
39
|
-
[self emitScanEnabledEmitter:status];
|
|
40
|
-
}
|
|
36
|
+
} authorizationObserve:^(NSString * _Nonnull status) {
|
|
37
|
+
[self wrapEventEmitter:^{
|
|
38
|
+
[self emitAuthorizationStatusEmitter:status];
|
|
41
39
|
}];
|
|
42
|
-
|
|
43
|
-
[
|
|
44
|
-
|
|
45
|
-
[self emitScanResultEmitter:scanResult];
|
|
46
|
-
}
|
|
40
|
+
} scanEnabledObserve:^(BOOL status) {
|
|
41
|
+
[self wrapEventEmitter:^{
|
|
42
|
+
[self emitScanEnabledEmitter:status];
|
|
47
43
|
}];
|
|
48
|
-
|
|
49
|
-
[
|
|
50
|
-
|
|
51
|
-
NSString* deviceId = device[@"id"];
|
|
52
|
-
|
|
53
|
-
if ([self->trackedDeviceServices indexOfObject:deviceId] == NSNotFound) {
|
|
54
|
-
[self->trackedDeviceServices addObject:deviceId];
|
|
55
|
-
[self->impl deviceServicesObserveWithId:deviceId onChanged:^(NSArray<id<NSObject>> * _Nonnull value) {
|
|
56
|
-
[self emitDeviceServicesEmitter:@{
|
|
57
|
-
@"id": deviceId,
|
|
58
|
-
@"value": value
|
|
59
|
-
}];
|
|
60
|
-
|
|
61
|
-
for (id service in value) {
|
|
62
|
-
NSString* serviceId = service[@"id"];
|
|
63
|
-
for (id characteristic in service[@"characteristics"]) {
|
|
64
|
-
NSString* characteristicId = characteristic[@"id"];
|
|
65
|
-
NSString* trackingKey = [NSString stringWithFormat:@"%@:%@:%@", deviceId, serviceId, characteristicId];
|
|
66
|
-
|
|
67
|
-
if ([self->trackedDeviceCharacteristicData indexOfObject:trackingKey] == NSNotFound) {
|
|
68
|
-
[self->trackedDeviceConnectionStatus addObject:trackingKey];
|
|
69
|
-
[self->impl deviceCharacteristicDataObserveWithId:deviceId serviceId:serviceId characteristicId:characteristicId onChanged:^(NSArray<NSNumber *> * _Nonnull value) {
|
|
70
|
-
[self emitDeviceCharacteristicDataEmitter:@{
|
|
71
|
-
@"id": deviceId,
|
|
72
|
-
@"serviceId": serviceId,
|
|
73
|
-
@"characteristicId": characteristicId,
|
|
74
|
-
@"value": value
|
|
75
|
-
}];
|
|
76
|
-
}];
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if ([self->trackedDeviceCharacteristicNotifyEnabled indexOfObject:trackingKey] == NSNotFound) {
|
|
80
|
-
[self->trackedDeviceCharacteristicNotifyEnabled addObject:trackingKey];
|
|
81
|
-
[self->impl deviceCharacteristicNotifyEnabledObserveWithId:deviceId serviceId:serviceId characteristicId:characteristicId onChanged:^(BOOL value) {
|
|
82
|
-
[self emitDeviceCharacteristicNotifyEnabledEmitter:@{
|
|
83
|
-
@"id": deviceId,
|
|
84
|
-
@"serviceId": serviceId,
|
|
85
|
-
@"characteristicId": characteristicId,
|
|
86
|
-
@"value": [NSNumber numberWithBool:value]
|
|
87
|
-
}];
|
|
88
|
-
}];
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}];
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if ([self->trackedDeviceConnectionStatus indexOfObject:deviceId] == NSNotFound) {
|
|
96
|
-
[self->trackedDeviceConnectionStatus addObject:deviceId];
|
|
97
|
-
[self->impl deviceConnectionStatusObserveWithId:deviceId onChanged:^(NSString * _Nonnull value) {
|
|
98
|
-
[self emitDeviceConnectionStatusEmitter:@{
|
|
99
|
-
@"id": deviceId,
|
|
100
|
-
@"value": value
|
|
101
|
-
}];
|
|
102
|
-
}];
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if ([self->trackedDeviceMTU indexOfObject:deviceId] == NSNotFound) {
|
|
106
|
-
[self->trackedDeviceMTU addObject:deviceId];
|
|
107
|
-
[self->impl deviceMTUObserveWithId:deviceId onChanged:^(NSInteger value) {
|
|
108
|
-
[self emitDeviceMTUEmitter:@{
|
|
109
|
-
@"id": deviceId,
|
|
110
|
-
@"value": [NSNumber numberWithInt:value]
|
|
111
|
-
}];
|
|
112
|
-
}];
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (self->_eventEmitterCallback != nil) {
|
|
117
|
-
[self emitDevicesEmitter:devices];
|
|
118
|
-
}
|
|
44
|
+
} scanResultsObserve:^(NSDictionary<NSString *,id> * _Nonnull scanResult) {
|
|
45
|
+
[self wrapEventEmitter:^{
|
|
46
|
+
[self emitScanResultEmitter:scanResult];
|
|
119
47
|
}];
|
|
120
|
-
}
|
|
121
|
-
|
|
48
|
+
} devicesObserve:^(NSArray<id<NSObject>> *devices) {
|
|
49
|
+
[self wrapEventEmitter:^{
|
|
50
|
+
[self emitDevicesEmitter:devices];
|
|
51
|
+
}];
|
|
52
|
+
} deviceConnectionStatusObserve:^(NSString * _Nonnull deviceId, NSString * _Nonnull value) {
|
|
53
|
+
[self wrapEventEmitter:^{
|
|
54
|
+
[self emitDeviceConnectionStatusEmitter:@{
|
|
55
|
+
@"id": deviceId,
|
|
56
|
+
@"value": value
|
|
57
|
+
}];
|
|
58
|
+
}];
|
|
59
|
+
} deviceServicesObserve:^(NSString * _Nonnull deviceId, NSArray<NSDictionary<NSString *,id> *> * _Nonnull value) {
|
|
60
|
+
[self wrapEventEmitter:^{
|
|
61
|
+
[self emitDeviceServicesEmitter:@{
|
|
62
|
+
@"id": deviceId,
|
|
63
|
+
@"value": value
|
|
64
|
+
}];
|
|
65
|
+
}];
|
|
66
|
+
} deviceMTUObserve:^(NSString * _Nonnull deviceId, NSInteger value) {
|
|
67
|
+
[self wrapEventEmitter:^{
|
|
68
|
+
[self emitDeviceMTUEmitter:@{
|
|
69
|
+
@"id": deviceId,
|
|
70
|
+
@"value": [NSNumber numberWithInt:value]
|
|
71
|
+
}];
|
|
72
|
+
}];
|
|
73
|
+
} deviceCharacteristicDataObserve:^(NSString * _Nonnull deviceId, NSString * _Nonnull serviceId, NSString * _Nonnull characteristicId, NSArray<NSNumber *> * _Nonnull value) {
|
|
74
|
+
[self wrapEventEmitter:^{
|
|
75
|
+
[self emitDeviceCharacteristicDataEmitter:@{
|
|
76
|
+
@"id": deviceId,
|
|
77
|
+
@"serviceId": serviceId,
|
|
78
|
+
@"characteristicId": characteristicId,
|
|
79
|
+
@"value": value
|
|
80
|
+
}];
|
|
81
|
+
}];
|
|
82
|
+
} deviceCharacteristicNotifyEnabledObserve:^(NSString * _Nonnull deviceId, NSString * _Nonnull serviceId, NSString * _Nonnull characteristicId, BOOL value) {
|
|
83
|
+
[self wrapEventEmitter:^{
|
|
84
|
+
[self emitDeviceCharacteristicNotifyEnabledEmitter:@{
|
|
85
|
+
@"id": deviceId,
|
|
86
|
+
@"serviceId": serviceId,
|
|
87
|
+
@"characteristicId": characteristicId,
|
|
88
|
+
@"value": [NSNumber numberWithBool:value]
|
|
89
|
+
}];
|
|
90
|
+
}];
|
|
91
|
+
}];
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
- (void)invalidate {
|
|
96
|
+
[impl unsubscribe];
|
|
122
97
|
}
|
|
123
98
|
|
|
124
99
|
RCT_EXPORT_MODULE()
|
|
@@ -129,6 +104,10 @@ RCT_EXPORT_MODULE()
|
|
|
129
104
|
return std::make_shared<facebook::react::NativeBlueBreezeSpecJSI>(params);
|
|
130
105
|
}
|
|
131
106
|
|
|
107
|
+
- (void)setEventEmitterCallback:(EventEmitterCallbackWrapper *)eventEmitterCallbackWrapper {
|
|
108
|
+
[super setEventEmitterCallback:eventEmitterCallbackWrapper];
|
|
109
|
+
}
|
|
110
|
+
|
|
132
111
|
// MARK: - State
|
|
133
112
|
|
|
134
113
|
- (NSString *)state {
|
package/package.json
CHANGED