@stoprocent/bleno 0.8.4 → 0.8.6
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.
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
@interface BLEPeripheralManager () <CBPeripheralManagerDelegate>
|
|
14
14
|
|
|
15
15
|
@property (nonatomic, strong) dispatch_queue_t queue;
|
|
16
|
+
@property (nonatomic, strong) NSMutableArray<NSDictionary *> *pendingNotifications;
|
|
16
17
|
@property (nonatomic, strong) CBPeripheralManager *peripheralManager;
|
|
17
18
|
|
|
18
19
|
@end
|
|
@@ -22,12 +23,32 @@
|
|
|
22
23
|
- (instancetype)init {
|
|
23
24
|
if (self = [super init]) {
|
|
24
25
|
// NSLog(@"-[BLEPeripheralManager init]");
|
|
25
|
-
|
|
26
|
-
self.
|
|
26
|
+
self.queue = dispatch_queue_create("CBqueue", DISPATCH_QUEUE_SERIAL);
|
|
27
|
+
self.pendingNotifications = [NSMutableArray array];
|
|
27
28
|
}
|
|
28
29
|
return self;
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
- (void)sendNotifications {
|
|
33
|
+
while (self.pendingNotifications.count > 0) {
|
|
34
|
+
NSDictionary *notification = self.pendingNotifications.firstObject;
|
|
35
|
+
NSData *data = notification[@"data"];
|
|
36
|
+
CBMutableCharacteristic *characteristic = notification[@"characteristic"];
|
|
37
|
+
CBCentral *central = notification[@"central"];
|
|
38
|
+
|
|
39
|
+
BOOL success = [self.peripheralManager updateValue:data
|
|
40
|
+
forCharacteristic:characteristic
|
|
41
|
+
onSubscribedCentrals:@[central]];
|
|
42
|
+
|
|
43
|
+
if (!success) {
|
|
44
|
+
break; // Wait until next ready callback
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Remove the successfully sent notification
|
|
48
|
+
[self.pendingNotifications removeObjectAtIndex:0];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
31
52
|
#pragma mark - API
|
|
32
53
|
|
|
33
54
|
- (void)start {
|
|
@@ -146,19 +167,22 @@
|
|
|
146
167
|
|
|
147
168
|
for (auto it = emitters.begin(); it != emitters.end(); ++it) {
|
|
148
169
|
if ([it->first isEqual:uuid]) {
|
|
149
|
-
auto cb = [
|
|
150
|
-
NSLog(@"subscription note: %@ %@", data, NSStringFromClass(characteristic.class));
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
170
|
+
auto cb = [=](NSData *data) {
|
|
171
|
+
// NSLog(@"subscription note: %@ %@", data, NSStringFromClass(characteristic.class));
|
|
172
|
+
|
|
173
|
+
// Dispatch since cb is called from node
|
|
174
|
+
dispatch_async(self.queue, ^{
|
|
175
|
+
NSDictionary *notification = @{
|
|
176
|
+
@"data": data,
|
|
177
|
+
@"characteristic": characteristic,
|
|
178
|
+
@"central": central
|
|
179
|
+
};
|
|
180
|
+
[self.pendingNotifications addObject:notification];
|
|
181
|
+
[self sendNotifications];
|
|
182
|
+
});
|
|
155
183
|
};
|
|
156
184
|
|
|
157
185
|
it->second.Subscribe(central.maximumUpdateValueLength, cb);
|
|
158
|
-
|
|
159
|
-
if ((characteristic.properties & CBCharacteristicPropertyNotify) == CBCharacteristicPropertyNotify) {
|
|
160
|
-
|
|
161
|
-
}
|
|
162
186
|
}
|
|
163
187
|
}
|
|
164
188
|
}
|
|
@@ -224,6 +248,7 @@
|
|
|
224
248
|
|
|
225
249
|
- (void)peripheralManagerIsReadyToUpdateSubscribers:(CBPeripheralManager *)peripheral {
|
|
226
250
|
// NSLog(@"peripheralManagerIsReadyToUpdateSubscribers");
|
|
251
|
+
[self sendNotifications];
|
|
227
252
|
}
|
|
228
253
|
|
|
229
254
|
- (void)peripheralManager:(CBPeripheralManager *)peripheral didPublishL2CAPChannel:(CBL2CAPPSM)PSM error:(nullable NSError *)error {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stoprocent/bleno",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.6",
|
|
4
4
|
"description": "A Node.js module for implementing BLE (Bluetooth Low Energy) peripherals",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"node-gyp-build": "^4.8.1"
|
|
71
71
|
},
|
|
72
72
|
"optionalDependencies": {
|
|
73
|
-
"@stoprocent/bluetooth-hci-socket": "^1.5.
|
|
73
|
+
"@stoprocent/bluetooth-hci-socket": "^1.5.2",
|
|
74
74
|
"bplist-parser": "0.3.2",
|
|
75
75
|
"xpc-connect": "^3.0.0"
|
|
76
76
|
},
|
|
Binary file
|
|
Binary file
|
|
Binary file
|