clients.lua

changeset 17
dd2a570367a9
parent 15
67858d731518
child 18
8050134f35b3
equal deleted inserted replaced
16:d35376a53644 17:dd2a570367a9
108 update_have_clients(); 108 update_have_clients();
109 end 109 end
110 110
111 function handle_active(event, path) 111 function handle_active(event, path)
112 mark_active(event.request); 112 mark_active(event.request);
113 event.response.headers.content_type = "text/plain";
113 return "OK"; 114 return "OK";
114 end 115 end
115 116
116 function handle_watchers(event) 117 function handle_watchers(event)
117 local active, total = 0, 0; 118 local active, total = 0, 0;
120 if active_clients[client] then 121 if active_clients[client] then
121 active = active + 1; 122 active = active + 1;
122 end 123 end
123 end 124 end
124 mark_active(event.request); 125 mark_active(event.request);
126 event.response.headers.content_type = "text/plain";
125 return tostring(total); 127 return tostring(total);
126 end 128 end
127 129
128 function handle_watcher_info(event) 130 function handle_watcher_info(event)
129 local watchers = {}; 131 local watchers = {};
135 age = math.floor(age_sec); 137 age = math.floor(age_sec);
136 sent = math.floor(bytes_tx/1024); 138 sent = math.floor(bytes_tx/1024);
137 }); 139 });
138 end 140 end
139 mark_active(event.request); 141 mark_active(event.request);
142 event.response.headers.content_type = "application/json";
140 return "[\n "..table.concat(watchers, ",\n ").."\n]"; 143 return "[\n "..table.concat(watchers, ",\n ").."\n]";
141 end 144 end
142 145
143 -- Called when a HTTP stream client closes 146 -- Called when a HTTP stream client closes
144 local function client_closed(request) 147 local function client_closed(request)

mercurial