Comparing version 1.8.1 to 1.9.0
@@ -0,1 +1,11 @@ | ||
## Version 1.9.0 | ||
* Don't initialize bindings until first state change listener added | ||
* webble: hooked up disconnect event | ||
* webble: clear cached services on reconnect | ||
* hci-socket: Added upport 32-bit and 128-bit service data UUIDs ([@arekzelechowski](https://github.com/arekzelechowski)) | ||
* Update 'connectable' property upon discovery ([@dimitrisx](https://github.com/dimitrisx)) | ||
* macOS: Added support for High Sierra | ||
* webble: remove subscribe listeners on disconnect | ||
## Version 1.8.1 | ||
@@ -2,0 +12,0 @@ |
@@ -40,3 +40,3 @@ var async = require('async'); | ||
if (serviceData) { | ||
console.log(' Service Data = ' + serviceData); | ||
console.log(' Service Data = ' + JSON.stringify(serviceData, null, 2)); | ||
} | ||
@@ -43,0 +43,0 @@ |
@@ -193,3 +193,3 @@ var debug = require('debug')('gap'); | ||
case 0x16: // Service Data, there can be multiple occurences | ||
case 0x16: // 16-bit Service Data, there can be multiple occurences | ||
var serviceDataUuid = bytes.slice(0, 2).toString('hex').match(/.{1,2}/g).reverse().join(''); | ||
@@ -204,2 +204,22 @@ var serviceData = bytes.slice(2, bytes.length); | ||
case 0x20: // 32-bit Service Data, there can be multiple occurences | ||
var serviceData32Uuid = bytes.slice(0, 4).toString('hex').match(/.{1,2}/g).reverse().join(''); | ||
var serviceData32 = bytes.slice(4, bytes.length); | ||
advertisement.serviceData.push({ | ||
uuid: serviceData32Uuid, | ||
data: serviceData32 | ||
}); | ||
break; | ||
case 0x21: // 128-bit Service Data, there can be multiple occurences | ||
var serviceData128Uuid = bytes.slice(0, 16).toString('hex').match(/.{1,2}/g).reverse().join(''); | ||
var serviceData128 = bytes.slice(16, bytes.length); | ||
advertisement.serviceData.push({ | ||
uuid: serviceData128Uuid, | ||
data: serviceData128 | ||
}); | ||
break; | ||
case 0x1f: // List of 32 bit solicitation UUIDs | ||
@@ -206,0 +226,0 @@ for (j = 0; j < bytes.length; j += 4) { |
@@ -288,3 +288,3 @@ var debug = require('debug')('att'); | ||
buf.writeUInt8(ATT_OP_PREPARE_WRITE_REQ); | ||
buf.writeUInt8(ATT_OP_PREPARE_WRITE_REQ, 0); | ||
buf.writeUInt16LE(handle, 1); | ||
@@ -303,3 +303,3 @@ buf.writeUInt16LE(offset, 3); | ||
buf.writeUInt8(ATT_OP_EXECUTE_WRITE_REQ); | ||
buf.writeUInt8(ATT_OP_EXECUTE_WRITE_REQ, 0); | ||
buf.writeUInt8(cancelPreparedWrites ? 0 : 1, 1); | ||
@@ -306,0 +306,0 @@ |
@@ -8,4 +8,6 @@ var os = require('os'); | ||
module.exports = require('./mavericks'); | ||
} else if (osRelease < 17) { | ||
module.exports = require('./yosemite'); | ||
} else { | ||
module.exports = require('./yosemite'); | ||
module.exports = require('./highsierra'); | ||
} |
@@ -12,5 +12,6 @@ var debug = require('debug')('noble'); | ||
function Noble(bindings) { | ||
this.state = 'unknown'; | ||
this.initialized = false; | ||
this.address = 'unknown'; | ||
this._state = 'unknown'; | ||
this._bindings = bindings; | ||
@@ -51,3 +52,25 @@ this._peripherals = {}; | ||
this._bindings.init(); | ||
//lazy init bindings on first new listener, should be on stateChange | ||
this.on('newListener', function(event) { | ||
if (event === 'stateChange' && !this.initialized) { | ||
process.nextTick(function() { | ||
this._bindings.init(); | ||
this.initialized = true; | ||
}.bind(this)); | ||
} | ||
}.bind(this)); | ||
//or lazy init bindings if someone attempts to get state first | ||
Object.defineProperties(this, { | ||
state: { | ||
get: function () { | ||
if (!this.initialized) { | ||
this._bindings.init(); | ||
this.initialized = true; | ||
} | ||
return this._state; | ||
} | ||
} | ||
}); | ||
} | ||
@@ -60,3 +83,3 @@ | ||
this.state = state; | ||
this._state = state; | ||
@@ -73,21 +96,32 @@ this.emit('stateChange', state); | ||
Noble.prototype.startScanning = function(serviceUuids, allowDuplicates, callback) { | ||
if (this.state !== 'poweredOn') { | ||
var error = new Error('Could not start scanning, state is ' + this.state + ' (not poweredOn)'); | ||
var scan = function(state) { | ||
if (state !== 'poweredOn') { | ||
var error = new Error('Could not start scanning, state is ' + state + ' (not poweredOn)'); | ||
if (typeof callback === 'function') { | ||
callback(error); | ||
if (typeof callback === 'function') { | ||
callback(error); | ||
} else { | ||
throw error; | ||
} | ||
} else { | ||
throw error; | ||
if (callback) { | ||
this.once('scanStart', function(filterDuplicates) { | ||
callback(null, filterDuplicates); | ||
}); | ||
} | ||
this._discoveredPeripheralUUids = []; | ||
this._allowDuplicates = allowDuplicates; | ||
this._bindings.startScanning(serviceUuids, allowDuplicates); | ||
} | ||
} else { | ||
if (callback) { | ||
this.once('scanStart', function(filterDuplicates) { | ||
callback(null, filterDuplicates); | ||
}); | ||
} | ||
}; | ||
this._discoveredPeripheralUUids = []; | ||
this._allowDuplicates = allowDuplicates; | ||
this._bindings.startScanning(serviceUuids, allowDuplicates); | ||
//if bindings still not init, do it now | ||
if (!this.initialized) { | ||
this._bindings.init(); | ||
this.initialized = true; | ||
this.once('stateChange', scan.bind(this)); | ||
}else{ | ||
scan.call(this, this._state); | ||
} | ||
@@ -105,3 +139,5 @@ }; | ||
} | ||
this._bindings.stopScanning(); | ||
if(this._bindings && this.initialized){ | ||
this._bindings.stopScanning(); | ||
} | ||
}; | ||
@@ -132,2 +168,3 @@ | ||
peripheral.connectable = connectable; | ||
peripheral.rssi = rssi; | ||
@@ -134,0 +171,0 @@ } |
@@ -155,2 +155,4 @@ var util = require('util'); | ||
var peripheral = this._peripherals[deviceUuid]; | ||
//clear any cached services in case this is a reconnect | ||
peripheral.cachedServices = {}; | ||
@@ -161,2 +163,9 @@ // Attempts to connect to remote GATT Server. | ||
debug('peripheral connected', gattServer); | ||
var onDisconnected = function(event){ | ||
debug('disconnected', peripheral.uuid); | ||
self.emit('disconnect', peripheral.uuid); | ||
}; | ||
peripheral.device.addEventListener('gattserverdisconnected', onDisconnected, {once: true}); | ||
self.emit('connect', deviceUuid); | ||
@@ -213,3 +222,3 @@ }, function(err){ | ||
.then(function(characteristics) { | ||
var discoveredCharateristcs = characteristics.map(function(char){ | ||
var discoveredCharacteristics = characteristics.map(function(char){ | ||
var charInfo = {uuid: stripDashes(char.uuid), properties: []}; | ||
@@ -236,4 +245,4 @@ | ||
debug('discoverCharacteristics', deviceUuid, serviceUuid, discoveredCharateristcs); | ||
self.emit('characteristicsDiscover', deviceUuid, serviceUuid, discoveredCharateristcs); | ||
debug('discoverCharacteristics', deviceUuid, serviceUuid, discoveredCharacteristics); | ||
self.emit('characteristicsDiscover', deviceUuid, serviceUuid, discoveredCharacteristics); | ||
@@ -333,2 +342,9 @@ }); | ||
characteristic.addEventListener('characteristicvaluechanged', peripheral.notifcationListeners[serviceUuid + '__' + characteristicUuid]); | ||
var onDisconnected = function(){ | ||
characteristic.removeEventListener('characteristicvaluechanged', peripheral.notifcationListeners[serviceUuid + '__' + characteristicUuid]); | ||
delete peripheral.notifcationListeners[serviceUuid + '__' + characteristicUuid]; | ||
}; | ||
peripheral.device.addEventListener('gattserverdisconnected', onDisconnected, {once: true}); | ||
self.emit('notify', deviceUuid, serviceUuid, characteristicUuid, true); | ||
@@ -335,0 +351,0 @@ return characteristic; |
{ | ||
"author": "Sandeep Mistry <sandeep.mistry@gmail.com>", | ||
"author": "Sandeep Mistry", | ||
"maintainers": [ | ||
"Jacob Rosenthal", | ||
"Luis Montes" | ||
], | ||
"license": "MIT", | ||
"name": "noble", | ||
"description": "A Node.js BLE (Bluetooth Low Energy) central library.", | ||
"version": "1.8.1", | ||
"version": "1.9.0", | ||
"repository": { | ||
@@ -8,0 +12,0 @@ "type": "git", |
@@ -92,6 +92,8 @@ # ![noble](assets/noble-logo.png) | ||
Some BLE adapters like Sena UD-100 (Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)) cannot connect to a peripheral while they are scanning. You will get the following message when trying to connect : | ||
Some BLE adapters cannot connect to a peripheral while they are scanning (examples below). You will get the following messages when trying to connect : | ||
`Error: Command disallowed` | ||
Sena UD-100 (Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)) : `Error: Command disallowed` | ||
Intel Dual Band Wireless-AC 7260 (Intel Corporation Wireless 7260 (rev 73)) : `Error: Connection Rejected due to Limited Resources (0xd)` | ||
You need to stop scanning before trying to connect in order to solve this issue. | ||
@@ -168,3 +170,3 @@ | ||
```javascript | ||
peripheral.discoverAllServicesAndCharacteristics([callback(error, services, characteristics)); | ||
peripheral.discoverAllServicesAndCharacteristics([callback(error, services, characteristics)]); | ||
``` | ||
@@ -395,2 +397,4 @@ | ||
**Note:** `isNotification` event parameter value MAY be `undefined` depending on platform support. The parameter is **deprecated** after version 1.8.1, and not supported when on macOS High Sierra and later. | ||
##### Write | ||
@@ -397,0 +401,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
367028
53
8020
587