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

actions.web.ts 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. import { IStore } from '../app/types';
  2. import { overwriteConfig } from '../base/config/actions';
  3. import { isMobileBrowser } from '../base/environment/utils';
  4. import { isLayoutTileView } from '../video-layout/functions.any';
  5. import {
  6. CLEAR_TOOLBOX_TIMEOUT,
  7. FULL_SCREEN_CHANGED,
  8. SET_FULL_SCREEN,
  9. SET_HANGUP_MENU_VISIBLE,
  10. SET_MAIN_TOOLBAR_BUTTONS_THRESHOLDS,
  11. SET_OVERFLOW_DRAWER,
  12. SET_OVERFLOW_MENU_VISIBLE,
  13. SET_TOOLBAR_HOVERED,
  14. SET_TOOLBOX_TIMEOUT
  15. } from './actionTypes';
  16. import { setToolboxVisible } from './actions.web';
  17. import { THRESHOLDS } from './constants';
  18. import { getToolbarTimeout } from './functions.web';
  19. import { IMainToolbarButtonThresholds } from './types';
  20. export * from './actions.any';
  21. /**
  22. * Docks/undocks the Toolbox.
  23. *
  24. * @param {boolean} dock - True if dock, false otherwise.
  25. * @returns {Function}
  26. */
  27. export function dockToolbox(dock: boolean) {
  28. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  29. const state = getState();
  30. const { visible } = state['features/toolbox'];
  31. const toolbarTimeout = getToolbarTimeout(state);
  32. if (dock) {
  33. // First make sure the toolbox is shown.
  34. visible || dispatch(showToolbox());
  35. dispatch(clearToolboxTimeout());
  36. } else if (visible) {
  37. dispatch(
  38. setToolboxTimeout(
  39. () => dispatch(hideToolbox()),
  40. toolbarTimeout));
  41. } else {
  42. dispatch(showToolbox());
  43. }
  44. };
  45. }
  46. /**
  47. * Signals that full screen mode has been entered or exited.
  48. *
  49. * @param {boolean} fullScreen - Whether or not full screen mode is currently
  50. * enabled.
  51. * @returns {{
  52. * type: FULL_SCREEN_CHANGED,
  53. * fullScreen: boolean
  54. * }}
  55. */
  56. export function fullScreenChanged(fullScreen: boolean) {
  57. return {
  58. type: FULL_SCREEN_CHANGED,
  59. fullScreen
  60. };
  61. }
  62. /**
  63. * Hides the toolbox.
  64. *
  65. * @param {boolean} force - True to force the hiding of the toolbox without
  66. * caring about the extended toolbar side panels.
  67. * @returns {Function}
  68. */
  69. export function hideToolbox(force = false) {
  70. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  71. const state = getState();
  72. const { toolbarConfig } = state['features/base/config'];
  73. const alwaysVisible = toolbarConfig?.alwaysVisible;
  74. const autoHideWhileChatIsOpen = toolbarConfig?.autoHideWhileChatIsOpen;
  75. const { hovered } = state['features/toolbox'];
  76. const toolbarTimeout = getToolbarTimeout(state);
  77. if (alwaysVisible) {
  78. return;
  79. }
  80. dispatch(clearToolboxTimeout());
  81. const hoverSelector = isLayoutTileView(state)
  82. ? '.remotevideomenu:hover'
  83. : '.filmstrip:hover,.remotevideomenu:hover';
  84. const hoveredElem = document.querySelector(hoverSelector);
  85. if (!force
  86. && (hovered
  87. || state['features/invite'].calleeInfoVisible
  88. || (state['features/chat'].isOpen && !autoHideWhileChatIsOpen)
  89. || hoveredElem)) {
  90. dispatch(
  91. setToolboxTimeout(
  92. () => dispatch(hideToolbox()),
  93. toolbarTimeout));
  94. } else {
  95. dispatch(setToolboxVisible(false));
  96. }
  97. };
  98. }
  99. /**
  100. * Signals a request to enter or exit full screen mode.
  101. *
  102. * @param {boolean} fullScreen - True to enter full screen mode, false to exit.
  103. * @returns {{
  104. * type: SET_FULL_SCREEN,
  105. * fullScreen: boolean
  106. * }}
  107. */
  108. export function setFullScreen(fullScreen: boolean) {
  109. return {
  110. type: SET_FULL_SCREEN,
  111. fullScreen
  112. };
  113. }
  114. /**
  115. * Sets the mainToolbarButtonsThresholds.
  116. *
  117. * @returns {Function}
  118. */
  119. export function setMainToolbarThresholds() {
  120. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  121. const { mainToolbarButtons } = getState()['features/base/config'];
  122. if (!mainToolbarButtons || !Array.isArray(mainToolbarButtons) || mainToolbarButtons.length === 0) {
  123. return;
  124. }
  125. const mainToolbarButtonsThresholds: IMainToolbarButtonThresholds = [];
  126. const mainToolbarButtonsLenghtMap = new Map();
  127. let orderIsChanged = false;
  128. mainToolbarButtons.forEach(buttons => {
  129. if (!Array.isArray(buttons) || buttons.length === 0) {
  130. return;
  131. }
  132. mainToolbarButtonsLenghtMap.set(buttons.length, buttons);
  133. });
  134. THRESHOLDS.forEach(({ width, order }) => {
  135. let finalOrder = mainToolbarButtonsLenghtMap.get(order.length);
  136. if (finalOrder) {
  137. orderIsChanged = true;
  138. } else {
  139. finalOrder = order;
  140. }
  141. mainToolbarButtonsThresholds.push({
  142. order: finalOrder,
  143. width
  144. });
  145. });
  146. if (orderIsChanged) {
  147. dispatch({
  148. type: SET_MAIN_TOOLBAR_BUTTONS_THRESHOLDS,
  149. mainToolbarButtonsThresholds
  150. });
  151. }
  152. };
  153. }
  154. /**
  155. * Shows the toolbox for specified timeout.
  156. *
  157. * @param {number} timeout - Timeout for showing the toolbox.
  158. * @returns {Function}
  159. */
  160. export function showToolbox(timeout = 0) {
  161. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  162. const state = getState();
  163. const { toolbarConfig } = state['features/base/config'];
  164. const toolbarTimeout = getToolbarTimeout(state);
  165. const initialTimeout = toolbarConfig?.initialTimeout;
  166. const alwaysVisible = toolbarConfig?.alwaysVisible;
  167. const {
  168. enabled,
  169. visible
  170. } = state['features/toolbox'];
  171. if (enabled && !visible) {
  172. dispatch(setToolboxVisible(true));
  173. // If the Toolbox is always visible, there's no need for a timeout
  174. // to toggle its visibility.
  175. if (!alwaysVisible) {
  176. if (typeof initialTimeout === 'number') {
  177. // reset `initialTimeout` once it is consumed once
  178. dispatch(overwriteConfig({ toolbarConfig: {
  179. ...toolbarConfig,
  180. initialTimeout: null
  181. } }));
  182. }
  183. dispatch(
  184. setToolboxTimeout(
  185. () => dispatch(hideToolbox()),
  186. timeout || initialTimeout || toolbarTimeout));
  187. }
  188. }
  189. };
  190. }
  191. /**
  192. * Signals a request to display overflow as drawer.
  193. *
  194. * @param {boolean} displayAsDrawer - True to display overflow as drawer, false to preserve original behaviour.
  195. * @returns {{
  196. * type: SET_OVERFLOW_DRAWER,
  197. * displayAsDrawer: boolean
  198. * }}
  199. */
  200. export function setOverflowDrawer(displayAsDrawer: boolean) {
  201. return {
  202. type: SET_OVERFLOW_DRAWER,
  203. displayAsDrawer
  204. };
  205. }
  206. /**
  207. * Signals that toolbox timeout should be cleared.
  208. *
  209. * @returns {{
  210. * type: CLEAR_TOOLBOX_TIMEOUT
  211. * }}
  212. */
  213. export function clearToolboxTimeout() {
  214. return {
  215. type: CLEAR_TOOLBOX_TIMEOUT
  216. };
  217. }
  218. /**
  219. * Shows/hides the hangup menu.
  220. *
  221. * @param {boolean} visible - True to show it or false to hide it.
  222. * @returns {{
  223. * type: SET_HANGUP_MENU_VISIBLE,
  224. * visible: boolean
  225. * }}
  226. */
  227. export function setHangupMenuVisible(visible: boolean) {
  228. return {
  229. type: SET_HANGUP_MENU_VISIBLE,
  230. visible
  231. };
  232. }
  233. /**
  234. * Shows/hides the overflow menu.
  235. *
  236. * @param {boolean} visible - True to show it or false to hide it.
  237. * @returns {{
  238. * type: SET_OVERFLOW_MENU_VISIBLE,
  239. * visible: boolean
  240. * }}
  241. */
  242. export function setOverflowMenuVisible(visible: boolean) {
  243. return {
  244. type: SET_OVERFLOW_MENU_VISIBLE,
  245. visible
  246. };
  247. }
  248. /**
  249. * Signals that toolbar is hovered value should be changed.
  250. *
  251. * @param {boolean} hovered - Flag showing whether toolbar is hovered.
  252. * @returns {{
  253. * type: SET_TOOLBAR_HOVERED,
  254. * hovered: boolean
  255. * }}
  256. */
  257. export function setToolbarHovered(hovered: boolean) {
  258. return {
  259. type: SET_TOOLBAR_HOVERED,
  260. hovered
  261. };
  262. }
  263. /**
  264. * Dispatches an action which sets new timeout for the toolbox visibility and clears the previous one.
  265. * On mobile browsers the toolbox does not hide on timeout. It is toggled on simple tap.
  266. *
  267. * @param {Function} handler - Function to be invoked after the timeout.
  268. * @param {number} timeoutMS - Delay.
  269. * @returns {{
  270. * type: SET_TOOLBOX_TIMEOUT,
  271. * handler: Function,
  272. * timeoutMS: number
  273. * }}
  274. */
  275. export function setToolboxTimeout(handler: Function, timeoutMS: number) {
  276. return function(dispatch: IStore['dispatch']) {
  277. if (isMobileBrowser()) {
  278. return;
  279. }
  280. dispatch({
  281. type: SET_TOOLBOX_TIMEOUT,
  282. handler,
  283. timeoutMS
  284. });
  285. };
  286. }
  287. /**
  288. * Closes the overflow menu if opened.
  289. *
  290. * @private
  291. * @returns {void}
  292. */
  293. export function closeOverflowMenuIfOpen() {
  294. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  295. const { overflowMenuVisible } = getState()['features/toolbox'];
  296. overflowMenuVisible && dispatch(setOverflowMenuVisible(false));
  297. };
  298. }