-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
109 lines (91 loc) · 2.41 KB
/
index.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var express = require('express');
var app = express();
app.use(express.static('public'));
app.use(express.static('files'));
var options = {
mode: 'text',
pythonOptions: ['-u'],
};
var PythonShell = require('python-shell');
var pyshell = new PythonShell("main2.py", options);
// PythonShell.run('main2.py', options, function (err, results) {
// if (err) throw err;
// // results is an array consisting of messages collected during execution
// console.log("'results: %j', results");
// console.log("Executed!")
// });
var path = require('path');
var mime = require('mime');
var fs = require('fs');
var bodyParser = require('body-parser')
app.use( bodyParser.json() );
app.use(bodyParser.urlencoded({ extended: true }));
var highlight = false;
var download = false;
var gettingdownload = false;
var downloadname = "";
app.get('/', function (req, res) {
setTimeout(function() {}, 2000);
res.sendfile('index.html');
});
app.post('/startrecording', function(req, res)
{
console.log("starting to record");
var streamname = req.body.name;
recording = true;
console.log(streamname)
pyshell.send(streamname)
res.end();
})
app.get('/update', function(req, res)
{
payload = {};
if(highlight == false)
{
payload = {status: "recording"};
}
else if(highlight == true && download == false && gettingdownload == false)
{
payload = {status: "highlight_start"};
}
else if(highlight == true && download == true && gettingdownload == false)
{
payload = {status: "highlight_end"}
}
else if(highlight == true && download == true && gettingdownload == true)
{
payload = {status: "download"};
highlight = false;
download = false;
gettingdownload = false;
}
res.json(payload);
});
app.get('/download', function(req, res)
{
var file = __dirname + '/' + downloadname;
res.download(file);
});
pyshell.on('message', function (message) {
// received a message sent from the Python script (a simple "print" statement)
console.log("In message which was: " + message);
if(message == "~~~Highlight start set!~~~")
{
console.log("Highlight start")
highlight = true;
}
else if(message == "~~~Highlight end~~~")
{
console.log("Highlight end")
download = true;
}
else if(message.substring(0, 9) == "highlight")
{
console.log("Highlight download")
gettingdownload = true;
downloadname = message;
}
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
})