1
0
mirror of http://github.com/AhabHyde/JSComando synced 2025-01-09 22:04:20 +01:00

Aggiunto TeleComando

This commit is contained in:
Ahab 2017-08-14 22:30:04 +02:00
parent 2076fb6ed5
commit fa8e741183
17 changed files with 228 additions and 0 deletions

2
Avvia.bat Normal file
View File

@ -0,0 +1,2 @@
@echo off
node serverApp.js

17
package.json Normal file
View File

@ -0,0 +1,17 @@
{
"name": "telecomando",
"version": "1.0.0",
"description": "Telecomando per comandare video di Youtube, Netflix o VLC",
"main": "serverApp.js",
"dependencies": {
"express": "^4.15.4",
"os": "^0.1.1",
"robotjs": "^0.4.7"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Ahab Hyde",
"license": "MIT"
}

16
public/css/materialize.min.css vendored Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

50
public/index.html Normal file
View File

@ -0,0 +1,50 @@
<!DOCTYPE html>
<html>
<head>
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/>
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<script src="js/clientApp.js"></script>
<div id="app">
<!-- Barra in alto -->
<nav>
<div class="nav-wrapper">
<a class="brand-logo center">TeleComando</a>
</div>
</nav>
<!-- Pulsanti -->
<div class="row center" style="margin-top:5em">
<a class="btn-floating btn-large waves-effect waves-light blue" onclick="fullscreen()"><i class="material-icons">fullscreen</i></a>
</div>
<div class="row center" style="margin-top:3em">
<a class="btn-floating btn-large waves-effect waves-light blue" onclick="audiodown()"><i class="material-icons">volume_down</i></a>
<a class="btn-floating btn-large waves-effect waves-light blue" onclick="mute()"><i class="material-icons">volume_off</i></a>
<a class="btn-floating btn-large waves-effect waves-light blue" onclick="audioup()"><i class="material-icons">volume_up</i></a>
</div>
<div class="row center" style="margin-top:3em">
<a class="btn-floating btn-large waves-effect waves-light blue" onclick="back()"><i class="material-icons">arrow_back</i></a>
<a class="btn-floating btn-large waves-effect waves-light blue" onclick="forward()"><i class="material-icons">arrow_forward</i></a>
</div>
<div class="row center" style="margin-top:3em">
<a class="btn-floating btn-large waves-effect waves-light blue" onclick="playPause()"><i class="material-icons">pause</i></a>
</div>
</div> <!-- Viene chiuso il div dell'app -->
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="js/materialize.min.js"></script>
</body>
</html>

49
public/js/clientApp.js Normal file
View File

@ -0,0 +1,49 @@
function playPause() {
$.ajax('/playpause/', {
method: 'GET',
success: null
})
console.log("playPause")
}
function fullscreen() {
$.ajax('/fullscreen/', {
method: 'GET'
})
console.log("fullscreen")
}
function back() {
$.ajax('/back/', {
method: 'GET'
})
console.log("back")
}
function forward() {
$.ajax('/forward/', {
method: 'GET'
})
console.log("forward")
}
function audiodown() {
$.ajax('/audiodown/', {
method: 'GET'
})
console.log("audiodown")
}
function mute() {
$.ajax('/mute/', {
method: 'GET'
})
console.log("mute")
}
function audioup() {
$.ajax('/audioup/', {
method: 'GET'
})
console.log("audioup")
}

6
public/js/materialize.min.js vendored Normal file

File diff suppressed because one or more lines are too long

88
serverApp.js Normal file
View File

@ -0,0 +1,88 @@
var robot = require("robotjs"); //used to simulate key taps
var express = require('express'); //used to accept http requests
var app = express();
//Used to show hosting IPs:
var os = require('os');
var interfaces = os.networkInterfaces();
var addresses = [];
// http://expressjs.com/en/starter/static-files.html
// Needed to make static files in the public folder (like css) visible to clients
app.use(express.static('public'));
//Tap spacebar for pause and resume:
app.get("/playpause/", function (request, response) {
robot.keyTap("space")
// OK to client
response.writeHead(200);
response.end("");
})
//Tap F for fullscreen:
app.get("/fullscreen/", function (request, response) {
robot.keyTap("f")
// OK to client
response.writeHead(200);
response.end("");
})
//Tap left arrow for rewind:
app.get("/back/", function (request, response) {
robot.keyTap("left")
// OK to client
response.writeHead(200);
response.end("");
})
//Tap right arrow for fast forward:
app.get("/forward/", function (request, response) {
robot.keyTap("right")
// OK to client
response.writeHead(200);
response.end("");
})
//Tap volume down:
app.get("/audiodown/", function (request, response) {
robot.keyTap("audio_vol_down")
// OK to client
response.writeHead(200);
response.end("");
})
//Tap mute audio:
app.get("/mute/", function (request, response) {
robot.keyTap("audio_mute")
// OK to client
response.writeHead(200);
response.end("");
})
//Tap volume up:
app.get("/audioup/", function (request, response) {
robot.keyTap("audio_vol_up")
// OK to client
response.writeHead(200);
response.end("");
})
// http://expressjs.com/en/starter/basic-routing.html
// Send HTML page to generic get requests
app.get("/", function (request, response) {
response.sendFile('/public/index.html');
});
app.listen(80)
console.log("Avviato sulla porta 80 degli indirizzi: ")
for (var k in interfaces) {
for (var k2 in interfaces[k]) {
var address = interfaces[k][k2];
if (address.family === 'IPv4' && !address.internal) {
addresses.push(address.address);
}
}
}
console.log(addresses);