bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/audio/audio-graphql/audio-captions/service.ts
João Victor Nunes 06500be757
refactor(storage): replace Tracker.Dependency with observer hook (#20322)
* refactor(storage): replace Tracker.Dependency with observer hook

* fix(storage): set initial value

* refactor(storage): stop using Meteor's Session singleton
2024-06-06 10:50:03 -03:00

52 lines
1.6 KiB
TypeScript

import { unique } from 'radash';
import { setAudioCaptionEnable } from '/imports/ui/core/local-states/useAudioCaptionEnable';
import { isLiveTranscriptionEnabled } from '/imports/ui/services/features';
import Session from '/imports/ui/services/storage/in-memory';
export const isAudioTranscriptionEnabled = () => isLiveTranscriptionEnabled();
export const isWebSpeechApi = () => {
const PROVIDER = window.meetingClientSettings.public.app.audioCaptions.provider;
return PROVIDER === 'webspeech';
};
export const getSpeechVoices = () => {
const LANGUAGES = window.meetingClientSettings.public.app.audioCaptions.language.available;
if (!isWebSpeechApi()) return LANGUAGES;
return unique(
window
.speechSynthesis
.getVoices()
.map((v) => v.lang)
.filter((v) => LANGUAGES.includes(v)),
);
};
export const setAudioCaptions = (value: boolean) => {
setAudioCaptionEnable(value);
// @ts-ignore - Exist while we have meteor in the project
Session.setItem('audioCaptions', value);
};
// SpeechLocale or CaptionLocale
export const setUserLocaleProperty = (value: string, setUserLocaleCallback: (a: string, b: string) => void) => {
const PROVIDER = window.meetingClientSettings.public.app.audioCaptions.provider;
setUserLocaleCallback(value, PROVIDER);
};
export const useFixedLocale = () => {
const FORCE_LOCALE = window.meetingClientSettings.public.app.audioCaptions.language.forceLocale;
return isAudioTranscriptionEnabled() && FORCE_LOCALE;
};
export default {
getSpeechVoices,
isAudioTranscriptionEnabled,
setUserLocaleProperty,
setAudioCaptions,
isWebSpeechApi,
useFixedLocale,
};