Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

actions.web.js 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import { overwriteConfig } from '../base/config';
  4. import { isLayoutTileView } from '../video-layout';
  5. import {
  6. CLEAR_TOOLBOX_TIMEOUT,
  7. FULL_SCREEN_CHANGED,
  8. SET_FULL_SCREEN,
  9. SET_OVERFLOW_DRAWER,
  10. SET_OVERFLOW_MENU_VISIBLE,
  11. SET_TOOLBAR_HOVERED,
  12. SET_TOOLBOX_TIMEOUT
  13. } from './actionTypes';
  14. import { setToolboxVisible } from './actions';
  15. import { getToolbarTimeout } from './functions';
  16. export * from './actions.any';
  17. /**
  18. * Docks/undocks the Toolbox.
  19. *
  20. * @param {boolean} dock - True if dock, false otherwise.
  21. * @returns {Function}
  22. */
  23. export function dockToolbox(dock: boolean): Function {
  24. return (dispatch: Dispatch<any>, getState: Function) => {
  25. const state = getState();
  26. const { visible } = state['features/toolbox'];
  27. const toolbarTimeout = getToolbarTimeout(state);
  28. if (dock) {
  29. // First make sure the toolbox is shown.
  30. visible || dispatch(showToolbox());
  31. dispatch(clearToolboxTimeout());
  32. } else if (visible) {
  33. dispatch(
  34. setToolboxTimeout(
  35. () => dispatch(hideToolbox()),
  36. toolbarTimeout));
  37. } else {
  38. dispatch(showToolbox());
  39. }
  40. };
  41. }
  42. /**
  43. * Signals that full screen mode has been entered or exited.
  44. *
  45. * @param {boolean} fullScreen - Whether or not full screen mode is currently
  46. * enabled.
  47. * @returns {{
  48. * type: FULL_SCREEN_CHANGED,
  49. * fullScreen: boolean
  50. * }}
  51. */
  52. export function fullScreenChanged(fullScreen: boolean) {
  53. return {
  54. type: FULL_SCREEN_CHANGED,
  55. fullScreen
  56. };
  57. }
  58. /**
  59. * Hides the toolbox.
  60. *
  61. * @param {boolean} force - True to force the hiding of the toolbox without
  62. * caring about the extended toolbar side panels.
  63. * @returns {Function}
  64. */
  65. export function hideToolbox(force: boolean = false): Function {
  66. return (dispatch: Dispatch<any>, getState: Function) => {
  67. const state = getState();
  68. const { toolbarConfig: { alwaysVisible } } = state['features/base/config'];
  69. const { hovered } = state['features/toolbox'];
  70. const toolbarTimeout = getToolbarTimeout(state);
  71. if (alwaysVisible) {
  72. return;
  73. }
  74. dispatch(clearToolboxTimeout());
  75. const focusSelector = '.toolbox-content-items:focus-within,.filmstrip:focus-within,.remotevideomenu:hover';
  76. if (!force
  77. && (hovered
  78. || state['features/invite'].calleeInfoVisible
  79. || state['features/chat'].isOpen
  80. || document.querySelector(focusSelector))) {
  81. dispatch(
  82. setToolboxTimeout(
  83. () => dispatch(hideToolbox()),
  84. toolbarTimeout));
  85. } else {
  86. dispatch(setToolboxVisible(false));
  87. }
  88. };
  89. }
  90. /**
  91. * Signals a request to enter or exit full screen mode.
  92. *
  93. * @param {boolean} fullScreen - True to enter full screen mode, false to exit.
  94. * @returns {{
  95. * type: SET_FULL_SCREEN,
  96. * fullScreen: boolean
  97. * }}
  98. */
  99. export function setFullScreen(fullScreen: boolean) {
  100. return {
  101. type: SET_FULL_SCREEN,
  102. fullScreen
  103. };
  104. }
  105. /**
  106. * Shows the toolbox for specified timeout.
  107. *
  108. * @param {number} timeout - Timeout for showing the toolbox.
  109. * @returns {Function}
  110. */
  111. export function showToolbox(timeout: number = 0): Object {
  112. return (dispatch: Dispatch<any>, getState: Function) => {
  113. const state = getState();
  114. const {
  115. toolbarConfig: { initialTimeout, alwaysVisible },
  116. toolbarConfig
  117. } = state['features/base/config'];
  118. const toolbarTimeout = getToolbarTimeout(state);
  119. const {
  120. enabled,
  121. visible,
  122. overflowDrawer
  123. } = state['features/toolbox'];
  124. const { contextMenuOpened } = state['features/base/responsive-ui'];
  125. const contextMenuOpenedInTileview = isLayoutTileView(state) && contextMenuOpened && !overflowDrawer;
  126. if (enabled && !visible && !contextMenuOpenedInTileview) {
  127. dispatch(setToolboxVisible(true));
  128. // If the Toolbox is always visible, there's no need for a timeout
  129. // to toggle its visibility.
  130. if (!alwaysVisible) {
  131. if (typeof initialTimeout === 'number') {
  132. // reset `initialTimeout` once it is consumed once
  133. dispatch(overwriteConfig({ toolbarConfig: {
  134. ...toolbarConfig,
  135. initialTimeout: null
  136. } }));
  137. }
  138. dispatch(
  139. setToolboxTimeout(
  140. () => dispatch(hideToolbox()),
  141. timeout || initialTimeout || toolbarTimeout));
  142. }
  143. }
  144. };
  145. }
  146. /**
  147. * Signals a request to display overflow as drawer.
  148. *
  149. * @param {boolean} displayAsDrawer - True to display overflow as drawer, false to preserve original behaviour.
  150. * @returns {{
  151. * type: SET_OVERFLOW_DRAWER,
  152. * displayAsDrawer: boolean
  153. * }}
  154. */
  155. export function setOverflowDrawer(displayAsDrawer: boolean) {
  156. return {
  157. type: SET_OVERFLOW_DRAWER,
  158. displayAsDrawer
  159. };
  160. }
  161. /**
  162. * Disables and hides the toolbox on demand when in tile view.
  163. *
  164. * @returns {void}
  165. */
  166. export function hideToolboxOnTileView() {
  167. return (dispatch: Dispatch<any>, getState: Function) => {
  168. const state = getState();
  169. const { overflowDrawer } = state['features/toolbox'];
  170. if (!overflowDrawer && isLayoutTileView(state)) {
  171. dispatch(hideToolbox(true));
  172. }
  173. };
  174. }
  175. /**
  176. * Signals that toolbox timeout should be cleared.
  177. *
  178. * @returns {{
  179. * type: CLEAR_TOOLBOX_TIMEOUT
  180. * }}
  181. */
  182. export function clearToolboxTimeout(): Object {
  183. return {
  184. type: CLEAR_TOOLBOX_TIMEOUT
  185. };
  186. }
  187. /**
  188. * Shows/hides the overflow menu.
  189. *
  190. * @param {boolean} visible - True to show it or false to hide it.
  191. * @returns {{
  192. * type: SET_OVERFLOW_MENU_VISIBLE,
  193. * visible: boolean
  194. * }}
  195. */
  196. export function setOverflowMenuVisible(visible: boolean): Object {
  197. return {
  198. type: SET_OVERFLOW_MENU_VISIBLE,
  199. visible
  200. };
  201. }
  202. /**
  203. * Signals that toolbar is hovered value should be changed.
  204. *
  205. * @param {boolean} hovered - Flag showing whether toolbar is hovered.
  206. * @returns {{
  207. * type: SET_TOOLBAR_HOVERED,
  208. * hovered: boolean
  209. * }}
  210. */
  211. export function setToolbarHovered(hovered: boolean): Object {
  212. return {
  213. type: SET_TOOLBAR_HOVERED,
  214. hovered
  215. };
  216. }
  217. /**
  218. * Dispatches an action which sets new timeout and clears the previous one.
  219. *
  220. * @param {Function} handler - Function to be invoked after the timeout.
  221. * @param {number} timeoutMS - Delay.
  222. * @returns {{
  223. * type: SET_TOOLBOX_TIMEOUT,
  224. * handler: Function,
  225. * timeoutMS: number
  226. * }}
  227. */
  228. export function setToolboxTimeout(handler: Function, timeoutMS: number): Object {
  229. return {
  230. type: SET_TOOLBOX_TIMEOUT,
  231. handler,
  232. timeoutMS
  233. };
  234. }