Skip to content

Commit

Permalink
gatt - enable add / remove /removeAll services for attribute caching
Browse files Browse the repository at this point in the history
  • Loading branch information
brycejacobs committed Sep 18, 2015
1 parent ddf978a commit ea3975b
Show file tree
Hide file tree
Showing 7 changed files with 390 additions and 245 deletions.
12 changes: 12 additions & 0 deletions examples/pizza/peripheral.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var PizzaService = require('./pizza-service');
//
var name = 'PizzaSquat';
var pizzaService = new PizzaService(new pizza.Pizza());
var pizzaService2 = new PizzaService(new pizza.Pizza());

//
// Wait until the BLE radio powers on before attempting to advertise.
Expand Down Expand Up @@ -56,5 +57,16 @@ bleno.on('advertisingStart', function(err) {
bleno.setServices([
pizzaService
]);

var flip = false;
setInterval(function (){
if(flip){
bleno.removeService(pizzaService2);
} else {
bleno.addService(pizzaService2);
}
flip = !flip;
}, 1500);

}
});
8 changes: 8 additions & 0 deletions lib/bleno.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ Bleno.prototype.onAdvertisingStop = function() {
this.emit('advertisingStop');
};

Bleno.prototype.addService = function(service) {
this._bindings.addService(service);
};

Bleno.prototype.removeService = function(service) {
this._bindings.removeService(service);
};

Bleno.prototype.setServices = function(services, callback) {
if (callback) {
this.once('servicesSet', callback);
Expand Down
12 changes: 11 additions & 1 deletion lib/hci-socket/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,17 @@ BlenoBindings.prototype.stopAdvertising = function() {
this._gap.stopAdvertising();
};

BlenoBindings.prototype.setServices = function(services) {
BlenoBindings.prototype.addService = function(service) {
this._gatt.addService(service);

this.emit('servicesChanged');
};

BlenoBindings.prototype.removeService = function (service){
this._gatt.removeService(service);
}

BlenoBindings.prototype.setServices = function(services, deviceName) {
this._gatt.setServices(services);

this.emit('servicesSet');
Expand Down
Loading

0 comments on commit ea3975b

Please sign in to comment.