* feat: Exposes a hook to mod_external_services data.

The hook can be used to get turn servers and credentials from another module.

* feat: JiConOp2 pushes a message with some info to clients.

* feat: JiConOp adds config for shard name feature.

* squash: Changes message type to service-info.

* squash: Drops the event in external_services.
This commit is contained in:
Дамян Минков 2021-04-22 12:54:34 -05:00 committed by GitHub
parent 9856add282
commit f4c8310ea7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 88 additions and 30 deletions

View File

@ -114,6 +114,45 @@ local services_mt = {
end;
}
function get_services(requested_type, origin, stanza, reply)
local extras = module:get_host_items("external_service");
local services = ( configured_services + extras ) / prepare;
if requested_type then
services:filter(function(item)
return item.type == requested_type;
end);
end
setmetatable(services, services_mt);
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
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];
@ -126,37 +165,9 @@ local function handle_services(event)
end
local reply = st.reply(stanza):tag("services", { xmlns = action.attr.xmlns });
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;
end);
end
setmetatable(services, services_mt);
module:fire_event("external_service/services", {
origin = origin;
stanza = stanza;
reply = reply;
requested_type = requested_type;
services = 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();
for _, srv in ipairs(get_services(action.attr.type, origin, stanza, reply)) do
reply:tag("service", srv):up();
end
origin.send(reply);

View File

@ -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);