Skip to content

Commit ea3975b

Browse files
committed
gatt - enable add / remove /removeAll services for attribute caching
1 parent ddf978a commit ea3975b

File tree

7 files changed

+390
-245
lines changed

7 files changed

+390
-245
lines changed

examples/pizza/peripheral.js

+12
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var PizzaService = require('./pizza-service');
2424
//
2525
var name = 'PizzaSquat';
2626
var pizzaService = new PizzaService(new pizza.Pizza());
27+
var pizzaService2 = new PizzaService(new pizza.Pizza());
2728

2829
//
2930
// Wait until the BLE radio powers on before attempting to advertise.
@@ -56,5 +57,16 @@ bleno.on('advertisingStart', function(err) {
5657
bleno.setServices([
5758
pizzaService
5859
]);
60+
61+
var flip = false;
62+
setInterval(function (){
63+
if(flip){
64+
bleno.removeService(pizzaService2);
65+
} else {
66+
bleno.addService(pizzaService2);
67+
}
68+
flip = !flip;
69+
}, 1500);
70+
5971
}
6072
});

lib/bleno.js

+8
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ Bleno.prototype.onAdvertisingStop = function() {
199199
this.emit('advertisingStop');
200200
};
201201

202+
Bleno.prototype.addService = function(service) {
203+
this._bindings.addService(service);
204+
};
205+
206+
Bleno.prototype.removeService = function(service) {
207+
this._bindings.removeService(service);
208+
};
209+
202210
Bleno.prototype.setServices = function(services, callback) {
203211
if (callback) {
204212
this.once('servicesSet', callback);

lib/hci-socket/bindings.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,17 @@ BlenoBindings.prototype.stopAdvertising = function() {
4848
this._gap.stopAdvertising();
4949
};
5050

51-
BlenoBindings.prototype.setServices = function(services) {
51+
BlenoBindings.prototype.addService = function(service) {
52+
this._gatt.addService(service);
53+
54+
this.emit('servicesChanged');
55+
};
56+
57+
BlenoBindings.prototype.removeService = function (service){
58+
this._gatt.removeService(service);
59+
}
60+
61+
BlenoBindings.prototype.setServices = function(services, deviceName) {
5262
this._gatt.setServices(services);
5363

5464
this.emit('servicesSet');

0 commit comments

Comments
 (0)