forked from alexbain/lirc_web
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
135 lines (116 loc) · 2.68 KB
/
app.js
File metadata and controls
135 lines (116 loc) · 2.68 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//
// lirc_web
// v0.0.6
// Alex Bain <alex@alexba.in>
//
// 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
//
if (!DEVELOPER_MODE) {
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',
'DTV/CBL'
],
'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.use(express.logger());
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.compress());
app.use(express.static(__dirname + '/static'));
});
//
// Routes
//
// Web UI endpoint
app.get('/', function(req, res) {
res.send(JST['index'].render({
remotes: lirc_node.remotes
}));
});
// Get all remotes (JSON API)
app.get('/remotes.json', function(req, res) {
res.json(lirc_node.remotes);
});
// Get all commands for a remote (JSON API)
app.get('/remotes/:remote.json', function(req, res) {
if (lirc_node.remotes[req.params.remote]) {
res.json(lirc_node.remotes[req.params.remote]);
} else {
res.send(404);
}
});
// API endpoint
app.post('/remotes/:remote/:command', function(req, res) {
lirc_node.irsend.send_once(req.params.remote, req.params.command, function() {});
res.setHeader('Cache-Control', 'no-cache');
res.send(200);
});
// Listen on port 3000
app.listen(3000);
console.log("Open Source Universal Remote UI + API has started on port 3000.");