Last active
April 29, 2016 04:16
-
-
Save paulwakeford/442f4c9de7888da43379 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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