-
Notifications
You must be signed in to change notification settings - Fork 40
/
index.js
37 lines (31 loc) · 1.14 KB
/
index.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
var express = require('express')
, request = require('request')
, multer = require('multer');
var app = express();
var upload = multer({ dest: '/tmp/' });
app.post('/', upload.single('thumb'), function (req, res, next) {
var payload = JSON.parse(req.body.payload);
console.log('Got webhook for', payload.event);
// Apple TV.
if (payload.Player.uuid == process.env.PLAYER && payload.Metadata.type != 'track') {
var options = {
method: 'PUT',
json: true,
url: 'https://winkapi.quirky.com/light_bulbs/' + process.env.BULB,
headers: { 'Authorization': 'Bearer ' + process.env.BEARER }
};
if (payload.event == 'media.play' || payload.event == 'media.resume') {
// Turn light off.
console.log('Turning light off.');
options.body = { desired_state: { powered: false } };
request(options);
} else if (payload.event == 'media.pause' || payload.event == 'media.stop') {
// Turn light on.
console.log('Turning light on.');
options.body = { desired_state: { powered: true, brightness: 1.0 } };
request(options);
}
}
res.sendStatus(200);
});
app.listen(12000);