@stoprocent/noble 2.3.1 → 2.3.3
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/lib/noble.js +1 -1
- package/lib/win/src/ble_manager.cc +12 -6
- package/lib/win/src/peripheral_winrt.cc +16 -4
- package/lib/win/src/peripheral_winrt.h +1 -1
- package/lib/win/src/radio_watcher.cc +17 -14
- package/package.json +1 -1
- package/prebuilds/darwin-x64+arm64/@stoprocent+noble.node +0 -0
- package/prebuilds/win32-ia32/@stoprocent+noble.node +0 -0
- package/prebuilds/win32-x64/@stoprocent+noble.node +0 -0
package/lib/noble.js
CHANGED
|
@@ -171,8 +171,8 @@ class Noble extends EventEmitter {
|
|
|
171
171
|
}, timeout);
|
|
172
172
|
|
|
173
173
|
const listener = (state) => {
|
|
174
|
-
clearTimeout(timeoutId);
|
|
175
174
|
if (state === 'poweredOn') {
|
|
175
|
+
clearTimeout(timeoutId);
|
|
176
176
|
resolve();
|
|
177
177
|
} else {
|
|
178
178
|
this.once('stateChange', listener);
|
|
@@ -413,9 +413,12 @@ void BLEManager::OnConnectionStatusChanged(BluetoothLEDevice device,
|
|
|
413
413
|
return;
|
|
414
414
|
}
|
|
415
415
|
PeripheralWinrt& peripheral = mDeviceMap[uuid];
|
|
416
|
-
peripheral.
|
|
417
|
-
|
|
418
|
-
|
|
416
|
+
if(peripheral.device.has_value() && &(peripheral.device.value()) == &device )
|
|
417
|
+
{
|
|
418
|
+
peripheral.Disconnect();
|
|
419
|
+
mNotifyMap.Remove(uuid);
|
|
420
|
+
mEmit.Disconnected(uuid);
|
|
421
|
+
}
|
|
419
422
|
}
|
|
420
423
|
}
|
|
421
424
|
|
|
@@ -454,7 +457,7 @@ void BLEManager::OnServicesDiscovered(IAsyncOperation<GattDeviceServicesResult>
|
|
|
454
457
|
};
|
|
455
458
|
|
|
456
459
|
CHECK_STATUS_AND_RESULT(status, result, emit);
|
|
457
|
-
|
|
460
|
+
PeripheralWinrt& peripheral = mDeviceMap[uuid];
|
|
458
461
|
FOR(service, result.Services())
|
|
459
462
|
{
|
|
460
463
|
auto id = service.Uuid();
|
|
@@ -462,6 +465,8 @@ void BLEManager::OnServicesDiscovered(IAsyncOperation<GattDeviceServicesResult>
|
|
|
462
465
|
{
|
|
463
466
|
serviceUuids.push_back(toStr(id));
|
|
464
467
|
}
|
|
468
|
+
//remember for cleanup
|
|
469
|
+
peripheral.cachedServices.insert(std::make_pair(id, CachedService(service)));
|
|
465
470
|
}
|
|
466
471
|
mEmit.ServicesDiscovered(uuid, serviceUuids);
|
|
467
472
|
}
|
|
@@ -503,7 +508,7 @@ void BLEManager::OnIncludedServicesDiscovered(IAsyncOperation<GattDeviceServices
|
|
|
503
508
|
};
|
|
504
509
|
|
|
505
510
|
CHECK_STATUS_AND_RESULT(status, result, emit);
|
|
506
|
-
|
|
511
|
+
PeripheralWinrt& peripheral = mDeviceMap[uuid];
|
|
507
512
|
FOR(service, result.Services())
|
|
508
513
|
{
|
|
509
514
|
auto id = service.Uuid();
|
|
@@ -511,6 +516,8 @@ void BLEManager::OnIncludedServicesDiscovered(IAsyncOperation<GattDeviceServices
|
|
|
511
516
|
{
|
|
512
517
|
servicesUuids.push_back(toStr(id));
|
|
513
518
|
}
|
|
519
|
+
//remember for cleanup
|
|
520
|
+
peripheral.cachedServices.insert(std::make_pair(id, CachedService(service)));
|
|
514
521
|
}
|
|
515
522
|
mEmit.IncludedServicesDiscovered(uuid, serviceId, servicesUuids);
|
|
516
523
|
}
|
|
@@ -552,7 +559,6 @@ void BLEManager::OnCharacteristicsDiscovered(IAsyncOperation<GattCharacteristics
|
|
|
552
559
|
};
|
|
553
560
|
|
|
554
561
|
CHECK_STATUS_AND_RESULT(status, result, emit);
|
|
555
|
-
|
|
556
562
|
FOR(characteristic, result.Characteristics())
|
|
557
563
|
{
|
|
558
564
|
auto id = characteristic.Uuid();
|
|
@@ -162,15 +162,27 @@ void PeripheralWinrt::Update(const int rssiValue, const BluetoothLEAdvertisement
|
|
|
162
162
|
|
|
163
163
|
void PeripheralWinrt::Disconnect()
|
|
164
164
|
{
|
|
165
|
+
//clean up to ensure disconnect from Windows
|
|
166
|
+
for(auto const& cachedService : cachedServices)
|
|
167
|
+
{
|
|
168
|
+
cachedService.second.service.Close();
|
|
169
|
+
}
|
|
165
170
|
cachedServices.clear();
|
|
166
|
-
if (gattSession.has_value()
|
|
171
|
+
if (gattSession.has_value())
|
|
167
172
|
{
|
|
168
|
-
|
|
173
|
+
if(maxPduSizeChangedToken)
|
|
174
|
+
{
|
|
175
|
+
gattSession->MaxPduSizeChanged(maxPduSizeChangedToken);
|
|
176
|
+
}
|
|
177
|
+
gattSession->Close();
|
|
169
178
|
}
|
|
170
|
-
if (device.has_value()
|
|
179
|
+
if (device.has_value())
|
|
171
180
|
{
|
|
181
|
+
if(connectionToken)
|
|
182
|
+
{
|
|
183
|
+
device->ConnectionStatusChanged(connectionToken);
|
|
184
|
+
}
|
|
172
185
|
device->Close();
|
|
173
|
-
device->ConnectionStatusChanged(connectionToken);
|
|
174
186
|
}
|
|
175
187
|
device = std::nullopt;
|
|
176
188
|
}
|
|
@@ -72,6 +72,7 @@ public:
|
|
|
72
72
|
winrt::event_token connectionToken;
|
|
73
73
|
std::optional<GattSession> gattSession;
|
|
74
74
|
winrt::event_token maxPduSizeChangedToken;
|
|
75
|
+
std::unordered_map<winrt::guid, CachedService> cachedServices;
|
|
75
76
|
|
|
76
77
|
private:
|
|
77
78
|
void GetServiceFromDevice(winrt::guid serviceUuid,
|
|
@@ -82,6 +83,5 @@ private:
|
|
|
82
83
|
void
|
|
83
84
|
GetDescriptorFromCharacteristic(GattCharacteristic characteristic, winrt::guid descriptorUuid,
|
|
84
85
|
std::function<void(std::optional<GattDescriptor>)> callback);
|
|
85
|
-
std::unordered_map<winrt::guid, CachedService> cachedServices;
|
|
86
86
|
void ProcessServiceData(const BluetoothLEAdvertisementDataSection& ds, size_t uuidSize);
|
|
87
87
|
};
|
|
@@ -80,22 +80,25 @@ winrt::fire_and_forget RadioWatcher::OnRadioChanged() {
|
|
|
80
80
|
capabilities.centralRoleSupported = adapter.IsCentralRoleSupported();
|
|
81
81
|
|
|
82
82
|
Radio bluetooth = nullptr;
|
|
83
|
-
if
|
|
83
|
+
if(adapter.IsCentralRoleSupported())
|
|
84
|
+
{
|
|
85
|
+
// Always set up radio state monitoring for any radio (on or off)
|
|
84
86
|
bluetooth = radio;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
} else {
|
|
96
|
-
mRadioStateChangedRevoker.revoke();
|
|
97
|
-
}
|
|
87
|
+
mRadioStateChangedRevoker.revoke();
|
|
88
|
+
mRadioStateChangedRevoker = radio.StateChanged(
|
|
89
|
+
winrt::auto_revoke,
|
|
90
|
+
[this, capabilities](Radio radio, auto&&) {
|
|
91
|
+
Radio bluetooth = radio;
|
|
92
|
+
radioStateChanged(bluetooth, capabilities);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
radioStateChanged(bluetooth, capabilities);
|
|
96
|
+
mRadio = bluetooth;
|
|
98
97
|
|
|
98
|
+
}
|
|
99
|
+
else
|
|
100
|
+
{
|
|
101
|
+
mRadioStateChangedRevoker.revoke();
|
|
99
102
|
radioStateChanged(bluetooth, capabilities);
|
|
100
103
|
mRadio = bluetooth;
|
|
101
104
|
}
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|