-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
executable file
·52 lines (40 loc) · 1.25 KB
/
server.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
'use strict';
// var apiai = require("../module/apiai");
var apiai = require("apiai");
var apiai = apiai("134aa955f4fb47b7a1c903efefd35604");
var express = require('express');
var app = express();
var fs = require('fs');
var server = require('http').createServer(app);
var io = require('socket.io')(server);
io.on('connection', function() {/* … */
});
//anonymous function
server.listen(8000, function() {
console.log('Server listening on port 8000!')
})
app.get('/', function(req, res) {
// res.sendfile(__dirname + '/osc_test0.txt');
var fileTxt = fs.readFileSync(__dirname + '/osc_test0.txt', "utf-8");
// {
// console.log(fileTxt);
var tempData = (fileTxt.split('\n'));
var stressValue = tempData[tempData.length - 2];
// console.log(typeof(stressValue));
var currentValue = JSON.parse(stressValue);
console.log(currentValue.stressed)
if (currentValue.stressed) {
var options = {
sessionId: '<UNIQE SESSION ID>'
};
var request = apiai.textRequest('stressed', options);
request.on('response', function(response) {
console.log(response);
});
request.on('error', function(error) {
console.log(error);
});
request.end();
}
// }
});