您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

actions.web.ts 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. import { IStore } from '../app/types';
  2. import { overwriteConfig } from '../base/config/actions';
  3. import { isMobileBrowser } from '../base/environment/utils';
  4. import {
  5. CLEAR_TOOLBOX_TIMEOUT,
  6. FULL_SCREEN_CHANGED,
  7. SET_FULL_SCREEN,
  8. SET_HANGUP_MENU_VISIBLE,
  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.web';
  15. import { getToolbarTimeout } from './functions.web';
  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) {
  24. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  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 = false) {
  66. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  67. const state = getState();
  68. const { toolbarConfig } = state['features/base/config'];
  69. const alwaysVisible = toolbarConfig?.alwaysVisible;
  70. const autoHideWhileChatIsOpen = toolbarConfig?.autoHideWhileChatIsOpen;
  71. const { hovered } = state['features/toolbox'];
  72. const toolbarTimeout = getToolbarTimeout(state);
  73. if (alwaysVisible) {
  74. return;
  75. }
  76. dispatch(clearToolboxTimeout());
  77. const focusSelector = '.toolbox-content-items:focus-within,.filmstrip:focus-within,.remotevideomenu:hover';
  78. if (!force
  79. && (hovered
  80. || state['features/invite'].calleeInfoVisible
  81. || (state['features/chat'].isOpen && !autoHideWhileChatIsOpen)
  82. || document.querySelector(focusSelector))) {
  83. dispatch(
  84. setToolboxTimeout(
  85. () => dispatch(hideToolbox()),
  86. toolbarTimeout));
  87. } else {
  88. dispatch(setToolboxVisible(false));
  89. }
  90. };
  91. }
  92. /**
  93. * Signals a request to enter or exit full screen mode.
  94. *
  95. * @param {boolean} fullScreen - True to enter full screen mode, false to exit.
  96. * @returns {{
  97. * type: SET_FULL_SCREEN,
  98. * fullScreen: boolean
  99. * }}
  100. */
  101. export function setFullScreen(fullScreen: boolean) {
  102. return {
  103. type: SET_FULL_SCREEN,
  104. fullScreen
  105. };
  106. }
  107. /**
  108. * Shows the toolbox for specified timeout.
  109. *
  110. * @param {number} timeout - Timeout for showing the toolbox.
  111. * @returns {Function}
  112. */
  113. export function showToolbox(timeout = 0) {
  114. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  115. const state = getState();
  116. const { toolbarConfig } = state['features/base/config'];
  117. const toolbarTimeout = getToolbarTimeout(state);
  118. const initialTimeout = toolbarConfig?.initialTimeout;
  119. const alwaysVisible = toolbarConfig?.alwaysVisible;
  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() {
  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) {
  229. return function(dispatch: IStore['dispatch']) {
  230. if (isMobileBrowser()) {
  231. return;
  232. }
  233. dispatch({
  234. type: SET_TOOLBOX_TIMEOUT,
  235. handler,
  236. timeoutMS
  237. });
  238. };
  239. }