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.

reducer.js 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. // @flow
  2. import { ReducerRegistry } from '../base/redux';
  3. import {
  4. CLEAR_TOOLBOX_TIMEOUT,
  5. FULL_SCREEN_CHANGED,
  6. SET_DEFAULT_TOOLBOX_BUTTONS,
  7. SET_SUBJECT,
  8. SET_SUBJECT_SLIDE_IN,
  9. SET_TOOLBAR_BUTTON,
  10. SET_TOOLBAR_HOVERED,
  11. SET_TOOLBOX_ALWAYS_VISIBLE,
  12. SET_TOOLBOX_ENABLED,
  13. SET_TOOLBOX_TIMEOUT,
  14. SET_TOOLBOX_TIMEOUT_MS,
  15. SET_TOOLBOX_VISIBLE
  16. } from './actionTypes';
  17. import getDefaultButtons from './defaultToolbarButtons';
  18. declare var interfaceConfig: Object;
  19. /**
  20. * Returns initial state for toolbox's part of Redux store.
  21. *
  22. * @private
  23. * @returns {{
  24. * alwaysVisible: boolean,
  25. * hovered: boolean,
  26. * primaryToolbarButtons: Map,
  27. * secondaryToolbarButtons: Map,
  28. * subject: string,
  29. * subjectSlideIn: boolean,
  30. * timeoutID: number,
  31. * timeoutMS: number,
  32. * visible: boolean
  33. * }}
  34. */
  35. function _getInitialState() {
  36. // Default toolbox timeout for mobile app.
  37. let timeoutMS = 5000;
  38. if (typeof interfaceConfig !== 'undefined'
  39. && interfaceConfig.INITIAL_TOOLBAR_TIMEOUT) {
  40. timeoutMS = interfaceConfig.INITIAL_TOOLBAR_TIMEOUT;
  41. }
  42. return {
  43. /**
  44. * The indicator which determines whether the Toolbox should always be
  45. * visible.
  46. *
  47. * @type {boolean}
  48. */
  49. alwaysVisible: false,
  50. /**
  51. * The indicator which determines whether the Toolbox is enabled. For
  52. * example, modules/UI/recording/Recording.js disables the Toolbox.
  53. *
  54. * @type {boolean}
  55. */
  56. enabled: true,
  57. /**
  58. * The indicator which determines whether a Toolbar in the Toolbox is
  59. * hovered.
  60. *
  61. * @type {boolean}
  62. */
  63. hovered: false,
  64. /**
  65. * A Map of the default buttons of the PrimaryToolbar.
  66. *
  67. * @type {Map}
  68. */
  69. primaryToolbarButtons: new Map(),
  70. /**
  71. * A Map of the default buttons of the SecondaryToolbar.
  72. *
  73. * @type {Map}
  74. */
  75. secondaryToolbarButtons: new Map(),
  76. /**
  77. * The text of the conference subject.
  78. *
  79. * @type {string}
  80. */
  81. subject: '',
  82. /**
  83. * The indicator which determines whether the subject is sliding in.
  84. *
  85. * @type {boolean}
  86. */
  87. subjectSlideIn: false,
  88. /**
  89. * A number, non-zero value which identifies the timer created by a call
  90. * to setTimeout() with timeoutMS.
  91. *
  92. * @type {number|null}
  93. */
  94. timeoutID: null,
  95. /**
  96. * The delay in milliseconds before timeoutID executes (after its
  97. * initialization).
  98. *
  99. * @type {number}
  100. */
  101. timeoutMS,
  102. /**
  103. * The indicator which determines whether the Toolbox is visible.
  104. *
  105. * @type {boolean}
  106. */
  107. visible: false
  108. };
  109. }
  110. ReducerRegistry.register(
  111. 'features/toolbox',
  112. (state: Object = _getInitialState(), action: Object) => {
  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_DEFAULT_TOOLBOX_BUTTONS: {
  125. const { primaryToolbarButtons, secondaryToolbarButtons } = action;
  126. return {
  127. ...state,
  128. primaryToolbarButtons,
  129. secondaryToolbarButtons
  130. };
  131. }
  132. case SET_SUBJECT:
  133. return {
  134. ...state,
  135. subject: action.subject
  136. };
  137. case SET_SUBJECT_SLIDE_IN:
  138. return {
  139. ...state,
  140. subjectSlideIn: action.subjectSlideIn
  141. };
  142. case SET_TOOLBAR_BUTTON:
  143. return _setToolbarButton(state, action);
  144. case SET_TOOLBAR_HOVERED:
  145. return {
  146. ...state,
  147. hovered: action.hovered
  148. };
  149. case SET_TOOLBOX_ALWAYS_VISIBLE:
  150. return {
  151. ...state,
  152. alwaysVisible: action.alwaysVisible
  153. };
  154. case SET_TOOLBOX_ENABLED:
  155. return {
  156. ...state,
  157. enabled: action.enabled
  158. };
  159. case SET_TOOLBOX_TIMEOUT:
  160. return {
  161. ...state,
  162. timeoutID: action.timeoutID,
  163. timeoutMS: action.timeoutMS
  164. };
  165. case SET_TOOLBOX_TIMEOUT_MS:
  166. return {
  167. ...state,
  168. timeoutMS: action.timeoutMS
  169. };
  170. case SET_TOOLBOX_VISIBLE:
  171. return {
  172. ...state,
  173. visible: action.visible
  174. };
  175. }
  176. return state;
  177. });
  178. /**
  179. * Reduces the redux action {@code SET_TOOLBAR_BUTTON} in the feature toolbox.
  180. *
  181. * @param {Object} state - The redux state.
  182. * @param {Object} action - The redux action of type {@code SET_TOOLBAR_BUTTON}.
  183. * @param {Object} action.button - Object describing toolbar button.
  184. * @param {Object} action.buttonName - The name of the button.
  185. * @private
  186. * @returns {Object}
  187. */
  188. function _setToolbarButton(state, { button, buttonName }): Object {
  189. // XXX getDefaultButtons, defaultToolbarButtons, SET_TOOLBAR_BUTTON are
  190. // abstractions fully implemented on Web only.
  191. const buttons = getDefaultButtons && getDefaultButtons();
  192. const buttonDefinition = buttons && buttons[buttonName];
  193. // We don't need to update if the button shouldn't be displayed
  194. if (!buttonDefinition || !buttonDefinition.isDisplayed()) {
  195. return state;
  196. }
  197. const { primaryToolbarButtons, secondaryToolbarButtons } = state;
  198. let selectedButton = primaryToolbarButtons.get(buttonName);
  199. let place = 'primaryToolbarButtons';
  200. if (!selectedButton) {
  201. selectedButton = secondaryToolbarButtons.get(buttonName);
  202. place = 'secondaryToolbarButtons';
  203. }
  204. selectedButton = {
  205. ...selectedButton,
  206. ...button
  207. };
  208. const updatedToolbar = state[place].set(buttonName, selectedButton);
  209. return {
  210. ...state,
  211. [place]: new Map(updatedToolbar)
  212. };
  213. }