Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(visitors): Transcriptions for visitors. (#15119)

Дамян Минковede26956e8cd
diff --git a/react/features/base/jwt/constants.ts b/react/features/base/jwt/constants.ts
index 7c1d6487ec..dd1abc8dff 100644
--- a/react/features/base/jwt/constants.ts
+++ b/react/features/base/jwt/constants.ts
@@ -18,15 +18,6 @@ export const MEET_FEATURES = {
TRANSCRIPTION: 'transcription'
};
-/**
- * A mapping between jwt features and toolbar buttons keys.
- * We don't need recording in here, as it will disable the local recording too.
- */
-export const FEATURES_TO_BUTTONS_MAPPING = {
- 'livestreaming': 'livestreaming',
- 'transcription': 'closedcaptions'
-};
-
/**
* The JWT validation errors for JaaS.
*/
diff --git a/react/features/toolbox/components/web/Toolbox.tsx b/react/features/toolbox/components/web/Toolbox.tsx
index d5adec8bdb..6ec5a73db9 100644
--- a/react/features/toolbox/components/web/Toolbox.tsx
+++ b/react/features/toolbox/components/web/Toolbox.tsx
@@ -99,7 +99,8 @@ export default function Toolbox({
const isDialogVisible = useSelector((state: IReduxState) => Boolean(state['features/base/dialog'].component));
const jwt = useSelector((state: IReduxState) => state['features/base/jwt'].jwt);
const localParticipant = useSelector(getLocalParticipant);
- const jwtDisabledButtons = getJwtDisabledButtons(jwt, localParticipant?.features);
+ const jwtDisabledButtons = useSelector((state: IReduxState) =>
+ getJwtDisabledButtons(state, jwt, localParticipant?.features));
const reactionsButtonEnabled = useSelector(isReactionsButtonEnabled);
const _shouldDisplayReactionsButtons = useSelector(shouldDisplayReactionsButtons);
const toolbarVisible = useSelector(isToolboxVisible);
diff --git a/react/features/toolbox/constants.ts b/react/features/toolbox/constants.ts
index b70e37f5ce..8cafff08a5 100644
--- a/react/features/toolbox/constants.ts
+++ b/react/features/toolbox/constants.ts
@@ -133,6 +133,7 @@ export const TOOLBAR_BUTTONS: ToolbarButton[] = [
*/
export const VISITORS_MODE_BUTTONS: ToolbarButton[] = [
'chat',
+ 'closedcaptions',
'hangup',
'raisehand',
'settings',
diff --git a/react/features/toolbox/functions.any.ts b/react/features/toolbox/functions.any.ts
index 781958e39f..e8a180cff3 100644
--- a/react/features/toolbox/functions.any.ts
+++ b/react/features/toolbox/functions.any.ts
@@ -1,8 +1,8 @@
import { IReduxState } from '../app/types';
-import { FEATURES_TO_BUTTONS_MAPPING } from '../base/jwt/constants';
import { isJwtFeatureEnabledStateless } from '../base/jwt/functions';
import { IGUMPendingState } from '../base/media/types';
import { IParticipantFeatures } from '../base/participants/types';
+import { isTranscribing } from '../transcribing/functions';
/**
* Indicates if the audio mute button is disabled or not.
@@ -20,21 +20,34 @@ export function isAudioMuteButtonDisabled(state: IReduxState) {
/**
* Returns the buttons corresponding to features disabled through jwt.
*
+ * @param {IReduxState} state - The state from the Redux store.
* @param {string | undefined} jwt - The jwt token.
* @param {ILocalParticipant} localParticipantFeatures - The features of the local participant.
* @returns {string[]} - The disabled by jwt buttons array.
*/
-export function getJwtDisabledButtons(jwt: string | undefined, localParticipantFeatures?: IParticipantFeatures) {
- return Object.keys(FEATURES_TO_BUTTONS_MAPPING).reduce((acc: string[], current: string) => {
- if (!isJwtFeatureEnabledStateless({
- jwt,
- localParticipantFeatures,
- feature: current,
- ifNoToken: true
- })) {
- acc.push(FEATURES_TO_BUTTONS_MAPPING[current as keyof typeof FEATURES_TO_BUTTONS_MAPPING]);
- }
+export function getJwtDisabledButtons(
+ state: IReduxState,
+ jwt: string | undefined,
+ localParticipantFeatures?: IParticipantFeatures) {
+ const acc = [];
+
+ if (!isJwtFeatureEnabledStateless({
+ jwt,
+ localParticipantFeatures,
+ feature: 'livestreaming',
+ ifNoToken: true
+ })) {
+ acc.push('livestreaming');
+ }
+
+ if (!isTranscribing(state) && !isJwtFeatureEnabledStateless({
+ jwt,
+ localParticipantFeatures,
+ feature: 'transcription',
+ ifNoToken: true
+ })) {
+ acc.push('closedcaptions');
+ }
- return acc;
- }, []);
+ return acc;
}
diff --git a/resources/prosody-plugins/mod_filter_iq_rayo.lua b/resources/prosody-plugins/mod_filter_iq_rayo.lua
index 535f024f4a..add3de1126 100644
--- a/resources/prosody-plugins/mod_filter_iq_rayo.lua
+++ b/resources/prosody-plugins/mod_filter_iq_rayo.lua
@@ -1,6 +1,7 @@
-- This module is enabled under the main virtual host
local new_throttle = require "util.throttle".create;
local st = require "util.stanza";
+local jid = require "util.jid";
local token_util = module:require "token/util".new(module);
local util = module:require 'util';
@@ -29,6 +30,14 @@ if token_util == nil then
return;
end
+-- this is the main virtual host of the main prosody that this vnode serves
+local main_domain = module:get_option_string('main_domain');
+-- only the visitor prosody has main_domain setting
+local is_visitor_prosody = main_domain ~= nil;
+
+-- this is the main virtual host of this vnode
+local local_domain = module:get_option_string('muc_mapper_domain_base');
+
local um_is_admin = require 'core.usermanager'.is_admin;
local function is_admin(jid)
return um_is_admin(jid, module.host);
@@ -45,6 +54,8 @@ load_config();
-- Header names to use to push extra data extracted from token, if any
local OUT_INITIATOR_USER_ATTR_NAME = "X-outbound-call-initiator-user";
local OUT_INITIATOR_GROUP_ATTR_NAME = "X-outbound-call-initiator-group";
+local OUT_ROOM_NAME_ATTR_NAME = "JvbRoomName";
+
local OUTGOING_CALLS_THROTTLE_INTERVAL = 60; -- if max_number_outgoing_calls is enabled it will be
-- the max number of outgoing calls a user can try for a minute
@@ -60,18 +71,33 @@ module:hook("pre-iq/full", function(event)
local token = session.auth_token;
-- find header with attr name 'JvbRoomName' and extract its value
- local headerName = 'JvbRoomName';
local roomName;
- for _, child in ipairs(dial.tags) do
- if (child.name == 'header'
- and child.attr.name == headerName) then
- roomName = child.attr.value;
- break;
+ -- Remove any 'header' element if it already exists, so it cannot be spoofed by a client
+ dial:maptags(function(tag)
+ if tag.name == "header"
+ and (tag.attr.name == OUT_INITIATOR_USER_ATTR_NAME
+ or tag.attr.name == OUT_INITIATOR_GROUP_ATTR_NAME) then
+ return nil
+ elseif tag.name == "header" and tag.attr.name == OUT_ROOM_NAME_ATTR_NAME then
+ roomName = tag.attr.value;
+ -- we will remove it as we will add it later, modified
+ if is_visitor_prosody then
+ return nil;
+ end
end
- end
+ return tag
+ end);
- local room_real_jid = room_jid_match_rewrite(roomName);
+ local room_jid = jid.bare(stanza.attr.to);
+ local room_real_jid = room_jid_match_rewrite(room_jid);
local room = main_muc_service.get_room_from_jid(room_real_jid);
+ local is_sender_in_room = room:get_occupant_jid(stanza.attr.from) ~= nil;
+
+ if not room or not is_sender_in_room then
+ module:log("warn", "Filtering stanza dial, stanza:%s", tostring(stanza));
+ session.send(st.error_reply(stanza, "auth", "forbidden"));
+ return true;
+ end
local feature = dial.attr.to == 'jitsi_meet_transcribe' and 'transcription' or 'outbound-call';
local is_session_allowed = is_feature_allowed(
@@ -81,6 +107,7 @@ module:hook("pre-iq/full", function(event)
room:get_affiliation(stanza.attr.from) == 'owner');
if roomName == nil
+ or roomName ~= room_jid
or (token ~= nil and not token_util:verify_room(session, room_real_jid))
or not is_session_allowed
then
@@ -119,20 +146,6 @@ module:hook("pre-iq/full", function(event)
-- now lets insert token information if any
if session and user_id then
- -- First remove any 'header' element if it already
- -- exists, so it cannot be spoofed by a client
- stanza:maptags(
- function(tag)
- if tag.name == "header"
- and (tag.attr.name == OUT_INITIATOR_USER_ATTR_NAME
- or tag.attr.name == OUT_INITIATOR_GROUP_ATTR_NAME) then
- return nil
- end
- return tag
- end
- )
-
- local dial = stanza:get_child('dial', 'urn:xmpp:rayo:1');
-- adds initiator user id from token
dial:tag("header", {
xmlns = "urn:xmpp:rayo:1",
@@ -149,9 +162,18 @@ module:hook("pre-iq/full", function(event)
dial:up();
end
end
+
+ -- we want to instruct jigasi to enter the main room, so send the correct main room jid
+ if is_visitor_prosody then
+ dial:tag("header", {
+ xmlns = "urn:xmpp:rayo:1",
+ name = OUT_ROOM_NAME_ATTR_NAME,
+ value = string.gsub(roomName, local_domain, main_domain) });
+ dial:up();
+ end
end
end
-end);
+end, 1); -- make sure we run before domain mapper
--- Finds and returns the number of concurrent outgoing calls for a user
-- @param context_user the user id extracted from the token
diff --git a/resources/prosody-plugins/mod_fmuc.lua b/resources/prosody-plugins/mod_fmuc.lua
index e1588ccd73..e0325d6325 100644
--- a/resources/prosody-plugins/mod_fmuc.lua
+++ b/resources/prosody-plugins/mod_fmuc.lua
@@ -14,6 +14,7 @@ local jid = require 'util.jid';
local st = require 'util.stanza';
local new_id = require 'util.id'.medium;
local filters = require 'util.filters';
+local array = require"util.array";
local util = module:require 'util';
local ends_with = util.ends_with;
@@ -24,6 +25,11 @@ local get_focus_occupant = util.get_focus_occupant;
local internal_room_jid_match_rewrite = util.internal_room_jid_match_rewrite;
local presence_check_status = util.presence_check_status;
+local PARTICIPANT_PROP_RAISE_HAND = 'jitsi_participant_raisedHand';
+local PARTICIPANT_PROP_REQUEST_TRANSCRIPTION = 'jitsi_participant_requestingTranscription';
+local PARTICIPANT_PROP_TRANSLATION_LANG = 'jitsi_participant_translation_language';
+local TRANSCRIPT_DEFAULT_LANG = module:get_option_string('transcriptions_default_language', 'en');
+
-- this is the main virtual host of this vnode
local local_domain = module:get_option_string('muc_mapper_domain_base');
if not local_domain then
@@ -60,6 +66,62 @@ local function is_admin(jid)
return um_is_admin(jid, module.host);
end
+local function send_transcriptions_update(room)
+ -- let's notify main prosody
+ local lang_array = array{};
+ local count = 0;
+
+ for k, v in pairs(room._transcription_languages) do
+ if not lang_array[v] then
+ lang_array:push(v);
+ end
+ count = count + 1;
+ end
+
+ local iq_id = new_id();
+ sent_iq_cache:set(iq_id, socket.gettime());
+ module:send(st.iq({
+ type = 'set',
+ to = 'visitors.'..main_domain,
+ from = local_domain,
+ id = iq_id })
+ :tag('visitors', { xmlns = 'jitsi:visitors',
+ room = jid.join(jid.node(room.jid), muc_domain_prefix..'.'..main_domain) })
+ :tag('transcription-languages', {
+ xmlns = 'jitsi:visitors',
+ langs = lang_array:sort():concat(','),
+ count = tostring(count)
+ }):up());
+end
+
+local function remove_transcription(room, occupant)
+ local send_update = false;
+ if room._transcription_languages then
+ if room._transcription_languages[occupant.jid] then
+ send_update = true;
+ end
+ room._transcription_languages[occupant.jid] = nil;
+ end
+
+ if send_update then
+ send_transcriptions_update(room);
+ end
+end
+
+-- if lang is nil we will remove it from the list
+local function add_transcription(room, occupant, lang)
+ if not room._transcription_languages then
+ room._transcription_languages = {};
+ end
+
+ local old = room._transcription_languages[occupant.jid];
+ room._transcription_languages[occupant.jid] = lang or TRANSCRIPT_DEFAULT_LANG;
+
+ if old ~= room._transcription_languages[occupant.jid] then
+ send_transcriptions_update(room);
+ end
+end
+
-- mark all occupants as visitors
module:hook('muc-occupant-pre-join', function (event)
local occupant, room, origin, stanza = event.occupant, event.room, event.origin, event.stanza;
@@ -92,7 +154,7 @@ module:hook('muc-occupant-pre-leave', function (event)
-- to main prosody
local pr = occupant:get_presence();
- local raiseHand = pr:get_child_text('jitsi_participant_raisedHand');
+ local raiseHand = pr:get_child_text(PARTICIPANT_PROP_RAISE_HAND);
-- a promotion detected let's send it to main prosody
if raiseHand and #raiseHand > 0 then
@@ -114,6 +176,7 @@ module:hook('muc-occupant-pre-leave', function (event)
module:send(promotion_request);
end
+ remove_transcription(room, occupant);
end, 1); -- rate limit is 0
-- Returns the main participants count and the visitors count
@@ -201,6 +264,7 @@ end);
-- forward visitor presences to jicofo
-- detects raise hand in visitors presence, this is request for promotion
+-- detects the requested transcription and its language to send updates for it
module:hook('muc-broadcast-presence', function (event)
local occupant = event.occupant;
@@ -230,7 +294,7 @@ module:hook('muc-broadcast-presence', function (event)
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');
+ local raiseHand = full_p:get_child_text(PARTICIPANT_PROP_RAISE_HAND);
-- a promotion detected let's send it to main prosody
if raiseHand then
local user_id;
@@ -286,6 +350,18 @@ module:hook('muc-broadcast-presence', function (event)
module:send(promotion_request);
end
+ -- detect transcription
+ if full_p:get_child_text(PARTICIPANT_PROP_REQUEST_TRANSCRIPTION) then
+ local lang = full_p:get_child_text(PARTICIPANT_PROP_TRANSLATION_LANG);
+
+ occupant._transcription_enabled = true;
+
+ add_transcription(room, occupant, lang);
+ elseif occupant._transcription_enabled then
+ occupant._transcription_enabled = false;
+ remove_transcription(room, occupant, nil);
+ end
+
return;
end);
diff --git a/resources/prosody-plugins/mod_visitors.lua b/resources/prosody-plugins/mod_visitors.lua
index 80701004e9..d97b6cab5f 100644
--- a/resources/prosody-plugins/mod_visitors.lua
+++ b/resources/prosody-plugins/mod_visitors.lua
@@ -14,6 +14,7 @@ local new_id = require 'util.id'.medium;
local util = module:require 'util';
local presence_check_status = util.presence_check_status;
local process_host_module = util.process_host_module;
+local is_transcriber_jigasi = util.is_transcriber_jigasi;
local um_is_admin = require 'core.usermanager'.is_admin;
local function is_admin(jid)
@@ -185,7 +186,7 @@ process_host_module(main_muc_component_config, function(host_module, host)
-- filter focus and configured domains (used for jibri and transcribers)
if is_admin(stanza.attr.from) or visitors_nodes[room.jid] == nil
- or ignore_list:contains(jid.host(occupant.bare_jid)) then
+ or (ignore_list:contains(jid.host(occupant.bare_jid)) and not is_transcriber_jigasi(stanza)) then
return;
end
@@ -206,7 +207,7 @@ process_host_module(main_muc_component_config, function(host_module, host)
-- ignore configured domains (jibri and transcribers)
if is_admin(occupant.bare_jid) or visitors_nodes[room.jid] == nil or visitors_nodes[room.jid].nodes == nil
- or ignore_list:contains(jid.host(occupant.bare_jid)) then
+ or (ignore_list:contains(jid.host(occupant.bare_jid)) and not is_transcriber_jigasi(stanza)) then
return;
end
@@ -249,7 +250,7 @@ process_host_module(main_muc_component_config, function(host_module, host)
-- filter focus, ignore configured domains (jibri and transcribers)
if is_admin(stanza.attr.from) or visitors_nodes[room.jid] == nil
- or ignore_list:contains(jid.host(occupant.bare_jid)) then
+ or (ignore_list:contains(jid.host(occupant.bare_jid)) and not is_transcriber_jigasi(stanza)) then
return;
end
@@ -268,7 +269,7 @@ process_host_module(main_muc_component_config, function(host_module, host)
local room, stanza, occupant = event.room, event.stanza, event.occupant;
-- filter sending messages from transcribers/jibris to visitors
- if not visitors_nodes[room.jid] or ignore_list:contains(jid.host(occupant.bare_jid)) then
+ if not visitors_nodes[room.jid] then
return;
end
diff --git a/resources/prosody-plugins/mod_visitors_component.lua b/resources/prosody-plugins/mod_visitors_component.lua
index 4d52ccc0ac..23ae1c897d 100644
--- a/resources/prosody-plugins/mod_visitors_component.lua
+++ b/resources/prosody-plugins/mod_visitors_component.lua
@@ -1,5 +1,6 @@
module:log('info', 'Starting visitors_component at %s', module.host);
+local array = require "util.array";
local http = require 'net.http';
local jid = require 'util.jid';
local st = require 'util.stanza';
@@ -14,6 +15,7 @@ local internal_room_jid_match_rewrite = util.internal_room_jid_match_rewrite;
local is_vpaas = util.is_vpaas;
local is_sip_jibri_join = util.is_sip_jibri_join;
local process_host_module = util.process_host_module;
+local split_string = util.split_string;
local new_id = require 'util.id'.medium;
local um_is_admin = require 'core.usermanager'.is_admin;
local json = require 'cjson.safe';
@@ -179,7 +181,7 @@ local function connect_vnode_received(room, vnode)
room._connected_vnodes = cache.new(16); -- we up to 16 vnodes for this prosody
end
- room._connected_vnodes:set(vnode..'.meet.jitsi', 'connected');
+ room._connected_vnodes:set(vnode..'.meet.jitsi', {});
end
local function disconnect_vnode_received(room, vnode)
@@ -194,6 +196,34 @@ local function disconnect_vnode_received(room, vnode)
end
end
+-- returns the accumulated data for visitors nodes, count all visitors requesting transcriptions
+-- and accumulated languages requested
+-- @returns count, languages
+function get_visitors_languages(room)
+ if not room._connected_vnodes then
+ return;
+ end
+
+ local count = 0;
+ local languages = array();
+
+ -- iterate over visitor nodes we are connected to and accumulate data if we have it
+ for k, v in room._connected_vnodes:items() do
+ if v.count then
+ count = count + v.count;
+ end
+ if v.langs then
+ for k in pairs(v.langs) do
+ local val = v.langs[k]
+ if not languages[val] then
+ languages:push(val);
+ end
+ end
+ end
+ end
+ return count, languages:sort():concat(',');
+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 it
local function stanza_handler(event)
@@ -232,12 +262,17 @@ local function stanza_handler(event)
return;
end
+ local from_vnode;
+ if room._connected_vnodes then
+ from_vnode = room._connected_vnodes:get(stanza.attr.from);
+ end
+
local processed;
-- promotion request is coming from visitors and is a set and is over the s2s connection
local request_promotion = visitors_iq:get_child('promotion-request');
if request_promotion then
- if not (room._connected_vnodes and room._connected_vnodes:get(stanza.attr.from)) then
- module:log('warn', 'Received forged promotion-request: %s %s %s', stanza, inspect(room._connected_vnodes), room._connected_vnodes:get(stanza.attr.from));
+ if not from_vnode then
+ module:log('warn', 'Received forged request_promotion message: %s %s',stanza, inspect(room._connected_vnodes));
return true; -- stop processing
end
@@ -266,6 +301,44 @@ local function stanza_handler(event)
end
end
+ -- request to update metadata service for jigasi languages
+ local transcription_languages = visitors_iq:get_child('transcription-languages');
+
+ if transcription_languages
+ and (transcription_languages.attr.langs or transcription_languages.attr.count) then
+ if not from_vnode then
+ module:log('warn', 'Received forged transcription_languages message: %s %s',stanza, inspect(room._connected_vnodes));
+ return true; -- stop processing
+ end
+ if not room.jitsiMetadata then
+ room.jitsiMetadata = {};
+ end
+ if not room.jitsiMetadata.visitors then
+ room.jitsiMetadata.visitors = {};
+ end
+
+ -- we keep the split by languages array to optimize accumulating languages
+ from_vnode.langs = split_string(transcription_languages.attr.langs, ',');
+ from_vnode.count = transcription_languages.attr.count;
+
+ local count, languages = get_visitors_languages(room);
+
+ if room.jitsiMetadata.visitors.transcribingLanguages ~= languages then
+ room.jitsiMetadata.visitors.transcribingLanguages = languages;
+ processed = true;
+ end
+
+ if room.jitsiMetadata.visitors.transcribingCount ~= count then
+ room.jitsiMetadata.visitors.transcribingCount = count;
+ processed = true;
+ end
+
+ if processed then
+ module:context(muc_domain_prefix..'.'..muc_domain_base)
+ :fire_event('room-metadata-changed', { room = room; });
+ end
+ end
+
if not processed then
module:log('warn', 'Unknown iq received for %s: %s', module.host, stanza);
end
diff --git a/resources/prosody-plugins/util.lib.lua b/resources/prosody-plugins/util.lib.lua
index d7f07c1a17..ce0ed1c068 100644
--- a/resources/prosody-plugins/util.lib.lua
+++ b/resources/prosody-plugins/util.lib.lua
@@ -2,6 +2,7 @@ local jid = require "util.jid";
local timer = require "util.timer";
local http = require "net.http";
local cache = require "util.cache";
+local array = require "util.array";
local http_timeout = 30;
local have_async, async = pcall(require, "util.async");
@@ -473,6 +474,23 @@ function is_sip_jigasi(stanza)
return stanza:get_child('initiator', 'http://jitsi.org/protocol/jigasi');
end
+function is_transcriber_jigasi(stanza)
+ local features = stanza:get_child('features');
+ if not features then
+ return false;
+ end
+
+ for i = 1, #features do
+ local feature = features[i];
+ if feature.attr and feature.attr.var and feature.attr.var == 'http://jitsi.org/protocol/transcriber' then
+ return true;
+ end
+ end
+
+ return false;
+end
+
+
function get_sip_jibri_email_prefix(email)
if not email then
return nil;
@@ -537,6 +555,17 @@ function table_shallow_copy(t)
return t2
end
+-- Splits a string using delimiter
+function split_string(str, delimiter)
+ str = str .. delimiter;
+ local result = array();
+ for w in str:gmatch("(.-)" .. delimiter) do
+ result:push(w);
+ end
+
+ return result;
+end
+
return {
OUTBOUND_SIP_JIBRI_PREFIXES = OUTBOUND_SIP_JIBRI_PREFIXES;
INBOUND_SIP_JIBRI_PREFIXES = INBOUND_SIP_JIBRI_PREFIXES;
@@ -546,6 +575,7 @@ return {
is_moderated = is_moderated;
is_sip_jibri_join = is_sip_jibri_join;
is_sip_jigasi = is_sip_jigasi;
+ is_transcriber_jigasi = is_transcriber_jigasi;
is_vpaas = is_vpaas;
get_focus_occupant = get_focus_occupant;
get_room_from_jid = get_room_from_jid;
@@ -560,6 +590,7 @@ return {
update_presence_identity = update_presence_identity;
http_get_with_retry = http_get_with_retry;
ends_with = ends_with;
+ split_string = split_string;
starts_with = starts_with;
starts_with_one_of = starts_with_one_of;
table_shallow_copy = table_shallow_copy;