Comparing version 1.1.0 to 1.2.0
@@ -0,1 +1,11 @@ | ||
## Version 1.2.0 | ||
* Use v0.4.0 of bluetooth-hci-socket | ||
* Ignore peripherals with only connectable flag on OS X 10.10 | ||
* Bindings no longer init themselves | ||
* Fix this._discoveredPeripheralUUids = []; variable not initalized in constructor ([@jacobrosenthal](https://github.com/jacobrosenthal)) | ||
* New ```peripheral.connectable``` property | ||
* Updates to Linux prerequisites in read me | ||
* Throw error if scanning is started when state is not powered on | ||
## Version 1.1.0 | ||
@@ -2,0 +12,0 @@ |
@@ -13,3 +13,5 @@ var noble = require('../index'); | ||
console.log('peripheral discovered (' + peripheral.id + | ||
' with address <' + peripheral.address + ', ' + peripheral.addressType + '>, RSSI ' + peripheral.rssi + ':'); | ||
' with address <' + peripheral.address + ', ' + peripheral.addressType + '>,' + | ||
' connectable ' + peripheral.connectable + ',' + | ||
' RSSI ' + peripheral.rssi + ':'); | ||
console.log('\thello my local name is:'); | ||
@@ -16,0 +18,0 @@ console.log('\t\t' + peripheral.advertisement.localName); |
@@ -26,2 +26,6 @@ var events = require('events'); | ||
NobleBindings.prototype.init = function() { | ||
// no-op | ||
}; | ||
NobleBindings.prototype._onConnection = function(ws) { | ||
@@ -56,2 +60,3 @@ var _this = this; | ||
var addressType = event.addressType; | ||
var connectable = event.connectable; | ||
var advertisement = event.advertisement; | ||
@@ -89,3 +94,3 @@ var rssi = event.rssi; | ||
this.emit('discover', peripheralUuid, address, addressType, advertisement, rssi); | ||
this.emit('discover', peripheralUuid, address, addressType, connectable, advertisement, rssi); | ||
} else if (type === 'connect') { | ||
@@ -323,4 +328,2 @@ this.emit('connect', peripheralUuid); | ||
var nobleBindings = new NobleBindings(); | ||
module.exports = nobleBindings; | ||
module.exports = new NobleBindings(); |
@@ -17,2 +17,3 @@ var debug = require('debug')('bindings'); | ||
this._addresseTypes = {}; | ||
this._connectable = {}; | ||
@@ -131,3 +132,3 @@ this._pendingConnection = false; | ||
NobleBindings.prototype.onDiscover = function(status, address, addressType, advertisement, rssi) { | ||
NobleBindings.prototype.onDiscover = function(status, address, addressType, connectable, advertisement, rssi) { | ||
if (this._scanServiceUuids === undefined) { | ||
@@ -154,4 +155,5 @@ return; | ||
this._addresseTypes[uuid] = addressType; | ||
this._connectable[uuid] = connectable; | ||
this.emit('discover', uuid, address, addressType, advertisement, rssi); | ||
this.emit('discover', uuid, address, addressType, connectable, advertisement, rssi); | ||
} | ||
@@ -474,6 +476,2 @@ }; | ||
var nobleBindings = new NobleBindings(); | ||
nobleBindings.init(); | ||
module.exports = nobleBindings; | ||
module.exports = new NobleBindings(); |
@@ -146,5 +146,8 @@ var debug = require('debug')('gap'); | ||
var connectable = (type === 0x04) ? this._discoveries[address].connectable : (type !== 0x03); | ||
this._discoveries[address] = { | ||
address: address, | ||
addressType: addressType, | ||
connectable: connectable, | ||
advertisement: advertisement, | ||
@@ -158,3 +161,3 @@ rssi: rssi, | ||
if (type === 0x04 || (discoveryCount > 1 && !hasScanResponse) || process.env.NOBLE_REPORT_ALL_HCI_EVENTS) { | ||
this.emit('discover', status, address, addressType, advertisement, rssi); | ||
this.emit('discover', status, address, addressType, connectable, advertisement, rssi); | ||
} | ||
@@ -161,0 +164,0 @@ }; |
@@ -15,2 +15,4 @@ var events = require('events'); | ||
var NobleBindings = function() { | ||
this._peripherals = {}; | ||
this._xpcConnection = new XpcConnection('com.apple.blued'); | ||
@@ -29,6 +31,2 @@ | ||
NobleBindings.prototype.setupXpcConnection = function() { | ||
this._xpcConnection.setup(); | ||
}; | ||
NobleBindings.prototype.sendXpcMessage = function(message) { | ||
@@ -40,4 +38,2 @@ this._xpcConnection.sendMessage(message); | ||
nobleBindings._peripherals = {}; | ||
nobleBindings.on('xpcEvent', function(event) { | ||
@@ -89,2 +85,4 @@ var kCBMsgId = event.kCBMsgId; | ||
nobleBindings.init = function() { | ||
this._xpcConnection.setup(); | ||
this.sendCBMsg(1, { | ||
@@ -180,3 +178,3 @@ kCBMsgArgAlert: 1, | ||
this.emit('discover', peripheralUuid, address, addressType, advertisement, rssi); | ||
this.emit('discover', peripheralUuid, address, addressType, undefined, advertisement, rssi); | ||
}.bind(this)); | ||
@@ -629,5 +627,2 @@ }.bind(this))(peripheralUuid, peripheralHandle, advertisement, rssi); | ||
nobleBindings.setupXpcConnection(); | ||
nobleBindings.init(); | ||
module.exports = nobleBindings; |
@@ -12,2 +12,4 @@ var events = require('events'); | ||
var NobleBindings = function() { | ||
this._peripherals = {}; | ||
this._xpcConnection = new XpcConnection('com.apple.blued'); | ||
@@ -26,6 +28,2 @@ | ||
NobleBindings.prototype.setupXpcConnection = function() { | ||
this._xpcConnection.setup(); | ||
}; | ||
NobleBindings.prototype.sendXpcMessage = function(message) { | ||
@@ -37,4 +35,2 @@ this._xpcConnection.sendMessage(message); | ||
nobleBindings._peripherals = {}; | ||
nobleBindings.on('xpcEvent', function(event) { | ||
@@ -62,2 +58,4 @@ var kCBMsgId = event.kCBMsgId; | ||
nobleBindings.init = function() { | ||
this._xpcConnection.setup(); | ||
this.sendCBMsg(1, { | ||
@@ -160,3 +158,3 @@ kCBMsgArgName: 'node-' + (new Date()).getTime(), | ||
this.emit('discover', deviceUuid, address, addressType, advertisement, rssi); | ||
this.emit('discover', deviceUuid, address, addressType, undefined, advertisement, rssi); | ||
}.bind(this)); | ||
@@ -599,5 +597,2 @@ }.bind(this))(deviceUuid, advertisement, rssi); | ||
nobleBindings.setupXpcConnection(); | ||
nobleBindings.init(); | ||
module.exports = nobleBindings; |
@@ -15,2 +15,4 @@ var events = require('events'); | ||
var NobleBindings = function() { | ||
this._peripherals = {}; | ||
this._xpcConnection = new XpcConnection('com.apple.blued'); | ||
@@ -22,10 +24,9 @@ this._xpcConnection.on('error', function(message) {this.emit('xpcError', message);}.bind(this)); | ||
util.inherits(NobleBindings, events.EventEmitter); | ||
NobleBindings.prototype.setupXpcConnection = function() {this._xpcConnection.setup();}; | ||
NobleBindings.prototype.sendXpcMessage = function(message) {this._xpcConnection.sendMessage(message);}; | ||
NobleBindings.prototype.sendXpcMessage = function(message) { | ||
this._xpcConnection.sendMessage(message); | ||
}; | ||
var nobleBindings = new NobleBindings(); | ||
nobleBindings._peripherals = {}; | ||
// General xpc message handling | ||
@@ -58,2 +59,4 @@ nobleBindings.on('xpcEvent', function(event) { | ||
nobleBindings.init = function() { | ||
this._xpcConnection.setup(); | ||
this.sendCBMsg(1, { | ||
@@ -122,3 +125,5 @@ kCBMsgArgName: 'node-' + (new Date()).getTime(), | ||
nobleBindings.on('kCBMsgId37', function(args) { | ||
if (Object.keys(args.kCBMsgArgAdvertisementData).length === 0) { | ||
if (Object.keys(args.kCBMsgArgAdvertisementData).length === 0 || | ||
(args.kCBMsgArgAdvertisementData.kCBAdvDataIsConnectable !== undefined && | ||
Object.keys(args.kCBMsgArgAdvertisementData).length === 1)) { | ||
return; | ||
@@ -135,2 +140,3 @@ } | ||
}; | ||
var connectable = args.kCBMsgArgAdvertisementData.kCBAdvDataIsConnectable ? true : false; | ||
var rssi = args.kCBMsgArgRssi; | ||
@@ -168,2 +174,3 @@ var i; | ||
this._peripherals[deviceUuid].uuid = uuid; | ||
this._peripherals[deviceUuid].connectable = connectable; | ||
this._peripherals[deviceUuid].advertisement = advertisement; | ||
@@ -180,3 +187,3 @@ this._peripherals[deviceUuid].rssi = rssi; | ||
this.emit('discover', deviceUuid, address, addressType, advertisement, rssi); | ||
this.emit('discover', deviceUuid, address, addressType, connectable, advertisement, rssi); | ||
}.bind(this)); | ||
@@ -854,4 +861,2 @@ }.bind(this))(deviceUuid, advertisement, rssi); | ||
// Exports | ||
nobleBindings.setupXpcConnection(); | ||
nobleBindings.init(); | ||
module.exports = nobleBindings; |
@@ -36,2 +36,3 @@ var debug = require('debug')('noble'); | ||
this._descriptors = {}; | ||
this._discoveredPeripheralUUids = []; | ||
@@ -64,2 +65,4 @@ this._bindings.on('stateChange', this.onStateChange.bind(this)); | ||
}.bind(this)); | ||
this._bindings.init(); | ||
} | ||
@@ -84,3 +87,3 @@ | ||
} else { | ||
this.emit('warning', error.message); | ||
throw error; | ||
} | ||
@@ -116,7 +119,7 @@ } else { | ||
Noble.prototype.onDiscover = function(uuid, address, addressType, advertisement, rssi) { | ||
Noble.prototype.onDiscover = function(uuid, address, addressType, connectable, advertisement, rssi) { | ||
var peripheral = this._peripherals[uuid]; | ||
if (!peripheral) { | ||
peripheral = new Peripheral(this, uuid, address, addressType, advertisement, rssi); | ||
peripheral = new Peripheral(this, uuid, address, addressType, connectable, advertisement, rssi); | ||
@@ -123,0 +126,0 @@ this._peripherals[uuid] = peripheral; |
@@ -7,3 +7,3 @@ /*jshint loopfunc: true */ | ||
function Peripheral(noble, id, address, addressType, advertisement, rssi) { | ||
function Peripheral(noble, id, address, addressType, connectable, advertisement, rssi) { | ||
this._noble = noble; | ||
@@ -15,2 +15,3 @@ | ||
this.addressType = addressType; | ||
this.connectable = connectable; | ||
this.advertisement = advertisement; | ||
@@ -28,2 +29,4 @@ this.rssi = rssi; | ||
address: this.address, | ||
addressType: this.addressType, | ||
connectable: this.connectable, | ||
advertisement: this.advertisement, | ||
@@ -30,0 +33,0 @@ rssi: this.rssi, |
@@ -33,2 +33,6 @@ var events = require('events'); | ||
NobleBindings.prototype.init = function() { | ||
// no-op | ||
}; | ||
NobleBindings.prototype._onOpen = function() { | ||
@@ -49,2 +53,3 @@ console.log('on -> open'); | ||
var addressType = event.addressType; | ||
var connectable = event.connectable; | ||
var advertisement = event.advertisement; | ||
@@ -83,3 +88,3 @@ var rssi = event.rssi; | ||
this.emit('discover', peripheralUuid, address, addressType, advertisement, rssi); | ||
this.emit('discover', peripheralUuid, address, addressType, connectable, advertisement, rssi); | ||
} else if (type === 'connect') { | ||
@@ -312,4 +317,2 @@ this.emit('connect', peripheralUuid); | ||
var nobleBindings = new NobleBindings(); | ||
module.exports = nobleBindings; | ||
module.exports = new NobleBindings(); |
@@ -6,3 +6,3 @@ { | ||
"description": "A Node.js BLE (Bluetooth Low Energy) central library.", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"repository": { | ||
@@ -35,5 +35,5 @@ "type": "git", | ||
"optionalDependencies": { | ||
"bluetooth-hci-socket": "~0.3.1", | ||
"bluetooth-hci-socket": "~0.4.0", | ||
"bplist-parser": "0.0.6", | ||
"xpc-connection": "~0.1.3" | ||
"xpc-connection": "~0.1.4" | ||
}, | ||
@@ -40,0 +40,0 @@ "devDependencies": { |
@@ -17,3 +17,3 @@ # noble | ||
### Linux (Ubuntu) | ||
### Linux | ||
@@ -26,5 +26,9 @@ * Kernel version 3.6 or above | ||
```sh | ||
sudo apt-get install bluetooth bluez-utils libbluetooth-dev | ||
sudo apt-get install bluetooth bluez-utils libbluetooth-dev libudev-dev | ||
``` | ||
Make sure ```node``` is on your path, if it's not, some options: | ||
* symlink ```nodejs``` to ```node```: ```sudo ln -s /usr/bin/nodejs /usr/bin/node``` | ||
* [install Node.js using the NodeSource package](https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions) | ||
#### Fedora / Other-RPM based | ||
@@ -238,2 +242,3 @@ | ||
addressType: "<BT address type>", // Bluetooth Address type (public, random), or 'unknown' if not known | ||
connectable: <connectable>, // true or false, or undefined if not known | ||
advertisement: { | ||
@@ -240,0 +245,0 @@ localName: "<name>", |
@@ -11,2 +11,3 @@ var should = require('should'); | ||
var mockAddressType = 'mock-address-type'; | ||
var mockConnectable = 'mock-connectable'; | ||
var mockAdvertisement = 'mock-advertisement'; | ||
@@ -29,3 +30,3 @@ var mockRssi = 'mock-rssi'; | ||
peripheral = new Peripheral(mockNoble, mockId, mockAddress, mockAddressType, mockAdvertisement, mockRssi); | ||
peripheral = new Peripheral(mockNoble, mockId, mockAddress, mockAddressType, mockConnectable, mockAdvertisement, mockRssi); | ||
}); | ||
@@ -49,2 +50,6 @@ | ||
it('should have connectable', function() { | ||
peripheral.connectable.should.equal(mockConnectable); | ||
}); | ||
it('should have advertisement', function() { | ||
@@ -59,4 +64,4 @@ peripheral.advertisement.should.equal(mockAdvertisement); | ||
describe('toString', function() { | ||
it('should be id, address, name, type, state', function() { | ||
peripheral.toString().should.equal('{"id":"mock-id","address":"mock-address","advertisement":"mock-advertisement","rssi":"mock-rssi","state":"disconnected"}'); | ||
it('should be id, address, address type, connectable, advertisement, rssi, state', function() { | ||
peripheral.toString().should.equal('{"id":"mock-id","address":"mock-address","addressType":"mock-address-type","connectable":"mock-connectable","advertisement":"mock-advertisement","rssi":"mock-rssi","state":"disconnected"}'); | ||
}); | ||
@@ -63,0 +68,0 @@ }); |
@@ -79,3 +79,3 @@ /* jshint loopfunc: true */ | ||
var command = JSON.parse(message); | ||
var action = command.action; | ||
@@ -220,3 +220,3 @@ var peripheralUuid = command.peripheralUuid; | ||
}; | ||
var characteristicsDiscover = function(characteristics) { | ||
@@ -238,3 +238,3 @@ var service = this; | ||
}; | ||
var write = function() { | ||
@@ -250,3 +250,3 @@ var characteristic = this; | ||
}; | ||
var broadcast = function(state) { | ||
@@ -263,3 +263,3 @@ var characteristic = this; | ||
}; | ||
var notify = function(state) { | ||
@@ -276,3 +276,3 @@ var characteristic = this; | ||
}; | ||
var descriptorsDiscover = function(descriptors) { | ||
@@ -295,3 +295,3 @@ var characteristic = this; | ||
}; | ||
var valueWrite = function(data) { | ||
@@ -382,3 +382,3 @@ var descriptor = this; | ||
}); | ||
peripheral.on('handleNotify', function(handle, data) { | ||
@@ -398,2 +398,3 @@ sendEvent({ | ||
addressType: peripheral.addressType, | ||
connectable: peripheral.connectable, | ||
advertisement: { | ||
@@ -400,0 +401,0 @@ localName: peripheral.advertisement.localName, |
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
273995
6526
426