Quellcode durchsuchen

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.
j8
Дамян Минков vor 4 Jahren
Ursprung
Commit
f4c8310ea7
Es ist kein Account mit der E-Mail-Adresse des Committers verbunden

+ 35
- 24
resources/prosody-plugins/mod_external_services.lua Datei anzeigen

@@ -114,22 +114,10 @@ local services_mt = {
114 114
 	end;
115 115
 }
116 116
 
117
-local function handle_services(event)
118
-	local origin, stanza = event.origin, event.stanza;
119
-	local action = stanza.tags[1];
120
-
121
-	local user_bare = jid.bare(stanza.attr.from);
122
-	local user_host = jid.host(user_bare);
123
-	if not ((access:empty() and origin.type == "c2s") or access:contains(user_bare) or access:contains(user_host)) then
124
-		origin.send(st.error_reply(stanza, "auth", "forbidden"));
125
-		return true;
126
-	end
127
-
128
-	local reply = st.reply(stanza):tag("services", { xmlns = action.attr.xmlns });
117
+function get_services(requested_type, origin, stanza, reply)
129 118
 	local extras = module:get_host_items("external_service");
130 119
 	local services = ( configured_services + extras ) / prepare;
131 120
 
132
-	local requested_type = action.attr.type;
133 121
 	if requested_type then
134 122
 		services:filter(function(item)
135 123
 			return item.type == requested_type;
@@ -138,25 +126,48 @@ local function handle_services(event)
138 126
 
139 127
 	setmetatable(services, services_mt);
140 128
 
141
-	module:fire_event("external_service/services", {
129
+	if origin and stanza and reply then
130
+		module:fire_event("external_service/services", {
142 131
 			origin = origin;
143 132
 			stanza = stanza;
144 133
 			reply = reply;
145 134
 			requested_type = requested_type;
146 135
 			services = services;
147 136
 		});
137
+	end
148 138
 
139
+	local res_services = {};
149 140
 	for _, srv in ipairs(services) do
150
-		reply:tag("service", {
151
-				type = srv.type;
152
-				transport = srv.transport;
153
-				host = srv.host;
154
-				port = srv.port and string.format("%d", srv.port) or nil;
155
-				username = srv.username;
156
-				password = srv.password;
157
-				expires = srv.expires and dt.datetime(srv.expires) or nil;
158
-				restricted = srv.restricted and "1" or nil;
159
-			}):up();
141
+		table.insert(res_services, {
142
+			type = srv.type;
143
+			transport = srv.transport;
144
+			host = srv.host;
145
+			port = srv.port and string.format("%d", srv.port) or nil;
146
+			username = srv.username;
147
+			password = srv.password;
148
+			expires = srv.expires and dt.datetime(srv.expires) or nil;
149
+			restricted = srv.restricted and "1" or nil;
150
+		})
151
+	end
152
+
153
+	return res_services;
154
+end
155
+
156
+local function handle_services(event)
157
+	local origin, stanza = event.origin, event.stanza;
158
+	local action = stanza.tags[1];
159
+
160
+	local user_bare = jid.bare(stanza.attr.from);
161
+	local user_host = jid.host(user_bare);
162
+	if not ((access:empty() and origin.type == "c2s") or access:contains(user_bare) or access:contains(user_host)) then
163
+		origin.send(st.error_reply(stanza, "auth", "forbidden"));
164
+		return true;
165
+	end
166
+
167
+	local reply = st.reply(stanza):tag("services", { xmlns = action.attr.xmlns });
168
+
169
+	for _, srv in ipairs(get_services(action.attr.type, origin, stanza, reply)) do
170
+		reply:tag("service", srv):up();
160 171
 	end
161 172
 
162 173
 	origin.send(reply);

+ 47
- 0
resources/prosody-plugins/mod_jiconop.lua Datei anzeigen

@@ -0,0 +1,47 @@
1
+local st = require "util.stanza";
2
+local get_services = module:depends("external_services").get_services;
3
+
4
+-- Jitsi Connection Optimization
5
+-- gathers needed information and pushes it with a message to clients
6
+-- this way we skip 4 request responses during every client setup
7
+
8
+local shard_name_config = module:get_option_string('shard_name');
9
+if shard_name_config then
10
+    module:add_identity("server", "shard", shard_name_config);
11
+end
12
+
13
+-- this is after xmpp-bind, the moment a client has resource and can be contacted
14
+module:hook("resource-bind", function (event)
15
+    local session = event.session;
16
+
17
+    -- disco info data / all identity and features
18
+    local query = st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#info" });
19
+    local done = {};
20
+    for _,identity in ipairs(module:get_host_items("identity")) do
21
+        local identity_s = identity.category.."\0"..identity.type;
22
+        if not done[identity_s] then
23
+            query:tag("identity", identity):up();
24
+            done[identity_s] = true;
25
+        end
26
+    end
27
+
28
+    -- check whether room has lobby enabled and display name is required for those trying to join
29
+    local lobby_muc_component_config = module:get_option_string('lobby_muc');
30
+    module:context(lobby_muc_component_config):fire_event('host-disco-info-node',
31
+            {origin = session; reply = query; node = 'lobbyrooms';});
32
+
33
+    local stanza = st.message({
34
+            type = 'service-info';
35
+            from = module.host;
36
+            to = session.full_jid; });
37
+    stanza:add_child(query):up();
38
+
39
+    --- get turnservers and credentials
40
+    local services = get_services();
41
+    stanza:tag("services");
42
+    for _, srv in ipairs(services) do
43
+        stanza:tag("service", srv):up();
44
+    end
45
+
46
+    session.send(stanza);
47
+end);

Laden…
Abbrechen
Speichern