-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
55 lines (38 loc) · 1.01 KB
/
app.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
52
53
54
55
/*jslint node: true */
'use strict';
var server = require('./server');
var superagent = require('superagent');
var io = require('socket.io').listen(server);
var port = process.env.PORT || 9002;
server.listen(port);
var App = function () {
return this.init();
};
App.prototype.init = function () {
this.bathStatus = 'spark core endpoint';
return this.startLoop();
};
App.prototype.startLoop = function () {
setInterval(this.getResult.bind(this), 2000);
return this;
};
App.prototype.getResult = function () {
superagent
.get(this.bathStatus)
.on('error', function (err) {
io.emit('error', err);
})
.end(function (res) {
if(res.body.result === 0) {
io.emit('open');
return this;
}
if(res.body.result === 1) {
io.emit('close');
return this;
}
io.emit('error', res);
});
return this;
};
module.exports = new App();