-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebServer.js
More file actions
94 lines (78 loc) · 1.94 KB
/
WebServer.js
File metadata and controls
94 lines (78 loc) · 1.94 KB
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
var express = require("express"),
app = express(),
table = require("./networktable"),
config = require("./config")
vision = require("./TargetTracker.js");
app.set("view engine", "ejs");
app.use("/static", express.static("static"));
app.get("/", function(req,res)
{
res.redirect("/vision");
});
app.get("/vision", function(req,res)
{
res.render("vision", {config: config});
});
app.get("/networktable", function(req,res)
{
console.log(table.getEntries());
res.render("networktable", {table: table.getEntries()});
});
app.get("/setProperty/:key/:value", function(req,res)
{
config[req.param("key")] = req.param("value");
res.send("set");
});
app.get("/getProperty/:key", function(req,res)
{
try {
res.send(config[req.param("key")]);
} catch (e) {
res.send("Key not found");
}
});
app.get("/target.mjpeg", function(req,res)
{
res.writeHead(200, {
'Content-Type': 'multipart/x-mixed-replace; boundary=first',
'Cache-Control': 'no-cache',
'Connection': 'close',
'Pragma': 'no-cache'
});
function send(res)
{
var sendImage = setInterval(function(res)
{
vision.processImage(function(img, hasTarget)
{
var currentImage = hasTarget.toBuffer();
res.write("--first\r\n");
res.write("Content-type: image/jpeg\r\n");
res.write("Content-Length: "+currentImage.length+"\r\n");
res.write("\r\n");
res.write(currentImage, "binary");
res.write("\r\n");
});
}, config.frameRequestRate, res);
res.connection.on('close', function() { clearInterval(sendImage); });
}
send(res);
}
});
app.get("/target.jpg", function(req,res)
{
vision.processImage(function(img, hasTarget)
{
res.writeHead(200, {
'Cache-Control': 'no-cache',
'Connection': 'close',
'Pragma': 'no-cache'
});
res.write(currentFrame.toBuffer(), "binary");
res.end();
});
});
//exports.init = function()
//{
app.listen(8080);
//};