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

reducer.ts 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. import ReducerRegistry from '../base/redux/ReducerRegistry';
  2. import { set } from '../base/redux/functions';
  3. import {
  4. CLEAR_TOOLBOX_TIMEOUT,
  5. FULL_SCREEN_CHANGED,
  6. SET_BUTTONS_WITH_NOTIFY_CLICK,
  7. SET_HANGUP_MENU_VISIBLE,
  8. SET_MAIN_TOOLBAR_BUTTONS_THRESHOLDS,
  9. SET_OVERFLOW_DRAWER,
  10. SET_OVERFLOW_MENU_VISIBLE,
  11. SET_PARTICIPANT_MENU_BUTTONS_WITH_NOTIFY_CLICK,
  12. SET_TOOLBAR_BUTTONS,
  13. SET_TOOLBAR_HOVERED,
  14. SET_TOOLBOX_ENABLED,
  15. SET_TOOLBOX_SHIFT_UP,
  16. SET_TOOLBOX_TIMEOUT,
  17. SET_TOOLBOX_VISIBLE,
  18. TOGGLE_TOOLBOX_VISIBLE
  19. } from './actionTypes';
  20. import { NATIVE_THRESHOLDS, THRESHOLDS } from './constants';
  21. import { IMainToolbarButtonThresholds, NOTIFY_CLICK_MODE } from './types';
  22. /**
  23. * Array of thresholds for the main toolbar buttons that will inlude only the usable entries from THRESHOLDS array.
  24. *
  25. * Note: THRESHOLDS array includes some dummy values that enables users of the iframe API to override and use.
  26. * Note2: Casting is needed because it seems isArray guard is not working well in TS. See:
  27. * https://github.com/microsoft/TypeScript/issues/17002.
  28. */
  29. const FILTERED_THRESHOLDS = THRESHOLDS.filter(({ order }) => Array.isArray(order)) as IMainToolbarButtonThresholds;
  30. /**
  31. * Initial state of toolbox's part of Redux store.
  32. */
  33. const INITIAL_STATE = {
  34. buttonsWithNotifyClick: new Map(),
  35. /**
  36. * The indicator which determines whether the Toolbox is enabled.
  37. *
  38. * @type {boolean}
  39. */
  40. enabled: true,
  41. /**
  42. * The indicator which determines whether the hangup menu is visible.
  43. *
  44. * @type {boolean}
  45. */
  46. hangupMenuVisible: false,
  47. /**
  48. * The indicator which determines whether a Toolbar in the Toolbox is
  49. * hovered.
  50. *
  51. * @type {boolean}
  52. */
  53. hovered: false,
  54. /**
  55. * The thresholds for screen size and visible main toolbar buttons.
  56. */
  57. mainToolbarButtonsThresholds: navigator.product === 'ReactNative' ? NATIVE_THRESHOLDS : FILTERED_THRESHOLDS,
  58. participantMenuButtonsWithNotifyClick: new Map(),
  59. /**
  60. * The indicator which determines whether the overflow menu(s) are to be displayed as drawers.
  61. *
  62. * @type {boolean}
  63. */
  64. overflowDrawer: false,
  65. /**
  66. * The indicator which determines whether the OverflowMenu is visible.
  67. *
  68. * @type {boolean}
  69. */
  70. overflowMenuVisible: false,
  71. /**
  72. * Whether to shift the toolbar up (in case it overlaps the tiles names).
  73. */
  74. shiftUp: false,
  75. /**
  76. * A number, non-zero value which identifies the timer created by a call
  77. * to setTimeout().
  78. *
  79. * @type {number|null}
  80. */
  81. timeoutID: null,
  82. /**
  83. * The list of enabled toolbar buttons.
  84. *
  85. * @type {Array<string>}
  86. */
  87. toolbarButtons: [],
  88. /**
  89. * The indicator that determines whether the Toolbox is visible.
  90. *
  91. * @type {boolean}
  92. */
  93. visible: false
  94. };
  95. export interface IToolboxState {
  96. buttonsWithNotifyClick: Map<string, NOTIFY_CLICK_MODE>;
  97. enabled: boolean;
  98. fullScreen?: boolean;
  99. hangupMenuVisible: boolean;
  100. hovered: boolean;
  101. mainToolbarButtonsThresholds: IMainToolbarButtonThresholds;
  102. overflowDrawer: boolean;
  103. overflowMenuVisible: boolean;
  104. participantMenuButtonsWithNotifyClick: Map<string, NOTIFY_CLICK_MODE>;
  105. shiftUp: boolean;
  106. timeoutID?: number | null;
  107. toolbarButtons: Array<string>;
  108. visible: boolean;
  109. }
  110. ReducerRegistry.register<IToolboxState>(
  111. 'features/toolbox',
  112. (state = INITIAL_STATE, action): IToolboxState => {
  113. switch (action.type) {
  114. case CLEAR_TOOLBOX_TIMEOUT:
  115. return {
  116. ...state,
  117. timeoutID: undefined
  118. };
  119. case FULL_SCREEN_CHANGED:
  120. return {
  121. ...state,
  122. fullScreen: action.fullScreen
  123. };
  124. case SET_HANGUP_MENU_VISIBLE:
  125. return {
  126. ...state,
  127. hangupMenuVisible: action.visible
  128. };
  129. case SET_OVERFLOW_DRAWER:
  130. return {
  131. ...state,
  132. overflowDrawer: action.displayAsDrawer
  133. };
  134. case SET_OVERFLOW_MENU_VISIBLE:
  135. return {
  136. ...state,
  137. overflowMenuVisible: action.visible
  138. };
  139. case SET_TOOLBAR_BUTTONS:
  140. return {
  141. ...state,
  142. toolbarButtons: action.toolbarButtons
  143. };
  144. case SET_BUTTONS_WITH_NOTIFY_CLICK:
  145. return {
  146. ...state,
  147. buttonsWithNotifyClick: action.buttonsWithNotifyClick
  148. };
  149. case SET_MAIN_TOOLBAR_BUTTONS_THRESHOLDS:
  150. return {
  151. ...state,
  152. mainToolbarButtonsThresholds: action.mainToolbarButtonsThresholds
  153. };
  154. case SET_TOOLBAR_HOVERED:
  155. return {
  156. ...state,
  157. hovered: action.hovered
  158. };
  159. case SET_TOOLBOX_ENABLED:
  160. return {
  161. ...state,
  162. enabled: action.enabled
  163. };
  164. case SET_TOOLBOX_TIMEOUT:
  165. return {
  166. ...state,
  167. timeoutID: action.timeoutID
  168. };
  169. case SET_TOOLBOX_SHIFT_UP:
  170. return {
  171. ...state,
  172. shiftUp: action.shiftUp
  173. };
  174. case SET_TOOLBOX_VISIBLE:
  175. return set(state, 'visible', action.visible);
  176. case SET_PARTICIPANT_MENU_BUTTONS_WITH_NOTIFY_CLICK:
  177. return {
  178. ...state,
  179. participantMenuButtonsWithNotifyClick: action.participantMenuButtonsWithNotifyClick
  180. };
  181. case TOGGLE_TOOLBOX_VISIBLE:
  182. return set(state, 'visible', !state.visible);
  183. }
  184. return state;
  185. });