Comparing version 0.2.8 to 0.3.0
@@ -17,5 +17,9 @@ var noble = require('../index'); | ||
console.log('\t\t' + JSON.stringify(peripheral.advertisement.serviceUuids)); | ||
if (peripheral.advertisement.serviceData) { | ||
var serviceData = peripheral.advertisement.serviceData; | ||
if (serviceData && serviceData.length) { | ||
console.log('\there is my service data:'); | ||
console.log('\t\t' + JSON.stringify(peripheral.advertisement.serviceData.toString('hex'))); | ||
for (var i in serviceData) { | ||
console.log('\t\t' + JSON.stringify(serviceData[i].uuid) + ': ' + JSON.stringify(serviceData[i].data.toString('hex'))); | ||
} | ||
} | ||
@@ -22,0 +26,0 @@ if (peripheral.advertisement.manufacturerData) { |
@@ -72,8 +72,15 @@ var debug = require('debug')('hci-ble'); | ||
localName: undefined, | ||
serviceData: undefined, | ||
txPowerLevel: undefined, | ||
manufacturerData: undefined, | ||
serviceData: [], | ||
serviceUuids: [] | ||
}; | ||
var discoveryCount = previouslyDiscovered ? this._discoveries[address].count : 0; | ||
if (discoveryCount % 2 === 0) { | ||
// reset service data every second event | ||
advertisement.serviceData = []; | ||
} | ||
var i = 0; | ||
@@ -124,4 +131,10 @@ var j = 0; | ||
case 0x16: // Service Data | ||
advertisement.serviceData = bytes; | ||
case 0x16: // Service Data, there can be multiple occurences | ||
var serviceDataUuid = bytes.slice(0, 2).toString('hex').match(/.{1,2}/g).reverse().join(''); | ||
var serviceData = bytes.slice(2, bytes.length); | ||
advertisement.serviceData.push({ | ||
uuid: serviceDataUuid, | ||
data: serviceData | ||
}); | ||
break; | ||
@@ -139,4 +152,2 @@ | ||
var discoveryCount = previouslyDiscovered ? this._discoveries[address].count : 0; | ||
this._discoveries[address] = { | ||
@@ -143,0 +154,0 @@ address: address, |
@@ -132,2 +132,3 @@ var debug = require('debug')('legacy-bindings'); | ||
manufacturerData: args.kCBMsgArgAdvertisementData.kCBAdvDataManufacturerData, | ||
serviceData: [], | ||
serviceUuids: [] | ||
@@ -146,9 +147,11 @@ }; | ||
if (serviceData) { | ||
var serviceDataString = ''; | ||
for (i = 0; i < serviceData.length; i += 2) { | ||
var serviceDataUuid = serviceData[i].toString('hex'); | ||
var data = serviceData[i + 1]; | ||
for (i = 0; i < serviceData.length; i++) { | ||
serviceDataString += serviceData[i].toString('hex'); | ||
advertisement.serviceData.push({ | ||
uuid: serviceDataUuid, | ||
data: data | ||
}); | ||
} | ||
advertisement.serviceData = new Buffer(serviceDataString, 'hex'); | ||
} | ||
@@ -155,0 +158,0 @@ |
@@ -111,2 +111,3 @@ var debug = require('debug')('mavericks-bindings'); | ||
manufacturerData: args.kCBMsgArgAdvertisementData.kCBAdvDataManufacturerData, | ||
serviceData: [], | ||
serviceUuids: [] | ||
@@ -125,9 +126,11 @@ }; | ||
if (serviceData) { | ||
var serviceDataString = ''; | ||
for (i = 0; i < serviceData.length; i += 2) { | ||
var serviceDataUuid = serviceData[i].toString('hex'); | ||
var data = serviceData[i + 1]; | ||
for (i = 0; i < serviceData.length; i++) { | ||
serviceDataString += serviceData[i].toString('hex'); | ||
advertisement.serviceData.push({ | ||
uuid: serviceDataUuid, | ||
data: data | ||
}); | ||
} | ||
advertisement.serviceData = new Buffer(serviceDataString, 'hex'); | ||
} | ||
@@ -134,0 +137,0 @@ |
@@ -16,3 +16,5 @@ var debug = require('debug')('noble'); | ||
if (platform === 'darwin') { | ||
if (process.env.NOBLE_DISTRIBUTED) { | ||
bindings = require('./distributed/bindings'); | ||
} else if (platform === 'darwin') { | ||
bindings = require('./mac/bindings'); | ||
@@ -134,2 +136,3 @@ } else if (platform === 'linux') { | ||
if (peripheral) { | ||
peripheral.state = 'connected'; | ||
peripheral.emit('connect', error); | ||
@@ -149,2 +152,3 @@ } else { | ||
if (peripheral) { | ||
peripheral.state = 'disconnected'; | ||
peripheral.emit('disconnect'); | ||
@@ -151,0 +155,0 @@ } else { |
@@ -14,2 +14,3 @@ /*jshint loopfunc: true */ | ||
this.services = null; | ||
this.state = 'disconnected'; | ||
} | ||
@@ -23,3 +24,4 @@ | ||
advertisement: this.advertisement, | ||
rssi: this.rssi | ||
rssi: this.rssi, | ||
state: this.state | ||
}); | ||
@@ -34,4 +36,9 @@ }; | ||
} | ||
this._noble.connect(this.uuid); | ||
if (this.state === 'connected') { | ||
this.emit('connect', new Error('Peripheral already connected')); | ||
} else { | ||
this.state = 'connecting'; | ||
this._noble.connect(this.uuid); | ||
} | ||
}; | ||
@@ -45,3 +52,3 @@ | ||
} | ||
this.state = 'disconnecting'; | ||
this._noble.disconnect(this.uuid); | ||
@@ -48,0 +55,0 @@ }; |
@@ -5,3 +5,3 @@ { | ||
"description": "A node.js BLE (Bluetooth low energy) central library.", | ||
"version": "0.2.8", | ||
"version": "0.3.0", | ||
"repository": { | ||
@@ -30,3 +30,4 @@ "type": "git", | ||
"dependencies": { | ||
"debug": "~0.7.2" | ||
"debug": "~0.7.2", | ||
"ws": "~0.4.31" | ||
}, | ||
@@ -33,0 +34,0 @@ "devDependencies": { |
@@ -140,5 +140,12 @@ noble | ||
localName: "<name>", | ||
serviceData: <Buffer>, | ||
txPowerLevel: <int>, | ||
serviceUuids: ["<service UUID>", ...], | ||
manufacturerData: <Buffer>, | ||
serviceData: [ | ||
{ | ||
uuid: "<service UUID>" | ||
data: <Buffer> | ||
}, | ||
... | ||
] | ||
}, | ||
@@ -145,0 +152,0 @@ rssi: <rssi> |
@@ -46,4 +46,4 @@ var should = require('should'); | ||
describe('toString', function() { | ||
it('should be uuid, name, type', function() { | ||
peripheral.toString().should.equal('{"uuid":"mock-uuid","advertisement":"mock-advertisement","rssi":"mock-rssi"}'); | ||
it('should be uuid, name, type, state', function() { | ||
peripheral.toString().should.equal('{"uuid":"mock-uuid","advertisement":"mock-advertisement","rssi":"mock-rssi","state":"disconnected"}'); | ||
}); | ||
@@ -50,0 +50,0 @@ }); |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
194621
33
4216
326
2
1
+ Addedws@~0.4.31
+ Addedcommander@2.1.0(transitive)
+ Addednan@1.0.0(transitive)
+ Addedoptions@0.0.6(transitive)
+ Addedtinycolor@0.0.1(transitive)
+ Addedws@0.4.32(transitive)