clients.lua

changeset 7
59655d6c45b3
parent 6
4e46ef3035ba
child 8
2e4c32c4fb6b
equal deleted inserted replaced
6:4e46ef3035ba 7:59655d6c45b3
105 function handle_active(event, path) 105 function handle_active(event, path)
106 mark_active(event.request); 106 mark_active(event.request);
107 return "OK"; 107 return "OK";
108 end 108 end
109 109
110 function handle_watchers(event)
111 local active, total = 0, 0;
112 for client in pairs(clients) do
113 total = total + 1;
114 if active_clients[client] then
115 active = active + 1;
116 end
117 end
118 mark_active(event.request);
119 return tostring(total);
120 end
121
110 events.add_handler("image-changed", function (event) 122 events.add_handler("image-changed", function (event)
111 log("debug", "New image"); 123 log("debug", "New image");
112 local chunk_data = table.concat({ 124 local chunk_data = table.concat({
113 "--BoundaryString", 125 "--BoundaryString",
114 "Content-Type: image/jpeg"; 126 "Content-Type: image/jpeg";
132 144
133 http_server.add_host("localhost"); 145 http_server.add_host("localhost");
134 http_server.set_default_host("localhost"); 146 http_server.set_default_host("localhost");
135 http_server.add_handler("GET localhost/*", handle_request); 147 http_server.add_handler("GET localhost/*", handle_request);
136 http_server.add_handler("GET localhost/active", handle_active); 148 http_server.add_handler("GET localhost/active", handle_active);
149 http_server.add_handler("GET localhost/watchers", handle_watchers);
137 http_server.listen_on(8006); 150 http_server.listen_on(8006);

mercurial