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.js 4.0KB

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