32 linhas
670 B
JavaScript
32 linhas
670 B
JavaScript
// Run this to receive a png image stream from your drone.
|
|
|
|
var arDrone = require('..');
|
|
var http = require('http');
|
|
|
|
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);
|
|
});
|
|
|
|
server.listen(8080, function() {
|
|
console.log('Serving latest png on port 8080 ...');
|
|
});
|
|
|