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
fix(visitors): Visitor updates - request to participate (#13106)
Дамян Минков1c04a4108126
diff --git a/conference.js b/conference.jsindex fe3b32c00c..e286fc83ab 100644--- a/conference.js+++ b/conference.js@@ -47,8 +47,8 @@ import {dataChannelClosed,dataChannelOpened,e2eRttChanged,- generateVisitorConfig,getConferenceOptions,+ getVisitorOptions,kickedOut,lockStateChanged,nonParticipantMessageReceived,@@ -56,6 +56,7 @@ import {p2pStatusChanged,sendLocalParticipant} from './react/features/base/conference';+import { overwriteConfig } from './react/features/base/config/actions';import { getReplaceParticipant } from './react/features/base/config/functions';import {checkAndNotifyForNewDevice,@@ -341,23 +342,26 @@ class ConferenceConnector {}case JitsiConferenceErrors.REDIRECTED: {- generateVisitorConfig(APP.store.getState(), params);+ const newConfig = getVisitorOptions(APP.store.getState(), params);- APP.store.dispatch(setIAmVisitor(true));-- connection.disconnect().then(() => {- connect(this._conference.roomName).then(con => {- const localTracks = getLocalTracks(APP.store.getState()['features/base/tracks']);+ if (!newConfig) {+ logger.warn('Not redirected missing params');+ break;+ }- const jitsiTracks = localTracks.map(t => t.jitsiTrack);+ const [ vnode ] = params;- // visitors connect muted- jitsiTracks.forEach(t => t.mute());+ APP.store.dispatch(overwriteConfig(newConfig))+ .then(APP.store.dispatch(setIAmVisitor(Boolean(vnode))))+ .then(this._conference.leaveRoom())- // TODO disable option to unmute audio or video- this._conference.startConference(con, jitsiTracks);+ // we do not clear local tracks on error, so we need to manually clear them+ .then(APP.store.dispatch(destroyLocalTracks()))+ .then(() => {+ connect(this._conference.roomName).then(con => {+ this._conference.startConference(con, []);+ });});- });break;}diff --git a/connection.js b/connection.jsindex 9b6f3f5d1d..fc863ef865 100644--- a/connection.js+++ b/connection.js@@ -167,7 +167,7 @@ export function openConnection({ id, password, retry, roomName }) {password = passwordOverride; // eslint-disable-line no-param-reassign}- return connect(id, password, roomName).catch(err => {+ return connect(id, password).catch(err => {if (retry) {const { jwt } = APP.store.getState()['features/base/jwt'];diff --git a/react/features/base/conference/functions.ts b/react/features/base/conference/functions.tsindex 6509043a81..3a52352220 100644--- a/react/features/base/conference/functions.ts+++ b/react/features/base/conference/functions.ts@@ -259,10 +259,10 @@ export function getConferenceOptions(stateful: IStateful) {** @param {IStateful} stateful - The redux store state.* @param {Array<string>} params - The received parameters.- * @returns {void}+ * @returns {Object}*/-export function generateVisitorConfig(stateful: IStateful, params: Array<string>) {- const [ vnode, focusJid ] = params;+export function getVisitorOptions(stateful: IStateful, params: Array<string>) {+ const [ vnode, focusJid, username ] = params;const config = toState(stateful)['features/base/config'];@@ -272,21 +272,47 @@ export function generateVisitorConfig(stateful: IStateful, params: Array<string>return;}- const oldDomain = config.hosts.domain;-- config.hosts.domain = `${vnode}.meet.jitsi`;- config.hosts.muc = config.hosts.muc.replace(oldDomain, config.hosts.domain);- config.focusUserJid = focusJid;-- // This flag disables sending the initial conference request- config.disableFocus = true;+ if (!vnode) {+ // this is redirecting back to main, lets restore config+ // no point of updating disableFocus, we can skip the initial iq to jicofo+ if (config.oldConfig && username) {+ return {+ hosts: {+ domain: config.oldConfig.hosts.domain,+ muc: config.oldConfig.hosts.muc+ },+ focusUserJid: focusJid,+ bosh: config.oldConfig.bosh && appendURLParam(config.oldConfig.bosh, 'customusername', username),+ websocket: config.oldConfig.websocket+ && appendURLParam(config.oldConfig.websocket, 'customusername', username)+ };+ }- if (config.bosh) {- config.bosh = appendURLParam(config.bosh, 'vnode', vnode);- }- if (config.websocket) {- config.websocket = appendURLParam(config.websocket, 'vnode', vnode);+ return {};}++ const oldConfig = {+ hosts: {+ domain: config.hosts.domain,+ muc: config.hosts.muc+ },+ bosh: config.bosh,+ websocket: config.websocket+ };++ const domain = `${vnode}.meet.jitsi`;++ return {+ oldConfig,+ hosts: {+ domain,+ muc: config.hosts.muc.replace(oldConfig.hosts.domain, domain)+ },+ focusUserJid: focusJid,+ disableFocus: true, // This flag disables sending the initial conference request+ bosh: config.bosh && appendURLParam(config.bosh, 'vnode', vnode),+ websocket: config.websocket && appendURLParam(config.websocket, 'vnode', vnode)+ };}/**diff --git a/react/features/base/config/constants.ts b/react/features/base/config/constants.tsindex 171bbc3791..f5b210fb88 100644--- a/react/features/base/config/constants.ts+++ b/react/features/base/config/constants.ts@@ -64,7 +64,7 @@ export const THIRD_PARTY_PREJOIN_BUTTONS = [ 'microphone', 'camera', 'select-bac/*** The toolbar buttons to show when in visitors mode.*/-export const VISITORS_MODE_BUTTONS = [ 'hangup', 'tileview' ];+export const VISITORS_MODE_BUTTONS = [ 'hangup', 'raisehand', 'tileview' ];/*** The set of feature flags.diff --git a/react/features/base/config/reducer.ts b/react/features/base/config/reducer.tsindex 81712464ac..a26de5c6be 100644--- a/react/features/base/config/reducer.ts+++ b/react/features/base/config/reducer.ts@@ -84,6 +84,14 @@ export interface IConfigState extends IConfig {};disableRemoteControl?: boolean;error?: Error;+ oldConfig?: {+ bosh?: string;+ hosts: {+ domain: string;+ muc: string;+ };+ websocket?: string;+ };}ReducerRegistry.register<IConfigState>('features/base/config', (state = _getInitialState(), action): IConfigState => {diff --git a/react/features/conference/components/web/SpeakerStatsLabel.tsx b/react/features/conference/components/web/SpeakerStatsLabel.tsxindex 04fa33ab88..395bf568c3 100644--- a/react/features/conference/components/web/SpeakerStatsLabel.tsx+++ b/react/features/conference/components/web/SpeakerStatsLabel.tsx@@ -9,6 +9,7 @@ import { COLORS } from '../../../base/label/constants';import { getParticipantCount } from '../../../base/participants/functions';import { SpeakerStats } from '../../../speaker-stats';import { isSpeakerStatsDisabled } from '../../../speaker-stats/functions';+import { iAmVisitor } from '../../../visitors/functions';/*** ParticipantsCount react component.@@ -18,10 +19,16 @@ import { isSpeakerStatsDisabled } from '../../../speaker-stats/functions';*/function SpeakerStatsLabel() {const conference = useSelector((state: IReduxState) => state['features/base/conference'].conference);- const count = useSelector(getParticipantCount);+ let count = useSelector(getParticipantCount);+ const iAmVisitorState = useSelector(iAmVisitor);const _isSpeakerStatsDisabled = useSelector(isSpeakerStatsDisabled);const dispatch = useDispatch();+ // visitor has hidden its own video and should not count itself+ if (iAmVisitorState) {+ count--;+ }+const onClick = () => {dispatch(openDialog(SpeakerStats, { conference }));};diff --git a/react/features/participants-pane/components/web/MeetingParticipants.tsx b/react/features/participants-pane/components/web/MeetingParticipants.tsxindex 6e9a3797ab..7722c159d4 100644--- a/react/features/participants-pane/components/web/MeetingParticipants.tsx+++ b/react/features/participants-pane/components/web/MeetingParticipants.tsx@@ -106,7 +106,7 @@ function MeetingParticipants({const participantActionEllipsisLabel = t('participantsPane.actions.moreParticipantOptions');const youText = t('chat.you');const isBreakoutRoom = useSelector(isInBreakoutRoom);- const visitorsCount = useSelector((state: IReduxState) => state['features/visitors'].count);+ const visitorsCount = useSelector((state: IReduxState) => state['features/visitors'].count || 0);const { classes: styles, cx } = useStyles();@@ -119,8 +119,8 @@ function MeetingParticipants({{ t('participantsPane.title') }</span><div className = { cx(styles.heading, styles.headingW) }>- {visitorsCount && visitorsCount > 0- && t('participantsPane.headings.visitors', { count: visitorsCount })}+ {visitorsCount > 0+ ? t('participantsPane.headings.visitors', { count: visitorsCount }) : undefined}</div><div className = { styles.heading }>{currentRoom?.namediff --git a/react/features/visitors/components/web/VisitorsCountLabel.tsx b/react/features/visitors/components/web/VisitorsCountLabel.tsxindex a4046143ac..d527ea7c5e 100644--- a/react/features/visitors/components/web/VisitorsCountLabel.tsx+++ b/react/features/visitors/components/web/VisitorsCountLabel.tsx@@ -25,7 +25,7 @@ const VisitorsCountLabel = () => {state['features/visitors'].count || 0);const { t } = useTranslation();- return visitorsMode && (<Tooltip+ return !visitorsMode && visitorsCount > 0 && (<Tooltipcontent = { t('visitorsLabel', { count: visitorsCount }) }position = { 'bottom' }><Labeldiff --git a/react/features/visitors/middleware.ts b/react/features/visitors/middleware.tsindex d4edd8783b..e21b0fe411 100644--- a/react/features/visitors/middleware.ts+++ b/react/features/visitors/middleware.ts@@ -1,19 +1,21 @@+import { CONFERENCE_JOIN_IN_PROGRESS } from '../base/conference/actionTypes';import { JitsiConferenceEvents } from '../base/lib-jitsi-meet';-import StateListenerRegistry from '../base/redux/StateListenerRegistry';+import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';import { updateVisitorsCount } from './actions';-StateListenerRegistry.register(- state => state['features/base/conference'].conference,- (conference, { dispatch, getState }, previousConference) => {- if (conference && !previousConference) {- conference.on(JitsiConferenceEvents.PROPERTIES_CHANGED, (properties: { 'visitor-count': number; }) => {- const visitorCount = Number(properties?.['visitor-count']);+MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {+ if (action.type === CONFERENCE_JOIN_IN_PROGRESS) {+ const { conference } = action;- if (!isNaN(visitorCount) && getState()['features/visitors'].count !== visitorCount) {- dispatch(updateVisitorsCount(visitorCount));- }- });- }- });+ conference.on(JitsiConferenceEvents.PROPERTIES_CHANGED, (properties: { 'visitor-count': number; }) => {+ const visitorCount = Number(properties?.['visitor-count']);+ if (!isNaN(visitorCount) && getState()['features/visitors'].count !== visitorCount) {+ dispatch(updateVisitorsCount(visitorCount));+ }+ });+ }++ return next(action);+});diff --git a/resources/extra-large-conference/README.md b/resources/extra-large-conference/README.mdindex 2c324e4862..124c09dc68 100644--- a/resources/extra-large-conference/README.md+++ b/resources/extra-large-conference/README.md@@ -55,13 +55,21 @@ Setting up configuration for the main prosody is a manual process:-- targets must be IPs, not hostnamess2s_connect_overrides = {["conference.v1.meet.jitsi"] = { "127.0.0.1", 52691 };+ ["v1.meet.jitsi"] = { "127.0.0.1", 52691 }; -- needed for v1.meet.jitsi->visitors.jitmeet.example.com["conference.v2.meet.jitsi"] = { "127.0.0.1", 52692 };+ ["v2.meet.jitsi"] = { "127.0.0.1", 52692 };["conference.v3.meet.jitsi"] = { "127.0.0.1", 52693 };+ ["v3.meet.jitsi"] = { "127.0.0.1", 52693 };["conference.v4.meet.jitsi"] = { "127.0.0.1", 52694 };+ ["v4.meet.jitsi"] = { "127.0.0.1", 52694 };["conference.v5.meet.jitsi"] = { "127.0.0.1", 52695 };+ ["v5.meet.jitsi"] = { "127.0.0.1", 52695 };["conference.v6.meet.jitsi"] = { "127.0.0.1", 52696 };+ ["v6.meet.jitsi"] = { "127.0.0.1", 52696 };["conference.v7.meet.jitsi"] = { "127.0.0.1", 52697 };+ ["v7.meet.jitsi"] = { "127.0.0.1", 52697 };["conference.v8.meet.jitsi"] = { "127.0.0.1", 52698 };+ ["v8.meet.jitsi"] = { "127.0.0.1", 52698 };}-- allowed list of server-2-server connectionss2s_whitelist = {@@ -71,17 +79,36 @@ s2s_whitelist = {```- Make sure s2s is not in modules_disabled-- Enable `"xxl_conference";` module under the main virtual host (e.g. [here](https://github.com/jitsi/jitsi-meet/blob/f42772ec5bcc87ff6de17423d36df9bcad6e770d/doc/debian/jitsi-meet-prosody/prosody.cfg.lua-jvb.example#L57))+- Enable `"visitors";` module under the main virtual host (e.g. [here](https://github.com/jitsi/jitsi-meet/blob/f42772ec5bcc87ff6de17423d36df9bcad6e770d/doc/debian/jitsi-meet-prosody/prosody.cfg.lua-jvb.example#L57))+- Create the visitors component in /etc/prosody/conf.d/jitmeet.example.com.cfg.lua:+```+Component "visitors.jitmeet.example.com" "visitors_component"+```+- Make sure you add the correct upstreams to nginx config+```+upstream v1 {+ zone upstreams 64K;+ server 127.0.0.1:52801;+ keepalive 2;+}+upstream v2 {+ zone upstreams 64K;+ server 127.0.0.1:52802;+ keepalive 2;+}+```After configuring you can set the maximum number of main participants, beforeredirecting to visitors.```+hocon -f /etc/jitsi/jicofo/jicofo.conf set "jicofo.visitors.enabled" truehocon -f /etc/jitsi/jicofo/jicofo.conf set "jicofo.visitors.max-participants" 30```Now restart prosody and jicofo```service prosody restartservice jicofo restart+service nginx restart```Now after the main 30 participants join, the rest will be visitors using thediff --git a/resources/extra-large-conference/pre-configure.sh b/resources/extra-large-conference/pre-configure.shindex 7375157d2a..ee778629d2 100755--- a/resources/extra-large-conference/pre-configure.sh+++ b/resources/extra-large-conference/pre-configure.sh@@ -14,6 +14,8 @@ echo "Will configure $NUMBER_OF_INSTANCES number of visitor prosodies"set -eset -x+. /etc/jitsi/jicofo/config+# Configure prosody instancesfor (( i=1 ; i<=${NUMBER_OF_INSTANCES} ; i++ ));do@@ -23,12 +25,14 @@ doln -s /etc/prosody/certs /etc/prosody-v${i}/certscp prosody.cfg.lua.visitor.template /etc/prosody-v${i}/prosody.cfg.luased -i "s/vX/v${i}/g" /etc/prosody-v${i}/prosody.cfg.lua+ sed -i "s/jitmeet.example.com/$JICOFO_HOSTNAME/g" /etc/prosody-v${i}/prosody.cfg.luadone# Configure jicofoHOCON_CONFIG="/etc/jitsi/jicofo/jicofo.conf"hocon -f $HOCON_CONFIG set "jicofo.bridge.selection-strategy" "VisitorSelectionStrategy"hocon -f $HOCON_CONFIG set "jicofo.bridge.visitor-selection-strategy" "RegionBasedBridgeSelectionStrategy"+hocon -f $HOCON_CONFIG set "jicofo.bridge.participant-selection-strategy" "RegionBasedBridgeSelectionStrategy"hocon -f $HOCON_CONFIG set "jicofo.bridge.topology-strategy" "VisitorTopologyStrategy"PASS=$(hocon -f $HOCON_CONFIG get "jicofo.xmpp.client.password")diff --git a/resources/extra-large-conference/prosody.cfg.lua.visitor.template b/resources/extra-large-conference/prosody.cfg.lua.visitor.templateindex 329713fc5a..11465c4131 100644--- a/resources/extra-large-conference/prosody.cfg.lua.visitor.template+++ b/resources/extra-large-conference/prosody.cfg.lua.visitor.template@@ -30,9 +30,19 @@ modules_enabled = {'bosh';'s2s_bidi';'s2s_whitelist';+ 's2soutinjection';+ 'certs_s2soutinjection';};-s2s_whitelist = {};+s2s_whitelist = {+ 'visitors.jitmeet.example.com'; -- needed for sending promotion request to visitors.jitmeet.example.com component+ 'jitmeet.example.com'; -- unavailable presences back to main room+};++s2s_connect_overrides = {+ ["jitmeet.example.com"] = { "127.0.0.1", 5269 }; -- needed for the main room when connecting in to send main participants+ ["visitors.jitmeet.example.com"] = { "127.0.0.1", 5269 }; -- needed for sending promotion request to visitors.jitmeet.example.com component+}external_service_secret = '__turnSecret__';@@ -111,6 +121,7 @@ Component 'conference.vX.meet.jitsi' 'muc''muc_domain_mapper';'muc_meeting_id';'fmuc';+ 's2soutinjection';}muc_room_default_presence_broadcast = {visitor = false;diff --git a/resources/prosody-plugins/mod_fmuc.lua b/resources/prosody-plugins/mod_fmuc.luaindex d5ed605847..b50b94d449 100644--- a/resources/prosody-plugins/mod_fmuc.lua+++ b/resources/prosody-plugins/mod_fmuc.lua@@ -7,35 +7,39 @@--- };--- Enable in global modules: 's2s_bidi'--- Make sure 's2s' is not in modules_disabled+--- NOTE: Make sure all communication between prosodies is using the real jids ([foo][email protected]), as there+--- are certain configs for whitelisted domains and connections that are domain based+--- TODO: filter presence from main occupants back to main prosody+--- TODO: filter messages back to main prosodylocal jid = require 'util.jid';local st = require 'util.stanza';+local new_id = require 'util.id'.medium;++local util = module:require 'util';+local room_jid_match_rewrite = util.room_jid_match_rewrite;+local get_room_from_jid = util.get_room_from_jid;+local get_focus_occupant = util.get_focus_occupant;+local internal_room_jid_match_rewrite = util.internal_room_jid_match_rewrite;local muc_domain_prefix = module:get_option_string('muc_mapper_domain_prefix', 'conference');local main_domain = string.gsub(module.host, muc_domain_prefix..'.', '');-local function get_focus_occupant(room)- local focus_occupant = room._data.focus_occupant;-- if focus_occupant then- return focus_occupant;- end+-- This is the domain of the main prosody that is federating with us;+local fmuc_main_domain;- for _, n_occupant in room:each_occupant() do- if jid.node(n_occupant.jid) == 'focus' then- room._data.focus_occupant = n_occupant;- return n_occupant;- end- end-- return nil;-end+local sent_iq_cache = require 'util.cache'.new(200);-- mark all occupants as visitorsmodule:hook('muc-occupant-pre-join', function (event)- local occupant = event.occupant;+ local occupant, session = event.occupant, event.origin;+ local node, host = jid.split(occupant.bare_jid);- if jid.host(occupant.bare_jid) == main_domain then+ if host == main_domain thenoccupant.role = 'visitor';+ elseif not fmuc_main_domain then+ if node ~= 'focus' then+ fmuc_main_domain = host;+ endendend, 3);@@ -53,30 +57,31 @@ module:hook('muc-occupant-left', function (event)return;end-- Let's forward unavailable presence to the special jicofo- local pr = st.presence({ to = focus_occupant.jid, from = occupant.nick, type = 'unavailable' })+ room:route_stanza(st.presence({+ to = focus_occupant.jid,+ from = internal_room_jid_match_rewrite(occupant.nick),+ type = 'unavailable' }):tag('x', { xmlns = 'http://jabber.org/protocol/muc#user' }):tag('item', {affiliation = room:get_affiliation(occupant.bare_jid) or 'none';role = 'none';nick = event.nick;- jid = occupant.bare_jid }):up()- :up();- room:route_stanza(pr);+ jid = occupant.bare_jid }):up():up());endif not room.destroying then- if room.xxl_destroy_timer then- room.xxl_destroy_timer:stop();+ if room.visitors_destroy_timer then+ room.visitors_destroy_timer:stop();end- room.xxl_destroy_timer = module:add_timer(15, function()+ room.visitors_destroy_timer = module:add_timer(15, function()-- let's check are all visitors in the room, if all a visitors - destroy it-- if all are main-participants also destroy itlocal main_count = 0;local visitors_count = 0;for _, o in room:each_occupant() do- -- if there are visitor and main participant there is no point continue+ -- if there are visitors and main participant there is no point continueif main_count > 0 and visitors_count > 0 thenreturn;end@@ -100,6 +105,7 @@ module:hook('muc-occupant-left', function (event)end);-- forward visitor presences to jicofo+-- detects raise hand in visitors presence, this is request for promotionmodule:hook('muc-broadcast-presence', function (event)local occupant = event.occupant;@@ -128,5 +134,105 @@ module:hook('muc-broadcast-presence', function (event)local full_p = st.clone(base_presence):add_child(full_x);full_p.attr.to = focus_occupant.jid;room:route_to_occupant(focus_occupant, full_p);++ local raiseHand = full_p:get_child_text('jitsi_participant_raisedHand');+ -- a promotion detected let's send it to main prosody+ if raiseHand then+ -- TODO check room= with tenants+ local iq_id = new_id();+ sent_iq_cache:set(iq_id, socket.gettime());+ local promotion_request = st.iq({+ type = 'set',+ to = 'visitors.'..fmuc_main_domain,+ from = main_domain,+ id = iq_id })+ :tag('visitors', { xmlns = 'jitsi:visitors',+ room = jid.join(jid.node(room.jid), muc_domain_prefix..'.'..fmuc_main_domain) })+ :tag('promotion-request', { xmlns = 'jitsi:visitors', jid = occupant.jid }):up();+ -- TODO what about name ???? it will be coming from the token, but we need to extract it and send it to the moderators+ module:send(promotion_request);+ end+return;end);++-- listens for responses to the iq sent for requesting promotion and forward it to the visitor+local function stanza_handler(event)+ local origin, stanza = event.origin, event.stanza;++ if stanza.name ~= 'iq' then+ return;+ end++ if stanza.attr.type == 'result' and sent_iq_cache:get(stanza.attr.id) then+ sent_iq_cache:set(stanza.attr.id, nil);+ return true;+ end++ if stanza.attr.type ~= 'set' then+ return;+ end++ local visitors_iq = event.stanza:get_child('visitors', 'jitsi:visitors');+ if not visitors_iq then+ return;+ end++ if stanza.attr.from ~= 'visitors.'..fmuc_main_domain then+ module:log('warn', 'not from visitors component, ignore! %s %s', stanza.attr.from, stanza);+ return true;+ end++ local room_jid = visitors_iq.attr.room;+ local room = get_room_from_jid(room_jid_match_rewrite(room_jid));++ if not room then+ log('warn', 'No room found %s', room_jid);+ return;+ end++ local request_promotion = visitors_iq:get_child('promotion-response');+ if not request_promotion then+ return;+ 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+ }));++ local req_jid = request_promotion.attr.jid;+ -- now let's find the occupant and forward the response+ local occupant = room:get_occupant_by_real_jid(req_jid);++ if occupant then+ stanza.attr.to = occupant.jid;+ stanza.attr.from = room.jid;+ room:route_to_occupant(occupant, stanza);+ return true;+ end+end++--process a host module directly if loaded or hooks to wait for its load+function process_host_module(name, callback)+ local function process_host(host)+ if host == name then+ callback(module:context(host), host);+ end+ end++ if prosody.hosts[name] == nil then+ module:log('debug', 'No host/component found, will wait for it: %s', name)++ -- when a host or component is added+ prosody.events.add_handler('host-activated', process_host);+ else+ process_host(name);+ end+end+process_host_module(main_domain, function(host_module, host)+ host_module:hook('iq/host', stanza_handler, 10);+end);diff --git a/resources/prosody-plugins/mod_jitsi_session.lua b/resources/prosody-plugins/mod_jitsi_session.luaindex 01619c16ba..3e52fb48b4 100644--- a/resources/prosody-plugins/mod_jitsi_session.lua+++ b/resources/prosody-plugins/mod_jitsi_session.lua@@ -18,6 +18,9 @@ function init_session(event)-- the param is used to find resumed session and re-use anonymous(random) user idsession.previd = query and params.previd or nil;+ -- customusername can be used with combination with "pre-jitsi-authentication" event to pre-set a known jid to a session+ session.customusername = query and params.customusername or nil;+-- The room name and optional prefix from the web querysession.jitsi_web_query_room = urlencode(params.room);session.jitsi_web_query_prefix = urlencode(params.prefix) or "";diff --git a/resources/prosody-plugins/mod_xxl_conference.lua b/resources/prosody-plugins/mod_visitors.luasimilarity index 85%rename from resources/prosody-plugins/mod_xxl_conference.luarename to resources/prosody-plugins/mod_visitors.luaindex e93fcfc2a4..c922760572 100644--- a/resources/prosody-plugins/mod_xxl_conference.lua+++ b/resources/prosody-plugins/mod_visitors.lua@@ -9,10 +9,13 @@--- Make sure 's2s' is not in modules_disabled--- Open port 5269 on the provider side and on the firewall on the machine (iptables -I INPUT 4 -p tcp -m tcp --dport 5269 -j ACCEPT)--- TODO: make it work with tenants+--- NOTE: Make sure all communication between prosodies is using the real jids ([foo][email protected])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)@@ -37,10 +40,13 @@ local muc_domain_prefix = module:get_option_string('muc_mapper_domain_prefix', 'local main_muc_component_config = module:get_option_string('main_muc');if main_muc_component_config == nil then- module:log('error', 'xxl rooms not enabled missing main_muc config');+ module:log('error', 'visitors rooms not enabled missing main_muc config');return ;end+-- Advertise the component for discovery via disco#items+module:add_identity('component', 'visitors', 'visitors.'..module.host);+-- visitors_nodes = {-- roomjid1 = {-- nodes = {@@ -68,7 +74,6 @@ module:hook('iq/full', function(event)end-- let's send participants if any from the room to the visitors room- -- TODO fix room name extract, make sure it works wit tenantslocal main_room = conference.attr.room;local vnode = conference.attr.vnode;@@ -76,8 +81,7 @@ module:hook('iq/full', function(event)return;end- local room = get_room_from_jid(main_room);-+ local room = get_room_from_jid(room_jid_match_rewrite(main_room));if room == nil thenreturn; -- room does not exists. Continue with normal flowend@@ -170,10 +174,10 @@ process_host_module(main_muc_component_config, function(host_module, host)endlocal vnodes = visitors_nodes[room.jid].nodes;+ local user, _, res = jid.split(occupant.nick);-- a change in the presence of a main participant we need to update all active visitor nodesfor k in pairs(vnodes) dolocal fmuc_pr = st.clone(stanza);- local user, _, res = jid.split(occupant.nick);fmuc_pr.attr.to = jid.join(user, k, res);fmuc_pr.attr.from = occupant.jid;module:send(fmuc_pr);@@ -191,9 +195,9 @@ process_host_module(main_muc_component_config, function(host_module, host)-- we want to update visitor node that a main participant leftif stanza thenlocal vnodes = visitors_nodes[room.jid].nodes;+ local user, _, res = jid.split(occupant.nick);for k in pairs(vnodes) dolocal fmuc_pr = st.clone(stanza);- local user, _, res = jid.split(occupant.nick);fmuc_pr.attr.to = jid.join(user, k, res);fmuc_pr.attr.from = occupant.jid;module:send(fmuc_pr);@@ -207,4 +211,24 @@ process_host_module(main_muc_component_config, function(host_module, host)host_module:hook('muc-room-destroyed',function(event)visitors_nodes[event.room.jid] = nil;end);++ -- detects new participants joining main room and sending them to the visitor nodes+ host_module:hook('muc-occupant-joined', function (event)+ local room, stanza, occupant = event.room, event.stanza, event.occupant;++ -- filter focus+ if is_admin(stanza.attr.from) or visitors_nodes[room.jid] == nil then+ return;+ end++ local vnodes = visitors_nodes[room.jid].nodes;+ local user, _, res = jid.split(occupant.nick);+ -- a main participant we need to update all active visitor nodes+ for k in pairs(vnodes) do+ local fmuc_pr = st.clone(stanza);+ fmuc_pr.attr.to = jid.join(user, k, res);+ fmuc_pr.attr.from = occupant.jid;+ module:send(fmuc_pr);+ end+ end);end);diff --git a/resources/prosody-plugins/mod_visitors_component.lua b/resources/prosody-plugins/mod_visitors_component.luanew file mode 100644index 0000000000..473dfa45b1--- /dev/null+++ b/resources/prosody-plugins/mod_visitors_component.lua@@ -0,0 +1,190 @@+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;+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 muc_domain_prefix = module:get_option_string('muc_mapper_domain_prefix', 'conference');+local muc_domain_base = module:get_option_string('muc_mapper_domain_base');+if not muc_domain_base then+ module:log('warn', 'No muc_domain_base option set.');+ return;+end++local auto_allow_promotion = module:get_option_boolean("auto_allow_visitor_promotion", false);++-- 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 moderator+local visitors_promotion_map = {};++local sent_iq_cache = require 'util.cache'.new(200);++-- 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 it+local function stanza_handler(event)+ local origin, stanza = event.origin, event.stanza;++ if stanza.name ~= 'iq' then+ return;+ end++ if stanza.attr.type == 'result' and sent_iq_cache:get(stanza.attr.id) then+ sent_iq_cache:set(stanza.attr.id, nil);+ return true;+ end++ if stanza.attr.type ~= 'set' then+ return; -- We do not want to reply to these, so leave.+ end++ local visitors_iq = event.stanza:get_child('visitors', 'jitsi:visitors');+ if not visitors_iq then+ return;+ end++ if origin.type ~= 's2sin' then+ module:log('warn', 'not from s2s session, ignore! %s', stanza);+ return true;+ end++ local room_jid = visitors_iq.attr.room;+ local room = get_room_from_jid(room_jid_match_rewrite(room_jid));++ if not room then+ log('warn', 'No room found %s', room_jid);+ return;+ end++ local request_promotion = visitors_iq:get_child('promotion-request');+ if not request_promotion then+ return;+ 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());++ 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;+ end++ -- TODO send promotion request to all moderators+ end+end++module:hook("iq/host", stanza_handler, 10);++ --process a host module directly if loaded or hooks to wait for its load+function process_host_module(name, callback)+ local function process_host(host)+ if host == name then+ callback(module:context(host), host);+ end+ end++ if prosody.hosts[name] == nil then+ module:log('debug', 'No host/component found, will wait for it: %s', name)++ -- when a host or component is added+ prosody.events.add_handler('host-activated', process_host);+ else+ process_host(name);+ end+end++process_host_module(muc_domain_prefix..'.'..muc_domain_base, function(host_module, host)+ -- if visitor mode is started, then you are not allowed to join without request/response exchange of iqs -> deny access+ -- check list of allowed jids for the room+ host_module:hook('muc-occupant-pre-join', function (event)+ local room, stanza, origin = event.room, event.stanza, event.origin;++ -- we skip any checks when auto-allow is enabled+ if auto_allow_promotion then+ return;+ end++ if visitors_promotion_map[room.jid] then+ -- now let's check for jid+ if visitors_promotion_map[room.jid] and visitors_promotion_map[room.jid][jid.node(stanza.attr.from)] then+ -- allow join+ return;+ end++ origin.send(st.error_reply(stanza, 'cancel', 'not-allowed', 'Visitor needs to be allowed by a moderator'));+ return true;+ end++ end, 7); -- after muc_meeting_id, the logic for not joining before jicofo+ host_module:hook('muc-room-destroyed', function (event)+ visitors_promotion_map[event.room.jid] = nil;+ end);+end);++-- enable only in case of auto-allow is enabled+if auto_allow_promotion then+ prosody.events.add_handler("pre-jitsi-authentication", function(session)+ if not session.customusername or not session.jitsi_web_query_room then+ return nil;+ end++ local room = get_room_by_name_and_subdomain(session.jitsi_web_query_room, session.jitsi_web_query_prefix);+ if not room then+ return nil;+ end++ if visitors_promotion_map[room.jid] and visitors_promotion_map[room.jid][session.customusername] then+ -- user was previously allowed to join, let him use the requested jid+ return session.customusername;+ end+ end);+enddiff --git a/resources/prosody-plugins/util.lib.lua b/resources/prosody-plugins/util.lib.luaindex f35c451d6a..d3c5292e6b 100644--- a/resources/prosody-plugins/util.lib.lua+++ b/resources/prosody-plugins/util.lib.lua@@ -372,10 +372,30 @@ function presence_check_status(muc_x, status)return false;end+-- Retrieves the focus from the room and cache it in the room object+-- @param room The room name for which to find the occupant+local function get_focus_occupant(room)+ local focus_occupant = room._data.focus_occupant;++ if focus_occupant then+ return focus_occupant;+ end++ for _, n_occupant in room:each_occupant() do+ if jid.node(n_occupant.jid) == 'focus' then+ room._data.focus_occupant = n_occupant;+ return n_occupant;+ end+ end++ return nil;+end+return {extract_subdomain = extract_subdomain;is_feature_allowed = is_feature_allowed;is_healthcheck_room = is_healthcheck_room;+ get_focus_occupant = get_focus_occupant;get_room_from_jid = get_room_from_jid;get_room_by_name_and_subdomain = get_room_by_name_and_subdomain;async_handler_wrapper = async_handler_wrapper;