You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.any.ts 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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} isCCTabEnabled - Whether the closed captions tab is enabled.
  27. * @param {ILocalParticipant} localParticipantFeatures - The features of the local participant.
  28. * @returns {string[]} - The disabled by jwt buttons array.
  29. */
  30. export function getJwtDisabledButtons(
  31. isTranscribing: boolean,
  32. isCCTabEnabled: boolean,
  33. localParticipantFeatures?: IParticipantFeatures) {
  34. const acc = [];
  35. if (!isJwtFeatureEnabledStateless({
  36. localParticipantFeatures,
  37. feature: 'livestreaming',
  38. ifNotInFeatures: false
  39. })) {
  40. acc.push('livestreaming');
  41. }
  42. if (!isTranscribing && !isCCTabEnabled && !isJwtFeatureEnabledStateless({
  43. localParticipantFeatures,
  44. feature: 'transcription',
  45. ifNotInFeatures: false
  46. })) {
  47. acc.push('closedcaptions');
  48. }
  49. return acc;
  50. }
  51. /**
  52. * Returns the list of enabled toolbar buttons.
  53. *
  54. * @param {Object|Function} stateful - Either the whole Redux state object or the Redux store's {@code getState} method.
  55. * @param {string[]} definedToolbarButtons - The list of all possible buttons.
  56. *
  57. * @returns {Array<string>} - The list of enabled toolbar buttons.
  58. */
  59. export function getToolbarButtons(stateful: IStateful, definedToolbarButtons: string[]): Array<string> {
  60. const state = toState(stateful);
  61. const { toolbarButtons, customToolbarButtons } = state['features/base/config'];
  62. const customButtons = customToolbarButtons?.map(({ id }) => id);
  63. let buttons = Array.isArray(toolbarButtons) ? toolbarButtons : definedToolbarButtons;
  64. if (iAmVisitor(state)) {
  65. buttons = VISITORS_MODE_BUTTONS.filter(button => buttons.indexOf(button) > -1);
  66. }
  67. if (customButtons) {
  68. return [ ...buttons, ...customButtons ];
  69. }
  70. return buttons;
  71. }
  72. /**
  73. * Checks if the specified button is enabled.
  74. *
  75. * @param {string} buttonName - The name of the button. See {@link interfaceConfig}.
  76. * @param {Object|Array<string>} state - The redux state or the array with the enabled buttons.
  77. * @returns {boolean} - True if the button is enabled and false otherwise.
  78. */
  79. export function isButtonEnabled(buttonName: string, state: IReduxState | Array<string>) {
  80. const buttons = Array.isArray(state) ? state : state['features/toolbox'].toolbarButtons || [];
  81. return buttons.includes(buttonName);
  82. }