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.web.ts 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import { IState } from '../app/types';
  2. import { getToolbarButtons } from '../base/config/functions.web';
  3. import { hasAvailableDevices } from '../base/devices/functions';
  4. import { isScreenMediaShared } from '../screen-share/functions';
  5. import { isWhiteboardVisible } from '../whiteboard/functions';
  6. import { TOOLBAR_TIMEOUT } from './constants';
  7. export * from './functions.any';
  8. /**
  9. * Helper for getting the height of the toolbox.
  10. *
  11. * @returns {number} The height of the toolbox.
  12. */
  13. export function getToolboxHeight() {
  14. const toolbox = document.getElementById('new-toolbox');
  15. return toolbox?.clientHeight || 0;
  16. }
  17. /**
  18. * Indicates if a toolbar button is enabled.
  19. *
  20. * @param {string} name - The name of the setting section as defined in
  21. * interface_config.js.
  22. * @param {IState} state - The redux state.
  23. * @returns {boolean|undefined} - True to indicate that the given toolbar button
  24. * is enabled, false - otherwise.
  25. */
  26. export function isButtonEnabled(name: string, state: IState) {
  27. const toolbarButtons = getToolbarButtons(state);
  28. return toolbarButtons.indexOf(name) !== -1;
  29. }
  30. /**
  31. * Indicates if the toolbox is visible or not.
  32. *
  33. * @param {IState} state - The state from the Redux store.
  34. * @returns {boolean} - True to indicate that the toolbox is visible, false -
  35. * otherwise.
  36. */
  37. export function isToolboxVisible(state: IState) {
  38. const { iAmRecorder, iAmSipGateway, toolbarConfig } = state['features/base/config'];
  39. const { alwaysVisible } = toolbarConfig || {};
  40. const {
  41. timeoutID,
  42. visible
  43. } = state['features/toolbox'];
  44. const { audioSettingsVisible, videoSettingsVisible } = state['features/settings'];
  45. const whiteboardVisible = isWhiteboardVisible(state);
  46. return Boolean(!iAmRecorder && !iAmSipGateway
  47. && (
  48. timeoutID
  49. || visible
  50. || alwaysVisible
  51. || audioSettingsVisible
  52. || videoSettingsVisible
  53. || whiteboardVisible
  54. ));
  55. }
  56. /**
  57. * Indicates if the audio settings button is disabled or not.
  58. *
  59. * @param {IState} state - The state from the Redux store.
  60. * @returns {boolean}
  61. */
  62. export function isAudioSettingsButtonDisabled(state: IState) {
  63. return !(hasAvailableDevices(state, 'audioInput')
  64. || hasAvailableDevices(state, 'audioOutput'))
  65. || state['features/base/config'].startSilent;
  66. }
  67. /**
  68. * Indicates if the desktop share button is disabled or not.
  69. *
  70. * @param {IState} state - The state from the Redux store.
  71. * @returns {boolean}
  72. */
  73. export function isDesktopShareButtonDisabled(state: IState) {
  74. const { muted, unmuteBlocked } = state['features/base/media'].video;
  75. const videoOrShareInProgress = !muted || isScreenMediaShared(state);
  76. return unmuteBlocked && !videoOrShareInProgress;
  77. }
  78. /**
  79. * Indicates if the video settings button is disabled or not.
  80. *
  81. * @param {IState} state - The state from the Redux store.
  82. * @returns {boolean}
  83. */
  84. export function isVideoSettingsButtonDisabled(state: IState) {
  85. return !hasAvailableDevices(state, 'videoInput');
  86. }
  87. /**
  88. * Indicates if the video mute button is disabled or not.
  89. *
  90. * @param {IState} state - The state from the Redux store.
  91. * @returns {boolean}
  92. */
  93. export function isVideoMuteButtonDisabled(state: IState) {
  94. const { muted, unmuteBlocked } = state['features/base/media'].video;
  95. return !hasAvailableDevices(state, 'videoInput') || (unmuteBlocked && Boolean(muted));
  96. }
  97. /**
  98. * If an overflow drawer should be displayed or not.
  99. * This is usually done for mobile devices or on narrow screens.
  100. *
  101. * @param {IState} state - The state from the Redux store.
  102. * @returns {boolean}
  103. */
  104. export function showOverflowDrawer(state: IState) {
  105. return state['features/toolbox'].overflowDrawer;
  106. }
  107. /**
  108. * Indicates whether the toolbox is enabled or not.
  109. *
  110. * @param {IState} state - The state from the Redux store.
  111. * @returns {boolean}
  112. */
  113. export function isToolboxEnabled(state: IState) {
  114. return state['features/toolbox'].enabled;
  115. }
  116. /**
  117. * Returns the toolbar timeout from config or the default value.
  118. *
  119. * @param {IState} state - The state from the Redux store.
  120. * @returns {number} - Toolbar timeout in milliseconds.
  121. */
  122. export function getToolbarTimeout(state: IState) {
  123. const { toolbarConfig } = state['features/base/config'];
  124. return toolbarConfig?.timeout || TOOLBAR_TIMEOUT;
  125. }