-
Notifications
You must be signed in to change notification settings - Fork 7
/
server.js
executable file
·73 lines (73 loc) · 2.54 KB
/
server.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
(function() {
var app, currentImg, drone, faye, imageSendingPaused, path, server, socket;
var express = require("express");
var PythonShell = require('python-shell');
var app = express()
faye = require("faye");
path = require("path");
var options = {
args: ['identify']
};
var drone = require("ar-drone").createClient({
ip: '[Insert Your Drones IP]',
frameRate: 10
});
drone.config('general:navdata_demo', 'TRUE');
app = express();
app.configure(function() {
app.set('port', process.env.PORT || 3001);
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
return app.use("/components", express.static(path.join(__dirname, 'components')));
});
server = require("http").createServer(app);
new faye.NodeAdapter({
mount: '/faye',
timeout: 45
}).attach(server);
socket = new faye.Client("http://localhost:" + (app.get("port")) + "/faye");
socket.subscribe("/drone/move", function(cmd) {
var _name;
console.log("move", cmd);
return typeof drone[_name = cmd.action] === "function" ? drone[_name](cmd.speed) : void 0;
});
socket.subscribe("/drone/animate", function(cmd) {
console.log('animate', cmd);
return drone.animate(cmd.action, cmd.duration);
});
app.get('/automate', function(req, res) {
console.log('automate was called');
var returnvalues = [drone.takeoff()];
return returnvalues;
});
socket.subscribe("/drone/drone", function(cmd) {
var _name;
console.log('drone command: ', cmd);
return typeof drone[_name = cmd.action] === "function" ? drone[_name]() : void 0;
});
server.listen(app.get("port"), function() {
return console.log("Webserver is open on port " + app.get("port"));
});
currentImg = null;
drone.on('navdata', function(data) {
return socket.publish("/drone/navdata", data);
});
imageSendingPaused = false;
drone.createPngStream().on("data", function(frame) {
currentImg = frame;
if (imageSendingPaused) {
return;
}
socket.publish("/drone/image", "/image/" + (01));
imageSendingPaused = true;
return setTimeout((function() {
return imageSendingPaused = false;
}), 100);
});
app.get("/image/:id", function(req, res) {
res.writeHead(200, {
"Content-Type": "image/png"
});
return res.end(currentImg, "binary");
});
}).call(this);