# HG changeset patch # User Matthew Wild # Date 1451907859 0 # Node ID 59655d6c45b3659a7086dba43148493a1113a0a6 # Parent 4e46ef3035bafbf5f4547a0dff48005ba5e053ed client.lua: Add /watchers endpoint to get the current number of people watching the feed diff -r 4e46ef3035ba -r 59655d6c45b3 clients.lua --- 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);