-
Notifications
You must be signed in to change notification settings - Fork 2
/
indexRecording.js
58 lines (40 loc) · 1.3 KB
/
indexRecording.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
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var fs = require('fs');
console.log("A1");
//app.use("/styles", express.static(__dirname + '/styles'));
app.get('/', function(req, res){
console.log("A2");
res.sendFile(__dirname + '/indexRecording.html');
});
var fname = "";
console.log("A3");
io.on('connection', function(socket){
console.log("Socket ok");
socket.on('createfile', function (data) {
fname = "recordings/data_"+ data.usr + "_" + data.action +".txt";
// Create the file
fs.writeFile( fname, "# Recordings of " + data.usr + " making movement " + data.action + " at " + new Date(Date.now()).toLocaleString() + " " +String.fromCharCode(10),
function(err) {
if(err){
console.log("Write to file failed");
return console.log(err);
}
}
);
});
socket.on('append', function(data){
console.log('append to file: ' + data);
// Write to file
fs.appendFile(fname, data, function(err) {
if (err) {
console.log(err);
return console.log(err);
}
});
});
});
http.listen(3000, function(){
console.log('listening you on *:3000');
});