replaced code in app.js
Esse commit está contido em:
+4
-1
@@ -1 +1,4 @@
|
||||
very (very) basic in-browser monitoring via websockets
|
||||
remote-control and monitoring for your nodecopter
|
||||
====
|
||||
|
||||
note: the code is a complete mess and will eventually be reworked and documented.
|
||||
|
||||
+1
-77
@@ -1,80 +1,4 @@
|
||||
var express = require('express'),
|
||||
http = require('http'),
|
||||
path = require('path');
|
||||
|
||||
var app = express(),
|
||||
srv = http.createServer(app),
|
||||
io = require('socket.io').listen(srv);
|
||||
|
||||
app.configure(function(){
|
||||
app.set('port', process.env.PORT || 3001);
|
||||
app.use(express.favicon());
|
||||
app.use(app.router);
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
});
|
||||
|
||||
var arDrone = require('ar-drone'),
|
||||
client = arDrone.createClient();
|
||||
|
||||
client.config('general:navdata_demo', 'TRUE');
|
||||
|
||||
io.set('log level', 0);
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
console.log('socket.io connected');
|
||||
|
||||
socket.on("move", function (cmd) {
|
||||
if(!client[cmd.action]) { return; }
|
||||
|
||||
console.log('move', cmd);
|
||||
client[cmd.action](cmd.speed);
|
||||
});
|
||||
|
||||
socket.on("animate", function (cmd) {
|
||||
if(!client[cmd.action]) { return; }
|
||||
|
||||
console.log('animate', cmd);
|
||||
client[cmd.action](cmd.duration);
|
||||
});
|
||||
|
||||
socket.on("drone", function (cmd) {
|
||||
if(!client[cmd.action]) { return; }
|
||||
|
||||
console.log('drone command: ', cmd);
|
||||
client[cmd.action]();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
srv.listen(app.get('port'), function(){
|
||||
console.log("Express server listening on port " + app.get('port'));
|
||||
});
|
||||
|
||||
|
||||
|
||||
var fs = require("fs"),
|
||||
pngstream = client.createPngStream(),
|
||||
currentImg,
|
||||
i = 0;
|
||||
|
||||
client.on('navdata', function(data) {
|
||||
io.sockets.emit('navdata', data);
|
||||
});
|
||||
|
||||
var imageSendingPaused = false;
|
||||
pngstream.on("data", function (frame) {
|
||||
currentImg = frame;
|
||||
|
||||
if(imageSendingPaused) { return; }
|
||||
|
||||
io.sockets.emit("image", "/image/" + i++);
|
||||
|
||||
imageSendingPaused = true;
|
||||
setTimeout(function() {imageSendingPaused = false; }, 100);
|
||||
});
|
||||
|
||||
app.get('/image/:id', function (req, res) {
|
||||
res.writeHead(200, { "Content-Type": "image/png" });
|
||||
res.end(currentImg, "binary");
|
||||
});
|
||||
require('./index.js').init(client);
|
||||
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
exports.init = function(client) {
|
||||
var express = require('express'),
|
||||
http = require('http'),
|
||||
path = require('path');
|
||||
|
||||
var app = express(),
|
||||
srv = http.createServer(app),
|
||||
io = require('socket.io').listen(srv);
|
||||
|
||||
client.config('general:navdata_demo', 'TRUE');
|
||||
|
||||
app.configure(function(){
|
||||
app.set('port', process.env.PORT || 3001);
|
||||
app.use(app.router);
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
});
|
||||
|
||||
io.set('log level', 0);
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
console.log('socket.io connected');
|
||||
|
||||
// socket.on("move", function (cmd) {
|
||||
// if(!client[cmd.action]) { return; }
|
||||
//
|
||||
// console.log('move', cmd);
|
||||
// client[cmd.action](cmd.speed);
|
||||
// });
|
||||
//
|
||||
// socket.on("animate", function (cmd) {
|
||||
// if(!client[cmd.action]) { return; }
|
||||
//
|
||||
// console.log('animate', cmd);
|
||||
// client[cmd.action](cmd.duration);
|
||||
// });
|
||||
//
|
||||
// socket.on("drone", function (cmd) {
|
||||
// if(!client[cmd.action]) { return; }
|
||||
//
|
||||
// console.log('drone command: ', cmd);
|
||||
// client[cmd.action]();
|
||||
// });
|
||||
});
|
||||
|
||||
srv.listen(app.get('port'), function(){
|
||||
console.log("Express server listening on port " + app.get('port'));
|
||||
});
|
||||
|
||||
var fs = require("fs"),
|
||||
pngstream = client.createPngStream(),
|
||||
currentImg,
|
||||
i = 0;
|
||||
|
||||
client.on('navdata', function(data) {
|
||||
io.sockets.emit('navdata', data);
|
||||
});
|
||||
|
||||
var imageSendingPaused = false;
|
||||
pngstream.on("data", function (frame) {
|
||||
currentImg = frame;
|
||||
|
||||
if(imageSendingPaused) { return; }
|
||||
|
||||
io.sockets.emit("image", "/image/" + i++);
|
||||
|
||||
imageSendingPaused = true;
|
||||
setTimeout(function() {imageSendingPaused = false; }, 100);
|
||||
});
|
||||
|
||||
app.get('/image/:id', function (req, res) {
|
||||
res.writeHead(200, { "Content-Type": "image/png" });
|
||||
res.end(currentImg, "binary");
|
||||
});
|
||||
|
||||
return app;
|
||||
};
|
||||
+12
-6
@@ -1,12 +1,18 @@
|
||||
{
|
||||
"name": "nodecopter-monitor",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"description": "monitoring and remote-control for a nodecopter",
|
||||
"version": "0.1.0",
|
||||
"dependencies": {
|
||||
"express": "~3.0.0"
|
||||
"express": "~3.0.0",
|
||||
"ar-drone": "*"
|
||||
},
|
||||
"main": "app.js",
|
||||
"repository": "",
|
||||
"author": "",
|
||||
"author": { "name" : "usefulthink", "email": "m.schuhfuss@gmail.com" },
|
||||
"contributors": [
|
||||
{ "name": "zaubernerd" },
|
||||
{ "name": "line-o" }
|
||||
],
|
||||
"main": "index.js",
|
||||
"repository": "https://github.com/usefulthink/nodecopter-monitor.git",
|
||||
"homepage": "https://github.com/usefulthink/nodecopter-monitor",
|
||||
"license": "BSD"
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
|
||||
#visualizer {
|
||||
border: 1px solid black;
|
||||
|
||||
-webkit-perspective: 200px;
|
||||
width: 400px; height: 400px;
|
||||
}
|
||||
#rotor {
|
||||
position: absolute;
|
||||
top: 150px; left: 150px;
|
||||
width: 100px; height: 100px;
|
||||
|
||||
border: 1px solid red;
|
||||
border-radius: 5px;
|
||||
|
||||
background: rgba(255,0,0,0.3);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="visualizer">
|
||||
<button id="mouselock">Mouselock</button>
|
||||
<div id="rotor">(front)</div>
|
||||
</div>
|
||||
|
||||
<img id="cam" src="about:blank" />
|
||||
|
||||
<pre id="display"></pre>
|
||||
<script src="/socket.io/socket.io.js"></script>
|
||||
<script src="/js/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Referência em uma Nova Issue
Bloquear um usuário