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
feat: Updates visitors component with new iq messages. (#13125)
Дамян Минков570ae81a3798
diff --git a/resources/extra-large-conference/pre-configure.sh b/resources/extra-large-conference/pre-configure.shindex b51d6f0501..7d1c87f99b 100755--- a/resources/extra-large-conference/pre-configure.sh+++ b/resources/extra-large-conference/pre-configure.sh@@ -49,6 +49,7 @@ dohocon -f $HOCON_CONFIG set "jicofo.xmpp.visitors.v${i}.hostname" 127.0.0.1hocon -f $HOCON_CONFIG set "jicofo.xmpp.visitors.v${i}.port" 5222${i}hocon -f $HOCON_CONFIG set "jicofo.xmpp.visitors.v${i}.domain" "auth.meet.jitsi"+ hocon -f $HOCON_CONFIG set "jicofo.xmpp.visitors.v${i}.xmpp-domain" "v${i}.meet.jitsi"hocon -f $HOCON_CONFIG set "jicofo.xmpp.visitors.v${i}.password" "${PASS}"hocon -f $HOCON_CONFIG set "jicofo.xmpp.visitors.v${i}.disable-certificate-verification" truedonediff --git a/resources/prosody-plugins/mod_visitors.lua b/resources/prosody-plugins/mod_visitors.luaindex ed37160253..ee6fe2929f 100644--- a/resources/prosody-plugins/mod_visitors.lua+++ b/resources/prosody-plugins/mod_visitors.lua@@ -12,8 +12,6 @@ local st = require 'util.stanza';local jid = require 'util.jid';local util = module:require 'util';local presence_check_status = util.presence_check_status;-local get_room_from_jid = util.get_room_from_jid;-local room_jid_match_rewrite = util.room_jid_match_rewrite;local um_is_admin = require 'core.usermanager'.is_admin;local function is_admin(jid)@@ -56,34 +54,9 @@ module:add_identity('component', 'visitors', 'visitors.'..module.host);--}local visitors_nodes = {};---- Intercept conference IQ error from Jicofo. Sends the main participants to the visitor node.---- Jicofo is connected to the room when sending this error-module:log('info', 'Hook to iq/host');-module:hook('iq/full', function(event)- local stanza = event.stanza;-- if stanza.name ~= 'iq' or stanza.attr.type ~= 'result' or stanza.attr.from ~= focus_component_host then- return; -- not IQ from jicofo. Ignore this event.- end-- local conference = stanza:get_child('conference', 'http://jitsi.org/protocol/focus');- if not conference then- return;- end-- -- let's send participants if any from the room to the visitors room- local main_room = conference.attr.room;- local vnode = conference.attr.vnode;-- if not main_room or not vnode then- return;- end-- local room = get_room_from_jid(room_jid_match_rewrite(main_room));- if room == nil then- return; -- room does not exists. Continue with normal flow- end-+-- an event received from visitors component, which receives iqs from jicofo+local function connect_vnode(event)+ local room, vnode = event.room, event.vnode;local conference_service = muc_domain_prefix..'.'..vnode..'.meet.jitsi';if visitors_nodes[room.jid] and@@ -117,7 +90,19 @@ module:hook('iq/full', function(event)endendvisitors_nodes[room.jid].nodes[conference_service] = sent_main_participants;-end, 900);+end+module:hook('jitsi-connect-vnode', connect_vnode);++-- an event received from visitors component, which receives iqs from jicofo+local function disconnect_vnode(event)+ local room, vnode = event.room, event.vnode;+ local conference_service = muc_domain_prefix..'.'..vnode..'.meet.jitsi';++ -- we are counting vnode main participants and we should be clearing it there+ -- let's do it here just in case+ visitors_nodes[room.jid].nodes[conference_service] = nil;+end+module:hook('jitsi-disconnect-vnode', disconnect_vnode);-- takes care when the visitor nodes destroys the room to count the leaving participants from there, and if its really destroyed-- we clean up, so if we establish again the connection to the same visitor node to send the main participantsdiff --git a/resources/prosody-plugins/mod_visitors_component.lua b/resources/prosody-plugins/mod_visitors_component.luaindex 473dfa45b1..9b2be1bcdf 100644--- a/resources/prosody-plugins/mod_visitors_component.lua+++ b/resources/prosody-plugins/mod_visitors_component.lua@@ -1,7 +1,6 @@module:log('info', 'Starting visitors_component at %s', module.host);local jid = require 'util.jid';-local iterators = require 'util.iterators';local st = require 'util.stanza';local util = module:require 'util';local room_jid_match_rewrite = util.room_jid_match_rewrite;@@ -9,6 +8,7 @@ local get_room_from_jid = util.get_room_from_jid;local get_focus_occupant = util.get_focus_occupant;local get_room_by_name_and_subdomain = util.get_room_by_name_and_subdomain;local new_id = require 'util.id'.medium;+local um_is_admin = require "core.usermanager".is_admin;local muc_domain_prefix = module:get_option_string('muc_mapper_domain_prefix', 'conference');local muc_domain_base = module:get_option_string('muc_mapper_domain_base');@@ -19,12 +19,80 @@ endlocal auto_allow_promotion = module:get_option_boolean("auto_allow_visitor_promotion", false);+local function is_admin(jid)+ return um_is_admin(jid, module.host);+end+-- This is a map to keep data for room and the jids that were allowed to join after visitor mode is enabled-- automatically allowed or allowed by a moderatorlocal visitors_promotion_map = {};local sent_iq_cache = require 'util.cache'.new(200);+-- send iq result that the iq was received and will be processed+local function respond_iq_result(origin, stanza)+ -- respond with successful receiving the iq+ origin.send(st.iq({+ type = "result";+ from = stanza.attr.to;+ to = stanza.attr.from;+ id = stanza.attr.id+ }));+end++local function request_promotion_received(room, from_jid, from_vnode)+ if not visitors_promotion_map[room.jid] and auto_allow_promotion then+ -- visitors is enabled+ visitors_promotion_map[room.jid] = {};+ end++ -- if visitors is enabled for the room+ if visitors_promotion_map[room.jid] then+ if auto_allow_promotion then+ -- we are in auto-allow mode, let's reply with accept+ -- we store where the request is coming from so we can send back the response+ local username = new_id():lower();+ visitors_promotion_map[room.jid][username] = {+ from = from_vnode;+ jid = from_jid;+ };++ local req_from = visitors_promotion_map[room.jid][username].from;+ local req_jid = visitors_promotion_map[room.jid][username].jid;+ local focus_occupant = get_focus_occupant(room);+ local focus_jid = focus_occupant and focus_occupant.bare_jid or nil;++ local iq_id = new_id();+ sent_iq_cache:set(iq_id, socket.gettime());++ module:send(st.iq({+ type='set', to = req_from, from = module.host, id = iq_id })+ :tag('visitors', {+ xmlns='jitsi:visitors',+ room = string.gsub(room.jid, muc_domain_base, req_from),+ focusjid = focus_jid })+ :tag('promotion-response', {+ xmlns='jitsi:visitors',+ jid = req_jid,+ username = username ,+ allow = 'true' }):up());+ return true;+ end++ -- TODO send promotion request to all moderators+ module:log('warn', 'Received promotion request from %s for room %s without active visitors', from, room.jid);+ return;+ end+end++local function connect_vnode_received(room, vnode)+ module:context(muc_domain_base):fire_event('jitsi-connect-vnode', { room = room; vnode = vnode; });+end++local function disconnect_vnode_received(room, vnode)+ module:context(muc_domain_base):fire_event('jitsi-disconnect-vnode', { room = room; vnode = vnode; });+end+-- listens for iq request for promotion and forward it to moderators in the meeting for approval-- or auto-allow it if such the config is set enabling itlocal function stanza_handler(event)@@ -39,7 +107,7 @@ local function stanza_handler(event)return true;end- if stanza.attr.type ~= 'set' then+ if stanza.attr.type ~= 'set' and stanza.attr.type ~= 'get' thenreturn; -- We do not want to reply to these, so leave.end@@ -48,7 +116,8 @@ local function stanza_handler(event)return;end- if origin.type ~= 's2sin' then+ -- set stanzas are coming from s2s connection+ if stanza.attr.type == 'set' and origin.type ~= 's2sin' thenmodule:log('warn', 'not from s2s session, ignore! %s', stanza);return true;end@@ -61,65 +130,32 @@ local function stanza_handler(event)return;end+ local processed;+ -- promotion request is coming from visitors and is a set and is over the s2s connectionlocal request_promotion = visitors_iq:get_child('promotion-request');- if not request_promotion then- return;+ if request_promotion then+ processed = request_promotion_received(room, request_promotion.attr.jid, stanza.attr.from);end- -- respond with successful receiving the iq- origin.send(st.iq({- type = "result";- from = stanza.attr.to;- to = stanza.attr.from;- id = stanza.attr.id- }));-- -- TODO send iq to moderators (what about name? -> it will be coming from the token) or auto allow- if not visitors_promotion_map[room.jid] and auto_allow_promotion then- -- visitors is enabled- visitors_promotion_map[room.jid] = {};- end-- -- if visitors is enabled for the room- if visitors_promotion_map[room.jid] then- if auto_allow_promotion then- -- we are in auto-allow mode, let's reply with accept- -- we store where the request is coming from so we can send back the response- local username = new_id():lower();- visitors_promotion_map[room.jid][username] = {- from = stanza.attr.from;- jid = request_promotion.attr.jid;- room = visitors_iq.attr.room;- };-- local req_from = visitors_promotion_map[room.jid][username].from;- local req_room = visitors_promotion_map[room.jid][username].room;- local req_jid = visitors_promotion_map[room.jid][username].jid;- local focus_occupant = get_focus_occupant(room);- local focus_jid = focus_occupant and focus_occupant.bare_jid or nil;-- local iq_id = new_id();- sent_iq_cache:set(iq_id, socket.gettime());+ -- connect and disconnect are only received from jicofo+ if is_admin(jid.bare(stanza.attr.from)) then+ for item in visitors_iq:childtags('connect-vnode') do+ connect_vnode_received(room, item.attr.vnode);+ processed = true;+ end- module:send(st.iq({- type='set',- to = req_from,- from = module.host,- id = iq_id })- :tag('visitors', {- xmlns='jitsi:visitors',- room = string.gsub(req_room, muc_domain_base, req_from),- focusjid = focus_jid })- :tag('promotion-response', {- xmlns='jitsi:visitors',- jid = req_jid,- username = username ,- allow = 'true' }):up());- return true;+ for item in visitors_iq:childtags('disconnect-vnode') do+ disconnect_vnode_received(room, item.attr.vnode);+ processed = true;end+ end- -- TODO send promotion request to all moderators+ if not processed then+ module:log('warn', 'Unknown iq received for %s: %s', module.host, stanza);end++ respond_iq_result(origin, stanza);+ return processed;endmodule:hook("iq/host", stanza_handler, 10);