Fixes the room size api which returns string result back to client.

This commit is contained in:
damencho 2018-07-06 16:05:29 -05:00 committed by Дамян Минков
parent 20444adbc9
commit d12afc5c07
2 changed files with 14 additions and 17 deletions

View File

@ -105,19 +105,14 @@ function handle_get_room_size(event)
"there are %s occupants in room", tostring(participant_count));
else
log("debug", "no such room exists");
return 404;
end
if participant_count > 1 then
participant_count = participant_count - 1;
end
local GET_response = {
headers = {
content_type = "application/json";
};
body = [[{"participants":]]..participant_count..[[}]];
};
return GET_response;
return [[{"participants":]]..participant_count..[[}]];
end
--- Handles request for retrieving the room participants details
@ -171,19 +166,14 @@ function handle_get_room (event)
"there are %s occupants in room", tostring(participant_count));
else
log("debug", "no such room exists");
return 404;
end
if participant_count > 1 then
participant_count = participant_count - 1;
end
local GET_response = {
headers = {
content_type = "application/json";
};
body = json.encode(occupants_json);
};
return GET_response;
return json.encode(occupants_json);
end;
function module.load()

View File

@ -66,9 +66,16 @@ function wrap_async_run(event,handler)
-- the handler is done.
local response = event.response;
local async_func = runner(function (event)
response.status_code = handler(event);
-- Send the response to the waiting http client.
response:send();
local result = handler(event);
-- if it is a number, it is a status code, else it is the body
-- result we will return
if (tonumber(result) ~= nil) then
response.status_code = result;
else
response.body = result;
end;
-- Send the response to the waiting http client.
response:send();
end)
async_func:run(event)
-- return true to keep the client http connection open.