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.

actions.web.js 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import { isLayoutTileView } from '../video-layout';
  4. import {
  5. CLEAR_TOOLBOX_TIMEOUT,
  6. FULL_SCREEN_CHANGED,
  7. SET_FULL_SCREEN,
  8. SET_OVERFLOW_DRAWER,
  9. SET_OVERFLOW_MENU_VISIBLE,
  10. SET_TOOLBAR_HOVERED,
  11. SET_TOOLBOX_TIMEOUT,
  12. SET_TOOLBOX_TIMEOUT_MS
  13. } from './actionTypes';
  14. import { setToolboxVisible } from './actions.any';
  15. declare var interfaceConfig: Object;
  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 { timeoutMS, visible } = getState()['features/toolbox'];
  26. if (dock) {
  27. // First make sure the toolbox is shown.
  28. visible || dispatch(showToolbox());
  29. dispatch(clearToolboxTimeout());
  30. } else if (visible) {
  31. dispatch(
  32. setToolboxTimeout(
  33. () => dispatch(hideToolbox()),
  34. timeoutMS));
  35. } else {
  36. dispatch(showToolbox());
  37. }
  38. };
  39. }
  40. /**
  41. * Signals that full screen mode has been entered or exited.
  42. *
  43. * @param {boolean} fullScreen - Whether or not full screen mode is currently
  44. * enabled.
  45. * @returns {{
  46. * type: FULL_SCREEN_CHANGED,
  47. * fullScreen: boolean
  48. * }}
  49. */
  50. export function fullScreenChanged(fullScreen: boolean) {
  51. return {
  52. type: FULL_SCREEN_CHANGED,
  53. fullScreen
  54. };
  55. }
  56. /**
  57. * Hides the toolbox.
  58. *
  59. * @param {boolean} force - True to force the hiding of the toolbox without
  60. * caring about the extended toolbar side panels.
  61. * @returns {Function}
  62. */
  63. export function hideToolbox(force: boolean = false): Function {
  64. return (dispatch: Dispatch<any>, getState: Function) => {
  65. const state = getState();
  66. const {
  67. alwaysVisible,
  68. hovered,
  69. timeoutMS
  70. } = state['features/toolbox'];
  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. timeoutMS));
  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. alwaysVisible,
  116. enabled,
  117. timeoutMS,
  118. visible,
  119. overflowDrawer
  120. } = state['features/toolbox'];
  121. const { contextMenuOpened } = state['features/base/responsive-ui'];
  122. const contextMenuOpenedInTileview = isLayoutTileView(state) && contextMenuOpened && !overflowDrawer;
  123. if (enabled && !visible && !contextMenuOpenedInTileview) {
  124. dispatch(setToolboxVisible(true));
  125. // If the Toolbox is always visible, there's no need for a timeout
  126. // to toggle its visibility.
  127. if (!alwaysVisible) {
  128. dispatch(
  129. setToolboxTimeout(
  130. () => dispatch(hideToolbox()),
  131. timeout || timeoutMS));
  132. dispatch(setToolboxTimeoutMS(interfaceConfig.TOOLBAR_TIMEOUT));
  133. }
  134. }
  135. };
  136. }
  137. /**
  138. * Signals a request to display overflow as drawer.
  139. *
  140. * @param {boolean} displayAsDrawer - True to display overflow as drawer, false to preserve original behaviour.
  141. * @returns {{
  142. * type: SET_OVERFLOW_DRAWER,
  143. * displayAsDrawer: boolean
  144. * }}
  145. */
  146. export function setOverflowDrawer(displayAsDrawer: boolean) {
  147. return {
  148. type: SET_OVERFLOW_DRAWER,
  149. displayAsDrawer
  150. };
  151. }
  152. /**
  153. * Disables and hides the toolbox on demand when in tile view.
  154. *
  155. * @returns {void}
  156. */
  157. export function hideToolboxOnTileView() {
  158. return (dispatch: Dispatch<any>, getState: Function) => {
  159. const state = getState();
  160. const { overflowDrawer } = state['features/toolbox'];
  161. if (!overflowDrawer && isLayoutTileView(state)) {
  162. dispatch(hideToolbox(true));
  163. }
  164. };
  165. }
  166. /**
  167. * Signals that toolbox timeout should be cleared.
  168. *
  169. * @returns {{
  170. * type: CLEAR_TOOLBOX_TIMEOUT
  171. * }}
  172. */
  173. export function clearToolboxTimeout(): Object {
  174. return {
  175. type: CLEAR_TOOLBOX_TIMEOUT
  176. };
  177. }
  178. /**
  179. * Shows/hides the overflow menu.
  180. *
  181. * @param {boolean} visible - True to show it or false to hide it.
  182. * @returns {{
  183. * type: SET_OVERFLOW_MENU_VISIBLE,
  184. * visible: boolean
  185. * }}
  186. */
  187. export function setOverflowMenuVisible(visible: boolean): Object {
  188. return {
  189. type: SET_OVERFLOW_MENU_VISIBLE,
  190. visible
  191. };
  192. }
  193. /**
  194. * Signals that toolbar is hovered value should be changed.
  195. *
  196. * @param {boolean} hovered - Flag showing whether toolbar is hovered.
  197. * @returns {{
  198. * type: SET_TOOLBAR_HOVERED,
  199. * hovered: boolean
  200. * }}
  201. */
  202. export function setToolbarHovered(hovered: boolean): Object {
  203. return {
  204. type: SET_TOOLBAR_HOVERED,
  205. hovered
  206. };
  207. }
  208. /**
  209. * Dispatches an action which sets new timeout and clears the previous one.
  210. *
  211. * @param {Function} handler - Function to be invoked after the timeout.
  212. * @param {number} timeoutMS - Delay.
  213. * @returns {{
  214. * type: SET_TOOLBOX_TIMEOUT,
  215. * handler: Function,
  216. * timeoutMS: number
  217. * }}
  218. */
  219. export function setToolboxTimeout(handler: Function, timeoutMS: number): Object {
  220. return {
  221. type: SET_TOOLBOX_TIMEOUT,
  222. handler,
  223. timeoutMS
  224. };
  225. }
  226. /**
  227. * Dispatches an action which sets new toolbox timeout value.
  228. *
  229. * @param {number} timeoutMS - Delay.
  230. * @returns {{
  231. * type: SET_TOOLBOX_TIMEOUT_MS,
  232. * timeoutMS: number
  233. * }}
  234. */
  235. export function setToolboxTimeoutMS(timeoutMS: number): Object {
  236. return {
  237. type: SET_TOOLBOX_TIMEOUT_MS,
  238. timeoutMS
  239. };
  240. }