JiConOp2 (#9052)
* 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:
parent
9856add282
commit
f4c8310ea7
|
@ -114,6 +114,45 @@ local services_mt = {
|
||||||
end;
|
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 function handle_services(event)
|
||||||
local origin, stanza = event.origin, event.stanza;
|
local origin, stanza = event.origin, event.stanza;
|
||||||
local action = stanza.tags[1];
|
local action = stanza.tags[1];
|
||||||
|
@ -126,37 +165,9 @@ local function handle_services(event)
|
||||||
end
|
end
|
||||||
|
|
||||||
local reply = st.reply(stanza):tag("services", { xmlns = action.attr.xmlns });
|
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;
|
for _, srv in ipairs(get_services(action.attr.type, origin, stanza, reply)) do
|
||||||
if requested_type then
|
reply:tag("service", srv):up();
|
||||||
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();
|
|
||||||
end
|
end
|
||||||
|
|
||||||
origin.send(reply);
|
origin.send(reply);
|
||||||
|
|
|
@ -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);
|
Loading…
Reference in New Issue