您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

actions.any.ts 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. import { VIDEO_MUTE, createToolbarEvent } from '../analytics/AnalyticsEvents';
  2. import { sendAnalytics } from '../analytics/functions';
  3. import { IStore } from '../app/types';
  4. import { setAudioOnly } from '../base/audio-only/actions';
  5. import { setVideoMuted } from '../base/media/actions';
  6. import { VIDEO_MUTISM_AUTHORITY } from '../base/media/constants';
  7. import {
  8. SET_MAIN_TOOLBAR_BUTTONS_THRESHOLDS,
  9. SET_TOOLBOX_ENABLED,
  10. SET_TOOLBOX_SHIFT_UP,
  11. SET_TOOLBOX_VISIBLE,
  12. TOGGLE_TOOLBOX_VISIBLE
  13. } from './actionTypes';
  14. import { DUMMY_10_BUTTONS_THRESHOLD_VALUE, DUMMY_9_BUTTONS_THRESHOLD_VALUE } from './constants';
  15. import { IMainToolbarButtonThresholds, IMainToolbarButtonThresholdsUnfiltered } from './types';
  16. /**
  17. * Enables/disables the toolbox.
  18. *
  19. * @param {boolean} enabled - True to enable the toolbox or false to disable it.
  20. * @returns {{
  21. * type: SET_TOOLBOX_ENABLED,
  22. * enabled: boolean
  23. * }}
  24. */
  25. export function setToolboxEnabled(enabled: boolean) {
  26. return {
  27. type: SET_TOOLBOX_ENABLED,
  28. enabled
  29. };
  30. }
  31. /**
  32. * Shows/hides the toolbox.
  33. *
  34. * @param {boolean} visible - True to show the toolbox or false to hide it.
  35. * @returns {Function}
  36. */
  37. export function setToolboxVisible(visible: boolean) {
  38. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  39. const { toolbarConfig } = getState()['features/base/config'];
  40. const alwaysVisible = toolbarConfig?.alwaysVisible;
  41. if (!visible && alwaysVisible) {
  42. return;
  43. }
  44. dispatch({
  45. type: SET_TOOLBOX_VISIBLE,
  46. visible
  47. });
  48. };
  49. }
  50. /**
  51. * Action to toggle the toolbox visibility.
  52. *
  53. * @returns {Function}
  54. */
  55. export function toggleToolboxVisible() {
  56. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  57. const state = getState();
  58. const { toolbarConfig } = getState()['features/base/config'];
  59. const alwaysVisible = toolbarConfig?.alwaysVisible;
  60. const { visible } = state['features/toolbox'];
  61. if (visible && alwaysVisible) {
  62. return;
  63. }
  64. dispatch({
  65. type: TOGGLE_TOOLBOX_VISIBLE
  66. });
  67. };
  68. }
  69. /**
  70. * Action to handle toggle video from toolbox's video buttons.
  71. *
  72. * @param {boolean} muted - Whether to mute or unmute.
  73. * @param {boolean} showUI - When set to false will not display any error.
  74. * @param {boolean} ensureTrack - True if we want to ensure that a new track is
  75. * created if missing.
  76. * @returns {Function}
  77. */
  78. export function handleToggleVideoMuted(muted: boolean, showUI: boolean, ensureTrack: boolean) {
  79. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  80. const state = getState();
  81. const { enabled: audioOnly } = state['features/base/audio-only'];
  82. sendAnalytics(createToolbarEvent(VIDEO_MUTE, { enable: muted }));
  83. if (audioOnly) {
  84. dispatch(setAudioOnly(false));
  85. }
  86. dispatch(
  87. setVideoMuted(
  88. muted,
  89. VIDEO_MUTISM_AUTHORITY.USER,
  90. ensureTrack));
  91. // FIXME: The old conference logic still relies on this event being
  92. // emitted.
  93. typeof APP === 'undefined'
  94. || APP.conference.muteVideo(muted, showUI);
  95. };
  96. }
  97. /**
  98. * Sets whether the toolbox should be shifted up or not.
  99. *
  100. * @param {boolean} shiftUp - Whether the toolbox should shift up or not.
  101. * @returns {Object}
  102. */
  103. export function setShiftUp(shiftUp: boolean) {
  104. return {
  105. type: SET_TOOLBOX_SHIFT_UP,
  106. shiftUp
  107. };
  108. }
  109. /**
  110. * Sets the mainToolbarButtonsThresholds.
  111. *
  112. * @param {IMainToolbarButtonThresholds} thresholds - Thresholds for screen size and visible main toolbar buttons.
  113. * @returns {Function}
  114. */
  115. export function setMainToolbarThresholds(thresholds: IMainToolbarButtonThresholdsUnfiltered) {
  116. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  117. const { mainToolbarButtons } = getState()['features/base/config'];
  118. if (!Array.isArray(mainToolbarButtons) || mainToolbarButtons.length === 0) {
  119. return;
  120. }
  121. const mainToolbarButtonsThresholds: IMainToolbarButtonThresholds = [];
  122. const mainToolbarButtonsLengthMap = new Map();
  123. let orderIsChanged = false;
  124. mainToolbarButtons.forEach(buttons => {
  125. if (!Array.isArray(buttons) || buttons.length === 0) {
  126. return;
  127. }
  128. mainToolbarButtonsLengthMap.set(buttons.length, buttons);
  129. });
  130. thresholds.forEach(({ width, order }) => {
  131. let numberOfButtons = 0;
  132. if (Array.isArray(order)) {
  133. numberOfButtons = order.length;
  134. } else if (order === DUMMY_9_BUTTONS_THRESHOLD_VALUE) {
  135. numberOfButtons = 9;
  136. } else if (order === DUMMY_10_BUTTONS_THRESHOLD_VALUE) {
  137. numberOfButtons = 10;
  138. } else { // Unexpected value. Ignore it.
  139. return;
  140. }
  141. let finalOrder = mainToolbarButtonsLengthMap.get(numberOfButtons);
  142. if (finalOrder) {
  143. orderIsChanged = true;
  144. } else if (Array.isArray(order)) {
  145. finalOrder = order;
  146. } else {
  147. // Ignore dummy (symbol) values.
  148. return;
  149. }
  150. mainToolbarButtonsThresholds.push({
  151. order: finalOrder,
  152. width
  153. });
  154. });
  155. if (orderIsChanged) {
  156. dispatch({
  157. type: SET_MAIN_TOOLBAR_BUTTONS_THRESHOLDS,
  158. mainToolbarButtonsThresholds
  159. });
  160. }
  161. };
  162. }