Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ Device class interacts with a remote device.
* [.getAlias()](#Device+getAlias) ⇒ <code>string</code>
* [.getRSSI()](#Device+getRSSI) ⇒ <code>number</code>
* [.getTXPower()](#Device+getTXPower) ⇒ <code>number</code>
* [.getManufacturerData()](#Device+getManufacturerData) ⇒ <code>Object.&lt;string, any&gt;</code>
* [.getAdvertisingData()](#Device+getAdvertisingData) ⇒ <code>Object.&lt;string, any&gt;</code>
* [.isPaired()](#Device+isPaired) ⇒ <code>boolean</code>
* [.isConnected()](#Device+isConnected) ⇒ <code>boolean</code>
* [.pair()](#Device+pair)
Expand Down Expand Up @@ -266,6 +268,18 @@ Received Signal Strength Indicator of the remote device
### device.getTXPower() ⇒ <code>number</code>
Advertised transmitted power level.

**Kind**: instance method of [<code>Device</code>](#Device)
<a name="Device+getManufacturerData"></a>

### device.getManufacturerData() ⇒ <code>Object.&lt;string, any&gt;</code>
Advertised transmitted manufacturer data.

**Kind**: instance method of [<code>Device</code>](#Device)
<a name="Device+getAdvertisingData"></a>

### device.getAdvertisingData() ⇒ <code>Object.&lt;string, any&gt;</code>
Advertised transmitted data.

**Kind**: instance method of [<code>Device</code>](#Device)
<a name="Device+isPaired"></a>

Expand Down
16 changes: 16 additions & 0 deletions src/Device.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ class Device extends EventEmitter {
return this.helper.prop('TxPower')
}

/**
* Advertised transmitted manufacturer data.
* @returns {Object.<string, any>}
*/
async getManufacturerData () {
return this.helper.prop('ManufacturerData')
}

/**
* Advertised transmitted data.
* @returns {Object.<string, any>}
*/
async getAdvertisingData () {
return this.helper.prop('AdvertisingData')
}

/**
* Indicates if the remote device is paired.
* @returns {boolean}
Expand Down
4 changes: 3 additions & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ declare namespace NodeBle {
getAddressType(): Promise<string>;
getAlias(): Promise<string>;
getRSSI(): Promise<string>;
getManufacturerData(): Promise<{[key:string]:any}>;
getAdvertisingData(): Promise<{[key:string]:any}>;
isPaired(): Promise<string>;
isConnected(): Promise<string>;
pair(): Promise<void>;
Expand Down Expand Up @@ -71,7 +73,7 @@ declare namespace NodeBle {
adapters(): Promise<string[]>;
defaultAdapter(): Promise<Adapter>;
getAdapter(adapter: string): Promise<Adapter>;
}
}

function createBluetooth(): {
destroy(): void;
Expand Down
5 changes: 4 additions & 1 deletion test/Device.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ test('props', async () => {
Alias: '_alias_',
RSSI: 100,
TxPower: 50,

ManufacturerData: { 1: { signature: 'ay', value: { type: 'Buffer', data: Buffer.from('test') } } },
AdvertisingData: { 2: { signature: 'ay', value: { type: 'Buffer', data: Buffer.from('test') } } },
Paired: true,
Connected: true
}[value])))
Expand All @@ -44,6 +45,8 @@ test('props', async () => {
await expect(device.getAlias()).resolves.toEqual('_alias_')
await expect(device.getRSSI()).resolves.toEqual(100)
await expect(device.getTXPower()).resolves.toEqual(50)
await expect(device.getManufacturerData()).resolves.toMatchObject({ 1: { signature: 'ay', value: { type: 'Buffer', data: Buffer.from('test') } } })
await expect(device.getAdvertisingData()).resolves.toMatchObject({ 2: { signature: 'ay', value: { type: 'Buffer', data: Buffer.from('test') } } })

await expect(device.isConnected()).resolves.toEqual(true)
await expect(device.isPaired()).resolves.toEqual(true)
Expand Down