-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathapp.js
More file actions
118 lines (103 loc) · 2.42 KB
/
app.js
File metadata and controls
118 lines (103 loc) · 2.42 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//
// lirc_web
// v0.0.2
// Alex Bain <[email protected]>
//
// Set this to true if you'd like to emulate a list of remotes for development
var DEVELOPER_MODE = false;
//
// Requirements
//
var express = require('express'),
lirc_node = require('lirc_node'),
consolidate = require('consolidate'),
swig = require('swig');
var app = module.exports = express();
//
// Precompile templates
//
var JST = {
index: swig.compileFile(__dirname + '/templates/index.swig')
};
//
// lic_node initialization
//
lirc_node.init();
//
// Overwrite the remotes to be a default set if DEVELOPER_MODE is true
//
if (DEVELOPER_MODE) {
lirc_node.remotes = {
'Yamaha': [
'power',
'vaux',
'hdmi1',
'volup',
'voldown'
],
'SonyTV': [
'power',
'volumeup',
'volumedown',
'channelup',
'channeldown'
],
Microsoft_Xbox360: [
'OpenClose',
'XboxFancyButton',
'OnOff',
'Stop',
'Pause',
'Rewind',
'FastForward',
'Prev',
'Next',
'Play',
'Display',
'Title',
'DVD_Menu',
'Back',
'Info',
'UpArrow',
'LeftArrow',
'RightArrow',
'DownArrow',
'OK',
'Y',
'X',
'A',
'B',
]
};
}
//
// App configuration
//
app.engine('.html', consolidate.swig);
app.configure(function() {
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.compress());
app.use('/css', express.static(__dirname + '/css'));
app.use('/images', express.static(__dirname + '/images'));
app.use('/js', express.static(__dirname + '/js'));
});
//
// Routes
//
// Web UI endpoint
app.get('/', function(req, res) {
console.log("Viewed index");
res.send(JST['index'].render({
remotes: lirc_node.remotes
}));
});
// API endpoint
app.post('/remotes/:remote/:command', function(req, res) {
lirc_node.irsend.send_once(req.params.remote, req.params.command, function() {});
console.log("Sending " + req.params.command + " to " + req.params.remote);
res.send(200);
});
// Listen on port 3000
app.listen(3000);
console.log("Open Source Universal Remote UI + API has started on port 3000.");