Advertisement
FlyFar

png-stream.js

Mar 14th, 2023
1,653
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.68 KB | Cybersecurity | 0 0
  1. // Run this to receive a png image stream from your drone.
  2.  
  3. var arDrone = require('..');
  4. var http    = require('http');
  5.  
  6. console.log('Connecting png stream ...');
  7.  
  8. var pngStream = arDrone.createClient().getPngStream();
  9.  
  10. var lastPng;
  11. pngStream
  12.   .on('error', console.log)
  13.   .on('data', function(pngBuffer) {
  14.     lastPng = pngBuffer;
  15.   });
  16.  
  17. var server = http.createServer(function(req, res) {
  18.   if (!lastPng) {
  19.     res.writeHead(503);
  20.     res.end('Did not receive any png data yet.');
  21.     return;
  22.   }
  23.  
  24.   res.writeHead(200, {'Content-Type': 'image/png'});
  25.   res.end(lastPng);
  26. });
  27.  
  28. server.listen(8080, function() {
  29.   console.log('Serving latest png on port 8080 ...');
  30. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement