-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBluez.js
33 lines (26 loc) · 857 Bytes
/
Bluez.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const events = require('events');
const debug = require('debug')('Bluez');
const bluezDBus = require('./BluezDBus');
const BluezAdapter = require('./BluezAdapter');
var bluez = new events.EventEmitter();
function interfaceAdded(path, objects) {
/* We're only interested in Adapters */
if (objects['org.bluez.Adapter1'] === undefined)
return;
debug('An adapter was added: ' + path);
var adapter = new BluezAdapter(path);
adapter.init((err) => {
if (err) {
debug('Failed initializing new adapter ' + path + ': ' + err);
return;
}
bluez.emit('adapter', adapter);
});
}
bluezDBus.getAllObjects(function(err, objects) {
if (err)
throw 'Failed getting all objects';
Object.keys(objects).forEach((key) => interfaceAdded(key, objects[key]));
});
bluezDBus.onInterfaces(interfaceAdded);
module.exports = bluez;