From 4f188f06b3ff5e403b58d9dba6e282b422321f03 Mon Sep 17 00:00:00 2001 From: Sebastian Wiedenroth Date: Sun, 2 Oct 2016 18:27:20 +0200 Subject: [PATCH] json api to read current universe state --- dmx-web.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/dmx-web.js b/dmx-web.js index d7c29ea..cbe6db5 100755 --- a/dmx-web.js +++ b/dmx-web.js @@ -53,7 +53,20 @@ function DMXWeb() { }) app.get('/', function(req, res) { - res.sendfile(__dirname + '/index.html') + res.sendfile(__dirname + '/index.html') + }) + + app.get('/state/:universe', function(req, res) { + if(!(req.params.universe in dmx.universes)) { + res.status(404).json({"error": "universe not found"}) + return + } + var universe = dmx.universes[req.params.universe] + var u = {} + for(var i = 0; i < 256; i++) { + u[i] = universe.get(i) + } + res.json({"state": u}) }) app.post('/animation/:universe', function(req, res) { @@ -101,7 +114,7 @@ function DMXWeb() { }) dmx.on('update', function(universe, update) { - socket.emit('update', universe, update) + socket.emit('update', universe, update) }) }) }