選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

actions.web.js 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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_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, autoHideWhileChatIsOpen } } = 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 && !autoHideWhileChatIsOpen)
  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. } = state['features/toolbox'];
  123. if (enabled && !visible) {
  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. if (typeof initialTimeout === 'number') {
  129. // reset `initialTimeout` once it is consumed once
  130. dispatch(overwriteConfig({ toolbarConfig: {
  131. ...toolbarConfig,
  132. initialTimeout: null
  133. } }));
  134. }
  135. dispatch(
  136. setToolboxTimeout(
  137. () => dispatch(hideToolbox()),
  138. timeout || initialTimeout || toolbarTimeout));
  139. }
  140. }
  141. };
  142. }
  143. /**
  144. * Signals a request to display overflow as drawer.
  145. *
  146. * @param {boolean} displayAsDrawer - True to display overflow as drawer, false to preserve original behaviour.
  147. * @returns {{
  148. * type: SET_OVERFLOW_DRAWER,
  149. * displayAsDrawer: boolean
  150. * }}
  151. */
  152. export function setOverflowDrawer(displayAsDrawer: boolean) {
  153. return {
  154. type: SET_OVERFLOW_DRAWER,
  155. displayAsDrawer
  156. };
  157. }
  158. /**
  159. * Signals that toolbox timeout should be cleared.
  160. *
  161. * @returns {{
  162. * type: CLEAR_TOOLBOX_TIMEOUT
  163. * }}
  164. */
  165. export function clearToolboxTimeout(): Object {
  166. return {
  167. type: CLEAR_TOOLBOX_TIMEOUT
  168. };
  169. }
  170. /**
  171. * Shows/hides the overflow menu.
  172. *
  173. * @param {boolean} visible - True to show it or false to hide it.
  174. * @returns {{
  175. * type: SET_OVERFLOW_MENU_VISIBLE,
  176. * visible: boolean
  177. * }}
  178. */
  179. export function setOverflowMenuVisible(visible: boolean): Object {
  180. return {
  181. type: SET_OVERFLOW_MENU_VISIBLE,
  182. visible
  183. };
  184. }
  185. /**
  186. * Signals that toolbar is hovered value should be changed.
  187. *
  188. * @param {boolean} hovered - Flag showing whether toolbar is hovered.
  189. * @returns {{
  190. * type: SET_TOOLBAR_HOVERED,
  191. * hovered: boolean
  192. * }}
  193. */
  194. export function setToolbarHovered(hovered: boolean): Object {
  195. return {
  196. type: SET_TOOLBAR_HOVERED,
  197. hovered
  198. };
  199. }
  200. /**
  201. * Dispatches an action which sets new timeout for the toolbox visibility and clears the previous one.
  202. * On mobile browsers the toolbox does not hide on timeout. It is toggled on simple tap.
  203. *
  204. * @param {Function} handler - Function to be invoked after the timeout.
  205. * @param {number} timeoutMS - Delay.
  206. * @returns {{
  207. * type: SET_TOOLBOX_TIMEOUT,
  208. * handler: Function,
  209. * timeoutMS: number
  210. * }}
  211. */
  212. export function setToolboxTimeout(handler: Function, timeoutMS: number): Object {
  213. return function(dispatch) {
  214. if (isMobileBrowser()) {
  215. return;
  216. }
  217. dispatch({
  218. type: SET_TOOLBOX_TIMEOUT,
  219. handler,
  220. timeoutMS
  221. });
  222. };
  223. }