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(audio-translation): ring and listener count for speakers whose translation is still playing (#17683)

Jaya Allamsetty8269c7737909
diff --git a/lang/main.json b/lang/main.json
index 9d6cc1e0fc..6d4e7cc746 100644
--- a/lang/main.json
+++ b/lang/main.json
@@ -1662,6 +1662,9 @@
"showSelfView": "Show self view",
"translationEnabledForYou": "Translation enabled for you",
"translationOnAndReceiving": "Translation on · receiving",
+ "translationStillListening": "{{count}} participant is still hearing the translation — wait before speaking",
+ "translationStillListeningShort": "{{num}} still listening",
+ "translationStillListening_plural": "{{count}} participants are still hearing the translation — wait before speaking",
"unpinFromStage": "Unpin",
"verify": "Verify participant",
"videoMuted": "Camera disabled",
diff --git a/react/features/audio-translation/functions.ts b/react/features/audio-translation/functions.ts
index 5f2443e063..cc1290476e 100644
--- a/react/features/audio-translation/functions.ts
+++ b/react/features/audio-translation/functions.ts
@@ -31,6 +31,18 @@ export function isParticipantAudioTranslationActive(state: IReduxState, particip
return state['features/audio-translation'].translationListeners.includes(participantId);
}
+/**
+ * The target language encoded in a translated source name — the substring after the last {@code .}.
+ *
+ * @param {string} sourceName - The translated source name.
+ * @returns {string}
+ */
+export function getSourceLanguage(sourceName: string): string {
+ const dotIndex = sourceName.lastIndexOf('.');
+
+ return dotIndex === -1 ? '' : sourceName.substring(dotIndex + 1);
+}
+
/**
* The owner endpoint id encoded in a translated source name — the substring before the first {@code -}.
* Translated sources follow the {@code <endpointId>-a<idx>.<lang>} convention (endpoint ids are dash/dot-free).
@@ -46,16 +58,26 @@ export function getSourceOwnerEndpointId(sourceName: string): string {
}
/**
- * Whether the bridge is currently forwarding any translated audio owned by the given participant to us (i.e. we
- * are hearing that participant translated), per the {@code receivingSources} set.
+ * Whether we are hearing the given participant translated. The bridge floods sending changes to every
+ * endpoint, so {@code receivingSources} is every translated source in flight anywhere, not just ours; a
+ * source counts as ours only when its language matches the one we selected for this participant.
*
* @param {IReduxState} state - The redux state.
* @param {string} participantId - The participant (endpoint) id to check.
* @returns {boolean}
*/
export function isReceivingTranslationFrom(state: IReduxState, participantId: string): boolean {
+ const language = getEffectiveTranslationLanguage(state, participantId);
+
+ // The bridge announces sending changes to every endpoint, so a source being in flight does not mean we
+ // subscribed to it; require our own selection for this speaker to match the source's language.
+ if (!language) {
+ return false;
+ }
+
return state['features/audio-translation'].receivingSources
- .some(sourceName => getSourceOwnerEndpointId(sourceName) === participantId);
+ .some(sourceName => getSourceOwnerEndpointId(sourceName) === participantId
+ && sourceName.endsWith(`.${language}`));
}
/**
@@ -235,3 +257,45 @@ export function getDuckedVolumeForParticipant(state: IReduxState, participantId?
return typeof userVolume === 'number' ? Math.min(userVolume, duckedVolume) : duckedVolume;
}
+
+/**
+ * The number of participants still hearing the given speaker's translated audio, as published by that
+ * speaker. 0 when nothing is pending or the speaker's client does not publish the count.
+ *
+ * @param {IReduxState} state - The redux state.
+ * @param {string} participantId - The speaker's participant id.
+ * @returns {number}
+ */
+export function getTranslationDeliveryPendingCount(state: IReduxState, participantId: string): number {
+ const counts = state['features/base/conference'].metadata?.audioTranslationListenerCounts?.[participantId];
+
+ if (!counts) {
+ return 0;
+ }
+
+ // Sum the subscribers of only the languages the bridge is still sending for this speaker: the in-flight
+ // language count alone undercounts (one source serves every listener of that language) and the speaker's
+ // subscriber total overcounts (a language whose stream already finished).
+ return state['features/audio-translation'].receivingSources.reduce((total, sourceName) =>
+ getSourceOwnerEndpointId(sourceName) === participantId
+ ? total + (counts[getSourceLanguage(sourceName)] ?? 0)
+ : total, 0);
+}
+
+/**
+ * Whether translated audio for the given speaker is still being delivered, so others should wait before
+ * speaking. Falls back to any in-flight translated source owned by the speaker, so the ring still shows when
+ * the speaker's client does not publish a count.
+ *
+ * @param {IReduxState} state - The redux state.
+ * @param {string} participantId - The speaker's participant id.
+ * @returns {boolean}
+ */
+export function isTranslationDeliveryPending(state: IReduxState, participantId: string): boolean {
+ if (getTranslationDeliveryPendingCount(state, participantId) > 0) {
+ return true;
+ }
+
+ return state['features/audio-translation'].receivingSources
+ .some(sourceName => getSourceOwnerEndpointId(sourceName) === participantId);
+}
diff --git a/react/features/audio-translation/middleware.any.ts b/react/features/audio-translation/middleware.any.ts
index 5a43766c4d..f7fc1606fc 100644
--- a/react/features/audio-translation/middleware.any.ts
+++ b/react/features/audio-translation/middleware.any.ts
@@ -1,5 +1,4 @@
import { JitsiAudioTranslationErrors, JitsiConferenceEvents } from '../base/lib-jitsi-meet';
-import { getLocalParticipant } from '../base/participants/functions';
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
import StateListenerRegistry from '../base/redux/StateListenerRegistry';
import { showErrorNotification, showNotification } from '../notifications/actions';
@@ -16,7 +15,7 @@ import {
setTranslationListeners,
updateTranslatedSourceSending
} from './actions';
-import { getSourceOwnerEndpointId, isAudioTranslationRoomEnabled } from './functions';
+import { isAudioTranslationRoomEnabled } from './functions';
import logger from './logger';
/**
@@ -31,6 +30,7 @@ const ERROR_NOTIFICATION_KEYS: { [condition: string]: string; } = {
const DEFAULT_ERROR_KEY = 'audioTranslation.errorGeneric';
+
/**
* Middleware that drives the bridge-side translation when the local user changes
* the default or a per-participant audio-translation target language.
@@ -135,11 +135,6 @@ StateListenerRegistry.register(
return;
}
- // The bridge broadcasts sending changes to every endpoint, including the translated
- // participant itself; our own translated source is not audio we receive.
- if (getSourceOwnerEndpointId(sourceName) === getLocalParticipant(getState())?.id) {
- return;
- }
dispatch(updateTranslatedSourceSending(sourceName, sending, timestamp));
});
diff --git a/react/features/base/conference/reducer.ts b/react/features/base/conference/reducer.ts
index d03667c2b8..1a29b71c03 100644
--- a/react/features/base/conference/reducer.ts
+++ b/react/features/base/conference/reducer.ts
@@ -64,6 +64,13 @@ export interface IConferenceMetadata {
* means available.
*/
audioTranslationAvailable?: boolean;
+
+ /**
+ * Per-speaker, per-language count of participants subscribed to that speaker's translated audio, published
+ * by the audio-translation component. Combined with the bridge's synthetic-source sending state to show how
+ * many participants are still hearing a speaker.
+ */
+ audioTranslationListenerCounts?: { [senderId: string]: { [language: string]: number; }; };
dialinEnabled?: boolean;
files: {
[fileId: string]: {
diff --git a/react/features/filmstrip/components/web/Thumbnail.tsx b/react/features/filmstrip/components/web/Thumbnail.tsx
index da14e0ddd2..09c3473ee9 100644
--- a/react/features/filmstrip/components/web/Thumbnail.tsx
+++ b/react/features/filmstrip/components/web/Thumbnail.tsx
@@ -4,11 +4,13 @@ import { debounce } from 'lodash-es';
import React, { Component, KeyboardEvent, RefObject, createRef } from 'react';
import { WithTranslation } from 'react-i18next';
import { connect } from 'react-redux';
+import { keyframes } from 'tss-react';
import { withStyles } from 'tss-react/mui';
import { createScreenSharingIssueEvent } from '../../../analytics/AnalyticsEvents';
import { sendAnalytics } from '../../../analytics/functions';
import { IReduxState, IStore } from '../../../app/types';
+import { isTranslationDeliveryPending } from '../../../audio-translation/functions';
import Avatar from '../../../base/avatar/components/Avatar';
import { isMobileBrowser } from '../../../base/environment/utils';
import { translate } from '../../../base/i18n/functions';
@@ -61,6 +63,7 @@ import {
import ThumbnailAudioIndicator from './ThumbnailAudioIndicator';
import ThumbnailBottomIndicators from './ThumbnailBottomIndicators';
import ThumbnailTopIndicators from './ThumbnailTopIndicators';
+import TranslationPendingChip from './TranslationPendingChip';
import VirtualScreenshareParticipant from './VirtualScreenshareParticipant';
/**
@@ -203,6 +206,12 @@ export interface IProps extends WithTranslation {
*/
_thumbnailType: string;
+ /**
+ * Whether translated audio from this participant is still reaching other participants, so anyone about to
+ * speak should wait. Takes precedence over the dominant-speaker ring.
+ */
+ _translationDeliveryPending: boolean;
+
/**
* The video object position for the participant.
*/
@@ -326,6 +335,29 @@ const defaultStyles = (theme: Theme) => {
}
},
+ translationPending: {
+ '& .translation-pending-border': {
+ animation: `${keyframes`
+ 0% {
+ opacity: 0.45;
+ }
+ 50% {
+ opacity: 1;
+ }
+ 100% {
+ opacity: 0.45;
+ }
+ `} 1.6s ease-in-out infinite`,
+ outline: '3px dashed #F8AE1A',
+ outlineOffset: '-1.5px',
+
+ '@media (prefers-reduced-motion: reduce)': {
+ animation: 'none',
+ opacity: 0.85
+ }
+ }
+ },
+
raisedHand: {
'& .raised-hand-border': {
boxShadow: `inset 0px 0px 0px 2px ${theme.palette.warning02} !important`
@@ -887,7 +919,10 @@ class Thumbnail extends Component<IProps, IState> {
className += ` ${classes.raisedHand}`;
}
- if (!_isDominantSpeakerDisabled && _participant?.dominantSpeaker) {
+ if (this.props._translationDeliveryPending) {
+ // Others are still hearing this speaker translated; this ring replaces the dominant-speaker one.
+ className += ` ${classes.translationPending}`;
+ } else if (!_isDominantSpeakerDisabled && _participant?.dominantSpeaker) {
className += ` ${classes.activeSpeaker} dominant-speaker`;
}
if (_thumbnailType !== THUMBNAIL_TYPE.TILE && _participant?.pinned) {
@@ -1086,6 +1121,13 @@ class Thumbnail extends Component<IProps, IState> {
className = { clsx(classes.borderIndicator,
_gifSrc && classes.borderIndicatorOnTop,
'active-speaker-indicator') } />
+ <div
+ className = { clsx(classes.borderIndicator,
+ _gifSrc && classes.borderIndicatorOnTop,
+ 'translation-pending-border') } />
+ <TranslationPendingChip
+ participantId = { id }
+ thumbnailType = { _thumbnailType } />
{_gifSrc && (
<div
className = { clsx(classes.borderIndicator, classes.borderIndicatorOnTop) }
@@ -1322,6 +1364,7 @@ function _mapStateToProps(state: IReduxState, ownProps: any): Object {
_stageFilmstripLayout: isStageFilmstripAvailable(state),
_stageParticipantsVisible: _currentLayout === LAYOUTS.STAGE_FILMSTRIP_VIEW,
_shouldDisplayTintBackground: !disableTintForeground && shouldDisplayTintBackground,
+ _translationDeliveryPending: isTranslationDeliveryPending(state, id),
_thumbnailType: tileType,
_videoObjectPosition: getVideoObjectPosition(state, participant?.id),
_videoTrack,
diff --git a/react/features/filmstrip/components/web/TranslationPendingChip.tsx b/react/features/filmstrip/components/web/TranslationPendingChip.tsx
new file mode 100644
index 0000000000..5e222344df
--- /dev/null
+++ b/react/features/filmstrip/components/web/TranslationPendingChip.tsx
@@ -0,0 +1,113 @@
+import React from 'react';
+import { useTranslation } from 'react-i18next';
+import { useSelector } from 'react-redux';
+import { keyframes } from 'tss-react';
+import { makeStyles } from 'tss-react/mui';
+
+import { IReduxState } from '../../../app/types';
+import { getTranslationDeliveryPendingCount } from '../../../audio-translation/functions';
+import { THUMBNAIL_TYPE } from '../../constants';
+
+/**
+ * Amber, deliberately not the dominant-speaker blue.
+ */
+const PENDING_COLOR = '#F8AE1A';
+
+interface IProps {
+
+ /**
+ * The speaker whose translated audio is still being delivered.
+ */
+ participantId: string;
+
+ /**
+ * The type of thumbnail; drives the compact (count-only) form.
+ */
+ thumbnailType?: string;
+}
+
+const useStyles = makeStyles()(() => {
+ const breathe = keyframes`
+ 0% { opacity: 0.45; }
+ 50% { opacity: 1; }
+ 100% { opacity: 0.45; }
+ `;
+
+ return {
+ chip: {
+ alignItems: 'center',
+ backgroundColor: 'rgba(0, 0, 0, 0.72)',
+ border: `1px solid ${PENDING_COLOR}`,
+ borderRadius: '12px',
+ color: '#FFD98A',
+ display: 'flex',
+ gap: '4px',
+ padding: '2px 6px',
+ position: 'absolute' as const,
+ right: '4px',
+ top: '4px',
+ whiteSpace: 'nowrap' as const,
+ zIndex: 12
+ },
+
+ compact: {
+ fontSize: '9px',
+ lineHeight: '12px'
+ },
+
+ dot: {
+ animation: `${breathe} 1.6s ease-in-out infinite`,
+ backgroundColor: PENDING_COLOR,
+ borderRadius: '50%',
+ flexShrink: 0,
+ height: '8px',
+ width: '8px',
+
+ '@media (prefers-reduced-motion: reduce)': {
+ animation: 'none',
+ opacity: 0.85
+ }
+ },
+
+ label: {
+ fontSize: '10px',
+ lineHeight: '13px'
+ }
+ };
+});
+
+/**
+ * Corner chip counting the participants still hearing this speaker's translated audio. Renders nothing when
+ * no count was published (the ring alone still signals the wait).
+ *
+ * @param {IProps} props - The component's props.
+ * @returns {ReactElement|null}
+ */
+const TranslationPendingChip = ({ participantId, thumbnailType }: IProps) => {
+ const { classes, cx } = useStyles();
+ const { t } = useTranslation();
+ const count = useSelector((state: IReduxState) =>
+ getTranslationDeliveryPendingCount(state, participantId));
+
+ if (count < 1) {
+ return null;
+ }
+
+ const isCompact = thumbnailType !== THUMBNAIL_TYPE.TILE;
+ const tooltip = t('videothumbnail.translationStillListening', { count });
+ const label = t('videothumbnail.translationStillListeningShort', { num: count });
+
+ return (
+ <div
+ aria-label = { tooltip }
+ className = { cx(classes.chip, isCompact && classes.compact) }
+ title = { tooltip }>
+ <span className = { classes.dot } />
+ <span className = { classes.label }>
+ { isCompact ? count : label }
+ </span>
+ </div>
+ );
+};
+
+export default TranslationPendingChip;
diff --git a/resources/prosody-plugins/mod_audio_translation_component.lua b/resources/prosody-plugins/mod_audio_translation_component.lua
index ac28f8f223..e004e7051f 100644
--- a/resources/prosody-plugins/mod_audio_translation_component.lua
+++ b/resources/prosody-plugins/mod_audio_translation_component.lua
@@ -82,6 +82,10 @@ local ENABLED_METADATA_KEY = 'audioTranslation';
-- Aggregate map exposed to jicofo only. Stored on room._data (never in
-- jitsiMetadata) so it is never broadcast to regular clients.
local REQUESTS_METADATA_KEY = 'audioTranslationRequests';
+-- Per-(sender, language) subscriber counts. Client-visible (kept in jitsiMetadata): counts only, never
+-- identities. Clients combine these with the bridge's synthetic-source sending state to show how many
+-- participants are still hearing a given speaker.
+local LISTENER_COUNTS_METADATA_KEY = 'audioTranslationListenerCounts';
local ENABLE_PERMISSION = 'live-translation';
local SUBSCRIBE_PERMISSION = 'live-translation-subscribe';
@@ -322,6 +326,27 @@ local function compute_aggregate(room)
return out;
end
+-- Builds { [senderId] = { [lang] = <subscriber count> } }, or nil when there are no subscriptions.
+local function compute_listener_counts(room)
+ local out = {};
+ local any = false;
+
+ for _, subs in pairs(get_state(room).receivers) do
+ for sender_id, lang in pairs(subs) do
+ local counts = out[sender_id];
+
+ if not counts then
+ counts = {};
+ out[sender_id] = counts;
+ end
+ counts[lang] = (counts[lang] or 0) + 1;
+ any = true;
+ end
+ end
+
+ return any and out or nil;
+end
+
-- Recomputes the aggregate and, when it changed, publishes it to jicofo via
-- RoomMetadata. Stored on room._data so mod_room_metadata_component only forwards
-- it to admin (jicofo) occupants.
@@ -343,8 +368,16 @@ local function publish(room)
-- The request set the receivers have asked for, independent of gating. Computed
-- unconditionally so we can tell "nothing requested" apart from "requests suppressed".
local requested = compute_aggregate(room);
- local aggregate = (allow_publish and is_enabled(room)) and requested or nil;
- local encoded = aggregate and json.encode(aggregate) or nil;
+ local gated = allow_publish and is_enabled(room);
+ local aggregate = gated and requested or nil;
+ local listener_counts = gated and compute_listener_counts(room) or nil;
+ -- Deduped on both: counts can change while the language set does not (a second receiver picking a
+ -- language another receiver already requested). Stays nil when there is nothing to publish, so a gated
+ -- or empty room still broadcasts nothing.
+ local encoded = (aggregate or listener_counts)
+ and ((aggregate and json.encode(aggregate) or '')
+ ..'|'..(listener_counts and json.encode(listener_counts) or ''))
+ or nil;
if encoded == room._audio_translation.last_published then
return;
@@ -361,6 +394,8 @@ local function publish(room)
end
room._data.audioTranslationRequests = aggregate;
+ room.jitsiMetadata = room.jitsiMetadata or {};
+ room.jitsiMetadata[LISTENER_COUNTS_METADATA_KEY] = listener_counts;
main_muc_module:fire_event('room-metadata-changed', { room = room; });
end
diff --git a/resources/prosody-plugins/mod_room_metadata_component.lua b/resources/prosody-plugins/mod_room_metadata_component.lua
index 66446fa00a..512b344954 100644
--- a/resources/prosody-plugins/mod_room_metadata_component.lua
+++ b/resources/prosody-plugins/mod_room_metadata_component.lua
@@ -107,6 +107,7 @@ local blocked_metadata_keys = module:get_option_set('room_metadata_blocked_keys'
'allownersEnabled',
'asyncTranscription',
'audioTranslationAvailable',
+ 'audioTranslationListenerCounts',
'audioTranslationRequests',
'conferencePresetsServiceEnabled',
'dialinEnabled',
diff --git a/tests/prosody/mod_audio_translation_component_spec.js b/tests/prosody/mod_audio_translation_component_spec.js
index 4230671002..beff687352 100644
--- a/tests/prosody/mod_audio_translation_component_spec.js
+++ b/tests/prosody/mod_audio_translation_component_spec.js
@@ -795,9 +795,11 @@ describe('mod_audio_translation_component', () => {
await pushAndGetRequests(rx1, foc, { [sender.nick]: 'en' });
- // rx2 also wants en — aggregate unchanged, so no broadcast fires.
+ // rx2 also wants en: the language set is unchanged, but the per-language listener counts
+ // change (1 -> 2), so a broadcast still fires. Consume it, otherwise the next wait would
+ // return this one and see the pre-switch aggregate.
rx2.sendAudioTranslation(AT_COMPONENT, { [sender.nick]: 'en' });
- await settle();
+ await waitForMetadata(foc);
// rx1 switches to es; rx2 still references en → { sender: [en, es] }.
const requests = await pushAndGetRequests(rx1, foc, { [sender.nick]: 'es' });