snapshot of https://github.com/jitsi/jitsi-meet.git @ fd1749dd28f4138aa80234fc7f311b19aaffa0e7 (2026-09-15)
This commit is contained in:
84
react/features/subtitles/functions.any.ts
Normal file
84
react/features/subtitles/functions.any.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
import { IReduxState } from '../app/types';
|
||||
import { IStateful } from '../base/app/types';
|
||||
import { TRANSLATION_LANGUAGES, TRANSLATION_LANGUAGES_HEAD } from '../base/i18n/i18next';
|
||||
import { toState } from '../base/redux/functions';
|
||||
import { isInBreakoutRoom } from '../breakout-rooms/functions';
|
||||
import { canAddTranscriber, isTranscribing } from '../transcribing/functions';
|
||||
|
||||
/**
|
||||
* Checks whether the participant can start the subtitles.
|
||||
*
|
||||
* @param {IReduxState} state - The redux state.
|
||||
* @returns {boolean} - True if the participant can start the subtitles.
|
||||
*/
|
||||
export function canStartSubtitles(state: IReduxState) {
|
||||
return canAddTranscriber(state) || isTranscribing(state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the list of available subtitles languages. The list consists of head languages (fixed items that stay on
|
||||
* top) followed by the rest of available translation languages.
|
||||
*
|
||||
* @param {IStateful} stateful - The stateful object containing the redux state.
|
||||
* @param {string} [selectedLanguage] - Optional language code of currently selected language. If provided and not in
|
||||
* regular translation languages, it will be added after head languages.
|
||||
* @returns {Array<string>} - Array of language codes. Includes both head languages and regular translation languages.
|
||||
*/
|
||||
export function getAvailableSubtitlesLanguages(stateful: IStateful, selectedLanguage?: string | null) {
|
||||
const state = toState(stateful);
|
||||
const { transcription } = state['features/base/config'];
|
||||
|
||||
const translationLanguagesHead = transcription?.translationLanguagesHead ?? TRANSLATION_LANGUAGES_HEAD;
|
||||
const translationLanguages
|
||||
= (transcription?.translationLanguages ?? TRANSLATION_LANGUAGES)
|
||||
.filter((lang: string) => !translationLanguagesHead?.includes(lang) && lang !== selectedLanguage);
|
||||
const isSelectedLanguageNotIncluded = Boolean(
|
||||
selectedLanguage
|
||||
&& !translationLanguages.includes(selectedLanguage)
|
||||
&& !translationLanguagesHead.includes(selectedLanguage));
|
||||
|
||||
return [
|
||||
...translationLanguagesHead,
|
||||
|
||||
// selectedLanguage is redundant but otherwise TS complains about null elements in the array.
|
||||
...isSelectedLanguageNotIncluded && selectedLanguage ? [ selectedLanguage ] : [],
|
||||
...translationLanguages
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines if translation (language selection) is enabled.
|
||||
*
|
||||
* @param {IReduxState} state - The Redux state object.
|
||||
* @returns {boolean} A boolean indicating whether translation is enabled.
|
||||
*/
|
||||
export function isTranslationEnabled(state: IReduxState) {
|
||||
const { transcription } = state['features/base/config'];
|
||||
|
||||
return transcription?.translationEnabled !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if closed captions are enabled.
|
||||
*
|
||||
* @param {IReduxState} state - The Redux state object.
|
||||
* @returns {boolean} A boolean indicating whether closed captions are enabled.
|
||||
*/
|
||||
export function areClosedCaptionsEnabled(state: IReduxState) {
|
||||
const { transcription } = state['features/base/config'];
|
||||
|
||||
return !transcription?.disableClosedCaptions && Boolean(transcription?.enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the subtitles tab should be enabled in the UI.
|
||||
*
|
||||
* @param {IReduxState} state - The redux state.
|
||||
* @returns {boolean} - True if the subtitles tab should be enabled.
|
||||
*/
|
||||
export function isCCTabEnabled(state: IReduxState) {
|
||||
const { showSubtitlesOnStage = false } = state['features/base/settings'];
|
||||
|
||||
return areClosedCaptionsEnabled(state) && !showSubtitlesOnStage && !isInBreakoutRoom(state);
|
||||
}
|
||||
Reference in New Issue
Block a user