Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desired changes to use this library in noble (@abandonware/noble) #71

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
32 changes: 29 additions & 3 deletions src/Device.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,30 @@ class Device extends EventEmitter {
return this.helper.prop('Connected')
}

/**
* Service advertisement data. Keys are the UUIDs in string format followed by its byte array value.
* @returns {object}
*/
async getServiceAdvertisementData () {
return this.helper.prop('ServiceData')
}

/**
* Manufacturer specific advertisement data. Keys are 16 bits Manufacturer ID followed by its byte array value.
* @returns {object}
*/
async getManufacturerAdvertisementData () {
return this.helper.prop('ManufacturerData')
}

/**
* List of 128-bit UUIDs that represents the available remote services.
* @returns {string[]}
*/
async getServiceUUIDs () {
return this.helper.prop('UUIDs')
}

/**
* This method will connect to the remote device
*/
Expand All @@ -103,9 +127,10 @@ class Device extends EventEmitter {
if ('Connected' in propertiesChanged) {
const { value } = propertiesChanged.Connected
if (value) {
this.emit('connect', { connected: true })
this.emit('connect', { connected: true, deviceUuid: this.device })
} else {
this.emit('disconnect', { connected: false })
this.emit('disconnect', { connected: false, deviceUuid: this.device })
this.helper.removeAllListeners('PropertiesChanged') // might be improved
}
}
}
Expand All @@ -119,7 +144,6 @@ class Device extends EventEmitter {
*/
async disconnect () {
await this.helper.callMethod('Disconnect')
this.helper.removeListeners()
}

/**
Expand Down Expand Up @@ -150,6 +174,7 @@ class Device extends EventEmitter {
* @event Device#connect
* @type {object}
* @property {boolean} connected - Indicates current connection status.
* @property {string} deviceUuid - The UUID of the device freshly connected
*/

/**
Expand All @@ -158,6 +183,7 @@ class Device extends EventEmitter {
* @event Device#disconnect
* @type {object}
* @property {boolean} connected - Indicates current connection status.
* @property {string} deviceUuid - The UUID of the device freshly disconnected
*/

module.exports = Device
6 changes: 4 additions & 2 deletions src/GattCharacteristic.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ class GattCharacteristic extends EventEmitter {
* It emits valuechanged event when receives a notification.
*/
async startNotifications () {
await this.helper.callMethod('StartNotify')

const cb = (propertiesChanged) => {
if ('Value' in propertiesChanged) {
const { value } = propertiesChanged.Value
Expand All @@ -115,6 +113,10 @@ class GattCharacteristic extends EventEmitter {
}

this.helper.on('PropertiesChanged', cb)

// Call StartNotify after the listener is attached in order not to lose
// the first notifications of the device.
await this.helper.callMethod('StartNotify')
}

async stopNotifications () {
Expand Down
Loading