Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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_OVERFLOW_DRAWER,
  11. SET_OVERFLOW_MENU_VISIBLE,
  12. SET_TOOLBAR_HOVERED,
  13. SET_TOOLBOX_TIMEOUT
  14. } from './actionTypes';
  15. import { setToolboxVisible } from './actions.web';
  16. import { getToolbarTimeout } from './functions.web';
  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) {
  25. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  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 = false) {
  67. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  68. const state = getState();
  69. const { toolbarConfig } = state['features/base/config'];
  70. const alwaysVisible = toolbarConfig?.alwaysVisible;
  71. const autoHideWhileChatIsOpen = toolbarConfig?.autoHideWhileChatIsOpen;
  72. const { hovered } = state['features/toolbox'];
  73. const toolbarTimeout = getToolbarTimeout(state);
  74. if (alwaysVisible) {
  75. return;
  76. }
  77. dispatch(clearToolboxTimeout());
  78. const hoverSelector = isLayoutTileView(state)
  79. ? '.remotevideomenu:hover'
  80. : '.filmstrip:hover,.remotevideomenu:hover';
  81. const hoveredElem = document.querySelector(hoverSelector);
  82. if (!force
  83. && (hovered
  84. || state['features/invite'].calleeInfoVisible
  85. || (state['features/chat'].isOpen && !autoHideWhileChatIsOpen)
  86. || hoveredElem)) {
  87. dispatch(
  88. setToolboxTimeout(
  89. () => dispatch(hideToolbox()),
  90. toolbarTimeout));
  91. } else {
  92. dispatch(setToolboxVisible(false));
  93. }
  94. };
  95. }
  96. /**
  97. * Signals a request to enter or exit full screen mode.
  98. *
  99. * @param {boolean} fullScreen - True to enter full screen mode, false to exit.
  100. * @returns {{
  101. * type: SET_FULL_SCREEN,
  102. * fullScreen: boolean
  103. * }}
  104. */
  105. export function setFullScreen(fullScreen: boolean) {
  106. return {
  107. type: SET_FULL_SCREEN,
  108. fullScreen
  109. };
  110. }
  111. /**
  112. * Shows the toolbox for specified timeout.
  113. *
  114. * @param {number} timeout - Timeout for showing the toolbox.
  115. * @returns {Function}
  116. */
  117. export function showToolbox(timeout = 0) {
  118. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  119. const state = getState();
  120. const { toolbarConfig } = state['features/base/config'];
  121. const toolbarTimeout = getToolbarTimeout(state);
  122. const initialTimeout = toolbarConfig?.initialTimeout;
  123. const alwaysVisible = toolbarConfig?.alwaysVisible;
  124. const {
  125. enabled,
  126. visible
  127. } = state['features/toolbox'];
  128. if (enabled && !visible) {
  129. dispatch(setToolboxVisible(true));
  130. // If the Toolbox is always visible, there's no need for a timeout
  131. // to toggle its visibility.
  132. if (!alwaysVisible) {
  133. if (typeof initialTimeout === 'number') {
  134. // reset `initialTimeout` once it is consumed once
  135. dispatch(overwriteConfig({ toolbarConfig: {
  136. ...toolbarConfig,
  137. initialTimeout: null
  138. } }));
  139. }
  140. dispatch(
  141. setToolboxTimeout(
  142. () => dispatch(hideToolbox()),
  143. timeout || initialTimeout || toolbarTimeout));
  144. }
  145. }
  146. };
  147. }
  148. /**
  149. * Signals a request to display overflow as drawer.
  150. *
  151. * @param {boolean} displayAsDrawer - True to display overflow as drawer, false to preserve original behaviour.
  152. * @returns {{
  153. * type: SET_OVERFLOW_DRAWER,
  154. * displayAsDrawer: boolean
  155. * }}
  156. */
  157. export function setOverflowDrawer(displayAsDrawer: boolean) {
  158. return {
  159. type: SET_OVERFLOW_DRAWER,
  160. displayAsDrawer
  161. };
  162. }
  163. /**
  164. * Signals that toolbox timeout should be cleared.
  165. *
  166. * @returns {{
  167. * type: CLEAR_TOOLBOX_TIMEOUT
  168. * }}
  169. */
  170. export function clearToolboxTimeout() {
  171. return {
  172. type: CLEAR_TOOLBOX_TIMEOUT
  173. };
  174. }
  175. /**
  176. * Shows/hides the hangup menu.
  177. *
  178. * @param {boolean} visible - True to show it or false to hide it.
  179. * @returns {{
  180. * type: SET_HANGUP_MENU_VISIBLE,
  181. * visible: boolean
  182. * }}
  183. */
  184. export function setHangupMenuVisible(visible: boolean) {
  185. return {
  186. type: SET_HANGUP_MENU_VISIBLE,
  187. visible
  188. };
  189. }
  190. /**
  191. * Shows/hides the overflow menu.
  192. *
  193. * @param {boolean} visible - True to show it or false to hide it.
  194. * @returns {{
  195. * type: SET_OVERFLOW_MENU_VISIBLE,
  196. * visible: boolean
  197. * }}
  198. */
  199. export function setOverflowMenuVisible(visible: boolean) {
  200. return {
  201. type: SET_OVERFLOW_MENU_VISIBLE,
  202. visible
  203. };
  204. }
  205. /**
  206. * Signals that toolbar is hovered value should be changed.
  207. *
  208. * @param {boolean} hovered - Flag showing whether toolbar is hovered.
  209. * @returns {{
  210. * type: SET_TOOLBAR_HOVERED,
  211. * hovered: boolean
  212. * }}
  213. */
  214. export function setToolbarHovered(hovered: boolean) {
  215. return {
  216. type: SET_TOOLBAR_HOVERED,
  217. hovered
  218. };
  219. }
  220. /**
  221. * Dispatches an action which sets new timeout for the toolbox visibility and clears the previous one.
  222. * On mobile browsers the toolbox does not hide on timeout. It is toggled on simple tap.
  223. *
  224. * @param {Function} handler - Function to be invoked after the timeout.
  225. * @param {number} timeoutMS - Delay.
  226. * @returns {{
  227. * type: SET_TOOLBOX_TIMEOUT,
  228. * handler: Function,
  229. * timeoutMS: number
  230. * }}
  231. */
  232. export function setToolboxTimeout(handler: Function, timeoutMS: number) {
  233. return function(dispatch: IStore['dispatch']) {
  234. if (isMobileBrowser()) {
  235. return;
  236. }
  237. dispatch({
  238. type: SET_TOOLBOX_TIMEOUT,
  239. handler,
  240. timeoutMS
  241. });
  242. };
  243. }
  244. /**
  245. * Closes the overflow menu if opened.
  246. *
  247. * @private
  248. * @returns {void}
  249. */
  250. export function closeOverflowMenuIfOpen() {
  251. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  252. const { overflowMenuVisible } = getState()['features/toolbox'];
  253. overflowMenuVisible && dispatch(setOverflowMenuVisible(false));
  254. };
  255. }