This repository has been archived by the owner on May 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
80 lines (63 loc) · 1.88 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
Copyright (C) 2015 CLMS
This file is part of Safepost.
Authors:
Antonis Migiakis <a.migiakis@clmsuk.com>
*/
var SCCU = require('./lib/sccu.js');
var http = require('http');
var restify = require('restify');
var fs = require('fs');
var nconf = require('nconf');
var channels = [ "ls" , "dtube", "sensors", "devEvents", "transportEvents", "imgRecog", "alarm" ];
// First consider commandline arguments and environment variables, respectively and then file.
nconf.argv()
.env()
.file({ file: 'config.json' });
// Provide default values for settings not provided above.
nconf.defaults({
'channels': [ "ls", "dtube", "sensors", "devEvents", "transportEvents", "imgRecog", "alarm" ],
'host' : 'dev.zappdev.com',
'basepath' : 'EUProjects_SafepostDemo_1_0_kvasileiou_Knockout/sccu'
});
sccu = new SCCU(nconf.get("aeonid"), nconf.get("channels"), nconf.get("host"), nconf.get("basepath"));
sccu.start();
// HTTP Server
var port = process.env.PORT || 3000;
var server = restify.createServer();
server.get('/channels' , function(req, res, next){
res.send(sccu.activechannels);
next();
});
server.get('/channels/stop' , function(req, res, next){
sccu.stop();
res.send("Done!");
next();
});
server.get('/channels/start' , function(req, res, next){
sccu.start();
res.send("Started!");
next();
});
server.listen(port, function() {
console.log('%s listening at %s', server.name, server.url);
});
var readLine = require ("readline");
if (process.platform === "win32" && !process.env.IISNODE_VERSION){
var rl = readLine.createInterface ({
input: process.stdin,
output: process.stdout
});
rl.on ("SIGINT", function (){
process.emit ("SIGINT");
});
}
process.on('SIGTERM', function(){
console.log("Stopping...");
sccu.stop();
});
process.on ("SIGINT", function(){
//graceful shutdown
sccu.stop();
process.exit ();
});