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.9KB

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