index.js
1.29 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict';
const UPnP = require('./UPnP')
, nupnp = require('./nupnp')
, bridgeValidator = require('./bridge-validation')
;
module.exports.upnpSearch = function (timeout) {
const upnp = new UPnP();
return upnp.search(timeout).then(loadDescriptions);
};
module.exports.nupnpSearch = function () {
return nupnp.nupnp().then(loadConfigurations);
};
module.exports.description = function (ipAddress) {
if (! ipAddress) {
return Promise.resolve(null);
}
return loadDescriptions([{internalipaddress: ipAddress}])
.then(results => {
if (results) {
return results[0];
}
return null;
});
};
function loadDescriptions(results) {
const promises = results.map(result => {
return bridgeValidator.getBridgeDescription(result);
});
return Promise.all(promises);
}
function loadConfigurations(results) {
const promises = results.map(result => {
return bridgeValidator
.getBridgeConfig(result)
.catch(err => {
return {
error: {
message: err.message,
description: `Failed to connect and load configuration from the bridge at ip address ${result.ipaddress}`,
ipaddress: result.internalipaddress,
id: result.id,
}
};
});
});
return Promise.all(promises);
}