-
Notifications
You must be signed in to change notification settings - Fork 2
/
node_helper.js
40 lines (33 loc) · 1.05 KB
/
node_helper.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
var NodeHelper = require('node_helper');
var request = require('request');
var process = require('child_process');
var express = require('express');
var app = express();
var body_parser = require('body-parser');
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
module.exports = NodeHelper.create({
start: function() {
console.log('Sonos helper starting...');
var self = this;
app.post('/', function(req, res) {
console.log('Sonos change posted');
self.sendSocketNotification('SONOS_DATA', req.body.data);
});
app.listen(4444, function() {
console.log('Webhook server listening...');
});
},
socketNotificationReceived: function(notification, url) {
if (notification == 'SONOS_UPDATE') {
var self = this;
request(url, function(error, response, body) {
if (error) {
console.error('Error: ' + error);
} else if (parseInt(response.statusCode) == 200) {
self.sendSocketNotification('SONOS_DATA', JSON.parse(body));
}
});
}
}
})