Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

JiConOp2 (#9052)

Дамян Минковf4c8310ea7a3
diff --git a/resources/prosody-plugins/mod_external_services.lua b/resources/prosody-plugins/mod_external_services.lua
index e18e7c3eae..56182c8ed8 100644
--- a/resources/prosody-plugins/mod_external_services.lua
+++ b/resources/prosody-plugins/mod_external_services.lua
@@ -114,22 +114,10 @@ local services_mt = {
end;
}
-local function handle_services(event)
- local origin, stanza = event.origin, event.stanza;
- local action = stanza.tags[1];
-
- local user_bare = jid.bare(stanza.attr.from);
- local user_host = jid.host(user_bare);
- if not ((access:empty() and origin.type == "c2s") or access:contains(user_bare) or access:contains(user_host)) then
- origin.send(st.error_reply(stanza, "auth", "forbidden"));
- return true;
- end
-
- local reply = st.reply(stanza):tag("services", { xmlns = action.attr.xmlns });
+function get_services(requested_type, origin, stanza, reply)
local extras = module:get_host_items("external_service");
local services = ( configured_services + extras ) / prepare;
- local requested_type = action.attr.type;
if requested_type then
services:filter(function(item)
return item.type == requested_type;
@@ -138,25 +126,48 @@ local function handle_services(event)
setmetatable(services, services_mt);
- module:fire_event("external_service/services", {
+ if origin and stanza and reply then
+ module:fire_event("external_service/services", {
origin = origin;
stanza = stanza;
reply = reply;
requested_type = requested_type;
services = services;
});
+ end
+ local res_services = {};
for _, srv in ipairs(services) do
- reply:tag("service", {
- type = srv.type;
- transport = srv.transport;
- host = srv.host;
- port = srv.port and string.format("%d", srv.port) or nil;
- username = srv.username;
- password = srv.password;
- expires = srv.expires and dt.datetime(srv.expires) or nil;
- restricted = srv.restricted and "1" or nil;
- }):up();
+ table.insert(res_services, {
+ type = srv.type;
+ transport = srv.transport;
+ host = srv.host;
+ port = srv.port and string.format("%d", srv.port) or nil;
+ username = srv.username;
+ password = srv.password;
+ expires = srv.expires and dt.datetime(srv.expires) or nil;
+ restricted = srv.restricted and "1" or nil;
+ })
+ end
+
+ return res_services;
+end
+
+local function handle_services(event)
+ local origin, stanza = event.origin, event.stanza;
+ local action = stanza.tags[1];
+
+ local user_bare = jid.bare(stanza.attr.from);
+ local user_host = jid.host(user_bare);
+ if not ((access:empty() and origin.type == "c2s") or access:contains(user_bare) or access:contains(user_host)) then
+ origin.send(st.error_reply(stanza, "auth", "forbidden"));
+ return true;
+ end
+
+ local reply = st.reply(stanza):tag("services", { xmlns = action.attr.xmlns });
+
+ for _, srv in ipairs(get_services(action.attr.type, origin, stanza, reply)) do
+ reply:tag("service", srv):up();
end
origin.send(reply);
diff --git a/resources/prosody-plugins/mod_jiconop.lua b/resources/prosody-plugins/mod_jiconop.lua
new file mode 100644
index 0000000000..19cc4ff92b
--- /dev/null
+++ b/resources/prosody-plugins/mod_jiconop.lua
@@ -0,0 +1,47 @@
+local st = require "util.stanza";
+local get_services = module:depends("external_services").get_services;
+
+-- Jitsi Connection Optimization
+-- gathers needed information and pushes it with a message to clients
+-- this way we skip 4 request responses during every client setup
+
+local shard_name_config = module:get_option_string('shard_name');
+if shard_name_config then
+ module:add_identity("server", "shard", shard_name_config);
+end
+
+-- this is after xmpp-bind, the moment a client has resource and can be contacted
+module:hook("resource-bind", function (event)
+ local session = event.session;
+
+ -- disco info data / all identity and features
+ local query = st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#info" });
+ local done = {};
+ for _,identity in ipairs(module:get_host_items("identity")) do
+ local identity_s = identity.category.."\0"..identity.type;
+ if not done[identity_s] then
+ query:tag("identity", identity):up();
+ done[identity_s] = true;
+ end
+ end
+
+ -- check whether room has lobby enabled and display name is required for those trying to join
+ local lobby_muc_component_config = module:get_option_string('lobby_muc');
+ module:context(lobby_muc_component_config):fire_event('host-disco-info-node',
+ {origin = session; reply = query; node = 'lobbyrooms';});
+
+ local stanza = st.message({
+ type = 'service-info';
+ from = module.host;
+ to = session.full_jid; });
+ stanza:add_child(query):up();
+
+ --- get turnservers and credentials
+ local services = get_services();
+ stanza:tag("services");
+ for _, srv in ipairs(services) do
+ stanza:tag("service", srv):up();
+ end
+
+ session.send(stanza);
+end);