-
Notifications
You must be signed in to change notification settings - Fork 0
/
tivo-network-remote.js
51 lines (43 loc) · 1.22 KB
/
tivo-network-remote.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
var express = require('express');
var net = require('net');
// Connect to TIVO box
var client = new net.Socket();
client.connect(31339, '192.168.0.159', function() {
console.log('Connected to Tivo');
});
client.on('close', function() {
console.log('Disconnected from Tivo');
});
client.on('data', function(data) {
console.log('Received: ' + data);
});
// Create Web Server
var app = express();
var favicon = require('serve-favicon');
var path = require('path');
app.use(favicon(__dirname + '/images/favicon.ico'));
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/index.html'));
});
app.get('/remote.png', function(req, res) {
res.sendFile(path.join(__dirname + '/images/virgin_tivo_remote.png'));
});
app.post('/ircode/:code', function (req, res) {
client.write('IRCODE ' + req.params.code + '\r\n');
res.end();
})
app.post('/teleport/:code', function (req, res) {
client.write('TELEPORT ' + req.params.code + '\r\n');
res.end();
})
var server = app.listen(10001, function () {
var port = server.address().port
console.log("Listening on port", port)
})
server.on('close', function() {
client.destroy();
})
// Trap Ctrl-C
//process.on('SIGINT', function() {
// server.close();
//});