Mon, 04 Jan 2016 11:44:19 +0000
client.lua: Add /watchers endpoint to get the current number of people watching the feed
clients.lua | file | annotate | diff | comparison | revisions |
--- a/clients.lua Mon Jan 04 11:35:43 2016 +0000 +++ b/clients.lua Mon Jan 04 11:44:19 2016 +0000 @@ -107,6 +107,18 @@ return "OK"; end +function handle_watchers(event) + local active, total = 0, 0; + for client in pairs(clients) do + total = total + 1; + if active_clients[client] then + active = active + 1; + end + end + mark_active(event.request); + return tostring(total); +end + events.add_handler("image-changed", function (event) log("debug", "New image"); local chunk_data = table.concat({ @@ -134,4 +146,5 @@ http_server.set_default_host("localhost"); http_server.add_handler("GET localhost/*", handle_request); http_server.add_handler("GET localhost/active", handle_active); +http_server.add_handler("GET localhost/watchers", handle_watchers); http_server.listen_on(8006);