Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
fixes async_handler_wrapper (#5001)
Aaron van Meerten710307725b13
diff --git a/resources/prosody-plugins/mod_muc_poltergeist.lua b/resources/prosody-plugins/mod_muc_poltergeist.luaindex fe03dc5bdb..4d6538bd87 100644--- a/resources/prosody-plugins/mod_muc_poltergeist.lua+++ b/resources/prosody-plugins/mod_muc_poltergeist.lua@@ -11,7 +11,7 @@ if not have_async thenreturn;end-local wrap_async_run = module:require "util".wrap_async_run;+local async_handler_wrapper = module:require "util".async_handler_wrapper;-- Optionslocal poltergeist_component@@ -175,7 +175,7 @@ module:hook(-- @return GET response, containing a json with response detailsfunction handle_create_poltergeist (event)if (not event.request.url.query) then- return 400;+ return { status_code = 400; };endlocal params = parse(event.request.url.query);@@ -189,7 +189,7 @@ function handle_create_poltergeist (event)local session = {};if not verify_token(params["token"], room_name, group, session) then- return 403;+ return { status_code = 403; };end-- If the provided room conference doesn't exist then we@@ -197,7 +197,7 @@ function handle_create_poltergeist (event)local room = get_room(room_name, group);if (not room) thenlog("error", "no room found %s", room_name);- return 404;+ return { status_code = 404; };end-- If the poltergiest is already in the conference then it will@@ -210,7 +210,7 @@ function handle_create_poltergeist (event)username,room_name);- return 202;+ return { status_code = 202; };endlocal context = {@@ -228,7 +228,7 @@ function handle_create_poltergeist (event)endpoltergeist.add_to_muc(room, user_id, name, avatar, context, status, resources)- return 200;+ return { status_code = 200; };end--- Handles request for updating poltergeists status@@ -236,7 +236,7 @@ end-- @return GET response, containing a json with response detailsfunction handle_update_poltergeist (event)if (not event.request.url.query) then- return 400;+ return { status_code = 400; };endlocal params = parse(event.request.url.query);@@ -252,18 +252,18 @@ function handle_update_poltergeist (event)endif not verify_token(params["token"], room_name, group, {}) then- return 403;+ return { status_code = 403; };endlocal room = get_room(room_name, group);if (not room) thenlog("error", "no room found %s", room_name);- return 404;+ return { status_code = 404; };endlocal username = poltergeist.get_username(room, user_id);if (not username) then- return 404;+ return { status_code = 404; };endlocal call_details = {@@ -273,11 +273,11 @@ function handle_update_poltergeist (event)local nick = poltergeist.create_nick(username);if (not poltergeist.occupies(room, nick)) then- return 404;+ return { status_code = 404; };endpoltergeist.update(room, nick, status, call_details);- return 200;+ return { status_code = 200; };end--- Handles remove poltergeists@@ -285,7 +285,7 @@ end-- @return GET response, containing a json with response detailsfunction handle_remove_poltergeist (event)if (not event.request.url.query) then- return 400;+ return { status_code = 400; };endlocal params = parse(event.request.url.query);@@ -294,27 +294,27 @@ function handle_remove_poltergeist (event)local group = params["group"];if not verify_token(params["token"], room_name, group, {}) then- return 403;+ return { status_code = 403; };endlocal room = get_room(room_name, group);if (not room) thenlog("error", "no room found %s", room_name);- return 404;+ return { status_code = 404; };endlocal username = poltergeist.get_username(room, user_id);if (not username) then- return 404;+ return { status_code = 404; };endlocal nick = poltergeist.create_nick(username);if (not poltergeist.occupies(room, nick)) then- return 404;+ return { status_code = 404; };endpoltergeist.remove(room, nick, false);- return 200;+ return { status_code = 200; };endlog("info", "Loading poltergeist service");@@ -323,8 +323,8 @@ module:provides("http", {default_path = "/";name = "poltergeist";route = {- ["GET /poltergeist/create"] = function (event) return wrap_async_run(event,handle_create_poltergeist) end;- ["GET /poltergeist/update"] = function (event) return wrap_async_run(event,handle_update_poltergeist) end;- ["GET /poltergeist/remove"] = function (event) return wrap_async_run(event,handle_remove_poltergeist) end;+ ["GET /poltergeist/create"] = function (event) return async_handler_wrapper(event,handle_create_poltergeist) end;+ ["GET /poltergeist/update"] = function (event) return async_handler_wrapper(event,handle_update_poltergeist) end;+ ["GET /poltergeist/remove"] = function (event) return async_handler_wrapper(event,handle_remove_poltergeist) end;};});diff --git a/resources/prosody-plugins/mod_muc_size.lua b/resources/prosody-plugins/mod_muc_size.luaindex abe7269bc8..f87f827eea 100644--- a/resources/prosody-plugins/mod_muc_size.lua+++ b/resources/prosody-plugins/mod_muc_size.lua@@ -14,7 +14,7 @@ if not have_async thenreturn;end-local wrap_async_run = module:require "util".wrap_async_run;+local async_handler_wrapper = module:require "util".async_handler_wrapper;local tostring = tostring;local neturl = require "net.url";@@ -79,7 +79,7 @@ end-- tha value is without counting the focus.function handle_get_room_size(event)if (not event.request.url.query) then- return 400;+ return { status_code = 400; };endlocal params = parse(event.request.url.query);@@ -95,7 +95,7 @@ function handle_get_room_size(event)endif not verify_token(params["token"], room_address) then- return 403;+ return { status_code = 403; };endlocal room = get_room_from_jid(room_address);@@ -112,14 +112,14 @@ function handle_get_room_size(event)"there are %s occupants in room", tostring(participant_count));elselog("debug", "no such room exists");- return 404;+ return { status_code = 404; };endif participant_count > 1 thenparticipant_count = participant_count - 1;end- return [[{"participants":]]..participant_count..[[}]];+ return { status_code = 200; body = [[{"participants":]]..participant_count..[[}]] };end--- Handles request for retrieving the room participants details@@ -127,7 +127,7 @@ end-- @return GET response, containing a json with participants detailsfunction handle_get_room (event)if (not event.request.url.query) then- return 400;+ return { status_code = 400; };endlocal params = parse(event.request.url.query);@@ -142,7 +142,7 @@ function handle_get_room (event)endif not verify_token(params["token"], room_address) then- return 403;+ return { status_code = 403; };endlocal room = get_room_from_jid(room_address);@@ -173,14 +173,14 @@ function handle_get_room (event)"there are %s occupants in room", tostring(participant_count));elselog("debug", "no such room exists");- return 404;+ return { status_code = 404; };endif participant_count > 1 thenparticipant_count = participant_count - 1;end- return json.encode(occupants_json);+ return { status_code = 200; body = json.encode(occupants_json); };end;function module.load()@@ -188,9 +188,9 @@ function module.load()module:provides("http", {default_path = "/";route = {- ["GET room-size"] = function (event) return wrap_async_run(event,handle_get_room_size) end;+ ["GET room-size"] = function (event) return async_handler_wrapper(event,handle_get_room_size) end;["GET sessions"] = function () return tostring(it.count(it.keys(prosody.full_sessions))); end;- ["GET room"] = function (event) return wrap_async_run(event,handle_get_room) end;+ ["GET room"] = function (event) return async_handler_wrapper(event,handle_get_room) end;};});enddiff --git a/resources/prosody-plugins/util.lib.lua b/resources/prosody-plugins/util.lib.luaindex 70e00a45ac..086cc7ff9b 100644--- a/resources/prosody-plugins/util.lib.lua+++ b/resources/prosody-plugins/util.lib.lua@@ -59,36 +59,14 @@ function get_room_from_jid(room_jid)endend--function wrap_async_run(event,handler)- local have_async = pcall(require, "util.async");+function async_handler_wrapper(event, handler)if not have_async thenmodule:log("error", "requires a version of Prosody with util.async");return nil;endlocal runner = async.runner;- -- Grab a local response so that we can send the http response when- -- the handler is done.- local response = event.response;- local async_func = runner(function (event)- 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.- return true;-end--function async_handler_wrapper(event, handler)+-- Grab a local response so that we can send the http response when-- the handler is done.local response = event.response;@@ -197,7 +175,6 @@ endreturn {is_feature_allowed = is_feature_allowed;get_room_from_jid = get_room_from_jid;- wrap_async_run = wrap_async_run;async_handler_wrapper = async_handler_wrapper;room_jid_match_rewrite = room_jid_match_rewrite;update_presence_identity = update_presence_identity;