@stoprocent/noble 2.3.14 → 2.3.15

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.
@@ -92,16 +92,21 @@ void PeripheralWinrt::ProcessServiceData(const BluetoothLEAdvertisementDataSecti
92
92
  dr.Close();
93
93
  }
94
94
 
95
+ static std::string advSectionToString(const winrt::Windows::Devices::Bluetooth::Advertisement::BluetoothLEAdvertisementDataSection &sec)
96
+ {
97
+ std::string result;
98
+ result.resize(sec.Data().Length());
99
+ auto reader = DataReader::FromBuffer(sec.Data());
100
+ reader.ReadBytes(winrt::array_view<uint8_t>(
101
+ reinterpret_cast<uint8_t*>(result.data()),
102
+ reinterpret_cast<uint8_t*>(result.data() + result.size())
103
+ ));
104
+ return result;
105
+ }
106
+
95
107
  void PeripheralWinrt::Update(const int rssiValue, const BluetoothLEAdvertisement& advertisment,
96
108
  const BluetoothLEAdvertisementType& advertismentType)
97
109
  {
98
- // Handle name
99
- std::string localName = ws2s(advertisment.LocalName().c_str());
100
- if (!localName.empty())
101
- {
102
- name = std::optional<std::string>(localName);
103
- }
104
-
105
110
  connectable = advertismentType == BluetoothLEAdvertisementType::ConnectableUndirected ||
106
111
  advertismentType == BluetoothLEAdvertisementType::ConnectableDirected;
107
112
 
@@ -144,6 +149,18 @@ void PeripheralWinrt::Update(const int rssiValue, const BluetoothLEAdvertisement
144
149
  {
145
150
  ProcessServiceData(ds, 16); // 16 bytes for 128-bit UUID
146
151
  }
152
+ else if (ds.DataType() == BluetoothLEAdvertisementDataTypes::ShortenedLocalName())
153
+ {
154
+ if (!nameIsComplete)
155
+ {
156
+ name = advSectionToString(ds); // use shortened local name if no complete name is available
157
+ }
158
+ }
159
+ else if (ds.DataType() == BluetoothLEAdvertisementDataTypes::CompleteLocalName())
160
+ {
161
+ name = advSectionToString(ds);
162
+ nameIsComplete = true; // set the flag to ignore shortened local names
163
+ }
147
164
  }
148
165
 
149
166
  // Handle service UUIDs
@@ -73,6 +73,7 @@ public:
73
73
  std::optional<GattSession> gattSession;
74
74
  winrt::event_token maxPduSizeChangedToken;
75
75
  std::unordered_map<winrt::guid, CachedService> cachedServices;
76
+ bool nameIsComplete { false }; // `name` is the Complete Local Name
76
77
 
77
78
  private:
78
79
  void GetServiceFromDevice(winrt::guid serviceUuid,
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "license": "MIT",
7
7
  "name": "@stoprocent/noble",
8
8
  "description": "A Node.js BLE (Bluetooth Low Energy) central library.",
9
- "version": "2.3.14",
9
+ "version": "2.3.15",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "https://github.com/stoprocent/noble.git"