Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.