Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

functions.any.ts 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { IReduxState } from '../app/types';
  2. import { IStateful } from '../base/app/types';
  3. import { isJwtFeatureEnabledStateless } from '../base/jwt/functions';
  4. import { IGUMPendingState } from '../base/media/types';
  5. import { IParticipantFeatures } from '../base/participants/types';
  6. import { toState } from '../base/redux/functions';
  7. import { iAmVisitor } from '../visitors/functions';
  8. import { VISITORS_MODE_BUTTONS } from './constants';
  9. /**
  10. * Indicates if the audio mute button is disabled or not.
  11. *
  12. * @param {IReduxState} state - The state from the Redux store.
  13. * @returns {boolean}
  14. */
  15. export function isAudioMuteButtonDisabled(state: IReduxState) {
  16. const { available, muted, unmuteBlocked, gumPending } = state['features/base/media'].audio;
  17. const { startSilent } = state['features/base/config'];
  18. return Boolean(!available || startSilent || (muted && unmuteBlocked) || gumPending !== IGUMPendingState.NONE
  19. || iAmVisitor(state));
  20. }
  21. /**
  22. * Returns the buttons corresponding to features disabled through jwt.
  23. * This function is stateless as it returns a new array and may cause re-rendering.
  24. *
  25. * @param {boolean} isTranscribing - Whether there is currently a transcriber in the meeting.
  26. * @param {boolean} isModerator - Whether local participant is moderator.
  27. * @param {string | undefined} jwt - The jwt token.
  28. * @param {ILocalParticipant} localParticipantFeatures - The features of the local participant.
  29. * @returns {string[]} - The disabled by jwt buttons array.
  30. */
  31. export function getJwtDisabledButtons(
  32. isTranscribing: boolean,
  33. isModerator: boolean,
  34. jwt: string | undefined,
  35. localParticipantFeatures?: IParticipantFeatures) {
  36. const acc = [];
  37. if (!isJwtFeatureEnabledStateless({
  38. jwt,
  39. localParticipantFeatures,
  40. feature: 'livestreaming',
  41. ifNoToken: isModerator,
  42. ifNotInFeatures: false
  43. })) {
  44. acc.push('livestreaming');
  45. }
  46. if (!isTranscribing && !isJwtFeatureEnabledStateless({
  47. jwt,
  48. localParticipantFeatures,
  49. feature: 'transcription',
  50. ifNoToken: isModerator,
  51. ifNotInFeatures: false
  52. })) {
  53. acc.push('closedcaptions');
  54. }
  55. return acc;
  56. }
  57. /**
  58. * Returns the list of enabled toolbar buttons.
  59. *
  60. * @param {Object|Function} stateful - Either the whole Redux state object or the Redux store's {@code getState} method.
  61. * @param {string[]} definedToolbarButtons - The list of all possible buttons.
  62. *
  63. * @returns {Array<string>} - The list of enabled toolbar buttons.
  64. */
  65. export function getToolbarButtons(stateful: IStateful, definedToolbarButtons: string[]): Array<string> {
  66. const state = toState(stateful);
  67. const { toolbarButtons, customToolbarButtons } = state['features/base/config'];
  68. const customButtons = customToolbarButtons?.map(({ id }) => id);
  69. let buttons = Array.isArray(toolbarButtons) ? toolbarButtons : definedToolbarButtons;
  70. if (iAmVisitor(state)) {
  71. buttons = VISITORS_MODE_BUTTONS.filter(button => buttons.indexOf(button) > -1);
  72. }
  73. if (customButtons) {
  74. return [ ...buttons, ...customButtons ];
  75. }
  76. return buttons;
  77. }
  78. /**
  79. * Checks if the specified button is enabled.
  80. *
  81. * @param {string} buttonName - The name of the button. See {@link interfaceConfig}.
  82. * @param {Object|Array<string>} state - The redux state or the array with the enabled buttons.
  83. * @returns {boolean} - True if the button is enabled and false otherwise.
  84. */
  85. export function isButtonEnabled(buttonName: string, state: IReduxState | Array<string>) {
  86. const buttons = Array.isArray(state) ? state : state['features/toolbox'].toolbarButtons || [];
  87. return buttons.includes(buttonName);
  88. }