-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock-scout.js
51 lines (38 loc) · 1.06 KB
/
mock-scout.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const config = require('./config');
const Scout = require(process.lynxari.scout);
const Mock = require('./mock');
module.exports = class MockScout extends Scout {
constructor(opts) {
super();
if (typeof opts !== 'undefined') {
// copy all config defined in the server
for (const key in opts) {
if (typeof opts[key] !== 'undefined') {
config[key] = opts[key];
}
}
}
if (config.name === undefined) { config.name = "MOCK" }
this.name = config.name;
this.mock = new Mock(config);
}
init(next) {
const query = this.server.where({name: this.name});
const self = this;
this.server.find(query, function(err, results) {
if (!err) {
if (results[0]) {
self.provision(results[0], self.mock);
self.server.info('Provisioned known device ' + self.name);
} else {
self.discover(self.mock);
self.server.info('Discovered new device ' + self.name);
}
}
else {
self.server.error(err);
}
});
next();
}
}