-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepl.js
46 lines (32 loc) · 932 Bytes
/
repl.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
var arDrone = require('ar-drone');
var http = require('http');
var download = require('download-file')
var url = "http://localhost:8080/"
var options = {
directory: "/Users/zamankhan/Desktop/data/",
filename: "me.png"
}
console.log('Connecting png stream ...');
var pngStream = arDrone.createClient().getPngStream();
var lastPng;
pngStream
.on('error', console.log)
.on('data', function (pngBuffer) {
lastPng = pngBuffer;
});
var server = http.createServer(function (req, res) {
if (!lastPng) {
res.writeHead(503);
res.end('Did not receive any png data yet.');
return;
}
res.writeHead(200, { 'Content-Type': 'image/png' });
res.end(lastPng);
download(url, options, function (err) {
if (err) throw err
console.log("oomf")
})
});
server.listen(8080, function () {
console.log('Serving latest png on port 8080 ...');
});