Skip to content

Instantly share code, notes, and snippets.

@paulwakeford
Last active April 29, 2016 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulwakeford/442f4c9de7888da43379 to your computer and use it in GitHub Desktop.
Save paulwakeford/442f4c9de7888da43379 to your computer and use it in GitHub Desktop.
var http = require('http');
exports.handler = function (event, context) {
var options = {};
options.host = "YOUR_HOST";
options.port = "YOUR_PORT";
options.path = '/YOUR_ROOM/state';
console.log("doing initial GET " + options.host + ":" + options.port + options.path );
http.get(options, function(res) {
console.log("in first get block");
var body = '';
res.setEncoding("utf8");
res.on('data', function (chunk) {
body += chunk;
});
res.on('end', function () {
var obj = JSON.parse(body);
console.log("finishing parsing " + obj.zoneState );
if (obj.zoneState != 'PLAYING') {
console.log("starting triplej");
options.path = '/preset/triple%20j';
} else {
console.log("pausing");
options.path = '/pauseall'; }
console.log("doing final GET " + options.host + ":" + options.port + options.path );
http.get(options);
console.log("GET complete " + options.host + ":" + options.port + options.path );
context.succeed();
}).on('error', function (e) {
console.log("Got error: ", e);
context.fail(e);
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment