@stoprocent/noble 2.5.1 → 2.5.2

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.
@@ -109,7 +109,8 @@ function buildAdvertisement (deviceProps) {
109
109
  const entries = Object.entries(deviceProps.ManufacturerData);
110
110
  if (entries.length > 0) {
111
111
  const buffers = [];
112
- for (const [companyId, payload] of entries) {
112
+ for (const [companyId, rawPayload] of entries) {
113
+ const payload = unwrapVariant(rawPayload);
113
114
  const id = Number(companyId) & 0xffff;
114
115
  const header = Buffer.from([id & 0xff, (id >> 8) & 0xff]);
115
116
  const data = Buffer.isBuffer(payload) ? payload : Buffer.from(payload);
@@ -120,7 +121,8 @@ function buildAdvertisement (deviceProps) {
120
121
  }
121
122
 
122
123
  if (deviceProps.ServiceData && typeof deviceProps.ServiceData === 'object') {
123
- for (const [uuid, payload] of Object.entries(deviceProps.ServiceData)) {
124
+ for (const [uuid, rawPayload] of Object.entries(deviceProps.ServiceData)) {
125
+ const payload = unwrapVariant(rawPayload);
124
126
  advertisement.serviceData.push({
125
127
  uuid: normalizeUuid(uuid),
126
128
  data: Buffer.isBuffer(payload) ? payload : Buffer.from(payload)
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.5.1",
9
+ "version": "2.5.2",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "https://github.com/stoprocent/noble.git"
@@ -270,6 +270,44 @@ describe('dbus/bindings', () => {
270
270
  expect(advertisement.serviceUuids).toEqual(['180d']);
271
271
  });
272
272
 
273
+ test('InterfacesAdded unwraps Variant-wrapped ManufacturerData and ServiceData payloads', async () => {
274
+ const bindings = new DbusBindings();
275
+ const discoveries = [];
276
+ bindings.on('discover', (...args) => discoveries.push(args));
277
+
278
+ bindings.start();
279
+ await flush();
280
+
281
+ // BlueZ exposes ManufacturerData as a{qv} and ServiceData as a{sv}; dbus-next
282
+ // surfaces each inner value as a Variant, not the raw bytes.
283
+ const mfgPayload = Buffer.from([0xde, 0xad, 0xbe, 0xef]);
284
+ const svcPayload = Buffer.from([0x01, 0x02, 0x03]);
285
+
286
+ const om = state.rootProxy.getInterface('org.freedesktop.DBus.ObjectManager');
287
+ om.emit('InterfacesAdded', '/org/bluez/hci0/dev_AA_BB_CC_DD_EE_FF', {
288
+ 'org.bluez.Device1': wrapDict({
289
+ Address: 'AA:BB:CC:DD:EE:FF',
290
+ AddressType: 'public',
291
+ ManufacturerData: { 0x004c: v('ay', mfgPayload) },
292
+ ServiceData: { '0000180d-0000-1000-8000-00805f9b34fb': v('ay', svcPayload) }
293
+ })
294
+ });
295
+ await flush();
296
+
297
+ expect(discoveries.length).toBe(1);
298
+ const advertisement = discoveries[0][4];
299
+
300
+ // Manufacturer: 2-byte little-endian company id (0x004c => Apple) + payload
301
+ expect(Buffer.isBuffer(advertisement.manufacturerData)).toBe(true);
302
+ expect(advertisement.manufacturerData.equals(
303
+ Buffer.concat([Buffer.from([0x4c, 0x00]), mfgPayload])
304
+ )).toBe(true);
305
+
306
+ expect(advertisement.serviceData).toEqual([
307
+ { uuid: '180d', data: svcPayload }
308
+ ]);
309
+ });
310
+
273
311
  test('discoverServices/Characteristics/Descriptors walk the cached object tree', async () => {
274
312
  const tree = adapterTree({
275
313
  '/org/bluez/hci0/dev_AA_BB_CC_DD_EE_FF': {