forked from tchekoto/SumoControl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
58 lines (46 loc) · 1.55 KB
/
index.js
File metadata and controls
58 lines (46 loc) · 1.55 KB
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
var app = require('express')();
var express = require('express');
var http = require('http').Server(app);
var io = require('socket.io')(http);
var myDroneandler = require('./lib/droneHandler.js');
var open = require('open');
var myDrone = new myDroneandler();
var path = __dirname + '/public/';
app.use('/js', express.static(__dirname + '/public/js'));
app.use('/css', express.static(__dirname + '/public/css'));
app.use('/img', express.static(__dirname + '/public/img'));
app.use('/fonts', express.static(__dirname + '/public/fonts'));
var PORT = 3000;
function Main() {
app.get("/", function (req, res) {
res.sendFile(path + "index.html");
});
app.get("/video/*", function (req, res) {
myDrone.serveDroneVideo(req, res);
});
http.listen(PORT, function () {
console.log('HTTP Server listening on *:' + PORT);
open('http://127.0.0.1:' + PORT);
});
io.on('connection', function (socket) {
console.log("User connected");
socket.on('keyup', function (data) {
myDrone.stopMoving(data);
});
socket.on('keydown', function (data) {
myDrone.move(data);
});
socket.on('action', function (data) {
myDrone.action(data);
});
var oldBatValue = -1;
setInterval(function () {
var newBatValue = myDrone.getBattery();
if (newBatValue !== oldBatValue) {
oldBatValue = newBatValue;
socket.emit('battery', newBatValue);
}
}, 1000);
});
}
Main();