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 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. /* @flow */
  2. import Recording from '../../../modules/UI/recording/Recording';
  3. import SideContainerToggler
  4. from '../../../modules/UI/side_pannels/SideContainerToggler';
  5. import UIEvents from '../../../service/UI/UIEvents';
  6. import {
  7. changeLocalRaiseHand,
  8. clearToolboxTimeout,
  9. setSubjectSlideIn,
  10. setToolbarButton,
  11. setToolboxTimeout,
  12. setToolboxTimeoutMS,
  13. setToolboxVisible,
  14. toggleFullScreen,
  15. toggleToolbarButton
  16. } from './actions.native';
  17. import { SET_DEFAULT_TOOLBOX_BUTTONS } from './actionTypes';
  18. import {
  19. getButton,
  20. getDefaultToolboxButtons,
  21. isButtonEnabled
  22. } from './functions';
  23. declare var $: Function;
  24. declare var APP: Object;
  25. declare var config: Object;
  26. declare var interfaceConfig: Object;
  27. export * from './actions.native';
  28. /**
  29. * Checks whether desktop sharing is enabled and whether
  30. * we have params to start automatically sharing.
  31. *
  32. * @returns {Function}
  33. */
  34. export function checkAutoEnableDesktopSharing(): Function {
  35. return () => {
  36. // XXX Should use dispatcher to toggle screensharing but screensharing
  37. // hasn't been React-ified yet.
  38. if (isButtonEnabled('desktop')
  39. && config.autoEnableDesktopSharing) {
  40. APP.UI.eventEmitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  41. }
  42. };
  43. }
  44. /**
  45. * Dispatches an action to hide any popups displayed by the associated button.
  46. *
  47. * @param {string} buttonName - The name of the button as specified in the
  48. * button configurations for the toolbar.
  49. * @returns {Function}
  50. */
  51. export function clearButtonPopup(buttonName) {
  52. return (dispatch, getState) => {
  53. _clearPopupTimeout(buttonName, getState());
  54. dispatch(setToolbarButton(buttonName, {
  55. popupDisplay: null
  56. }));
  57. };
  58. }
  59. /**
  60. * Docks/undocks the Toolbox.
  61. *
  62. * @param {boolean} dock - True if dock, false otherwise.
  63. * @returns {Function}
  64. */
  65. export function dockToolbox(dock: boolean): Function {
  66. return (dispatch: Dispatch<*>, getState: Function) => {
  67. if (interfaceConfig.filmStripOnly) {
  68. return;
  69. }
  70. const { timeoutMS, visible } = getState()['features/toolbox'];
  71. if (dock) {
  72. // First make sure the toolbox is shown.
  73. visible || dispatch(showToolbox());
  74. dispatch(clearToolboxTimeout());
  75. } else if (visible) {
  76. dispatch(
  77. setToolboxTimeout(
  78. () => dispatch(hideToolbox()),
  79. timeoutMS));
  80. } else {
  81. dispatch(showToolbox());
  82. }
  83. };
  84. }
  85. /**
  86. * Returns button on mount/unmount handlers with dispatch function stored in
  87. * closure.
  88. *
  89. * @param {Function} dispatch - Redux action dispatcher.
  90. * @param {Function} getState - The function fetching the Redux state.
  91. * @returns {Object} Button on mount/unmount handlers.
  92. * @private
  93. */
  94. function _getButtonHandlers(dispatch, getState) {
  95. const localRaiseHandHandler
  96. = (...args) => dispatch(changeLocalRaiseHand(...args));
  97. const toggleFullScreenHandler
  98. = (...args) => dispatch(toggleFullScreen(...args));
  99. return {
  100. /**
  101. * Mount handler for desktop button.
  102. *
  103. * @type {Object}
  104. */
  105. desktop: {
  106. onMount: () => dispatch(showDesktopSharingButton())
  107. },
  108. /**
  109. * Mount/Unmount handler for toggling fullscreen button.
  110. *
  111. * @type {Object}
  112. */
  113. fullscreen: {
  114. onMount: () =>
  115. APP.UI.addListener(
  116. UIEvents.FULLSCREEN_TOGGLED,
  117. toggleFullScreenHandler),
  118. onUnmount: () =>
  119. APP.UI.removeListener(
  120. UIEvents.FULLSCREEN_TOGGLED,
  121. toggleFullScreenHandler)
  122. },
  123. /**
  124. * Mount handler for profile button.
  125. *
  126. * @type {Object}
  127. */
  128. profile: {
  129. onMount: () =>
  130. getState()['features/jwt']
  131. || dispatch(setProfileButtonUnclickable(true))
  132. },
  133. /**
  134. * Mount/Unmount handlers for raisehand button.
  135. *
  136. * @type {button}
  137. */
  138. raisehand: {
  139. onMount: () =>
  140. APP.UI.addListener(
  141. UIEvents.LOCAL_RAISE_HAND_CHANGED,
  142. localRaiseHandHandler),
  143. onUnmount: () =>
  144. APP.UI.removeListener(
  145. UIEvents.LOCAL_RAISE_HAND_CHANGED,
  146. localRaiseHandHandler)
  147. },
  148. /**
  149. * Mount handler for recording button.
  150. *
  151. * @type {Object}
  152. */
  153. recording: {
  154. onMount: () =>
  155. config.enableRecording && dispatch(showRecordingButton())
  156. }
  157. };
  158. }
  159. /**
  160. * Hides the toolbox.
  161. *
  162. * @param {boolean} force - True to force the hiding of the toolbox without
  163. * caring about the extended toolbar side panels.
  164. * @returns {Function}
  165. */
  166. export function hideToolbox(force: boolean = false): Function {
  167. return (dispatch: Dispatch<*>, getState: Function) => {
  168. const state = getState();
  169. const {
  170. alwaysVisible,
  171. hovered,
  172. timeoutMS
  173. } = state['features/toolbox'];
  174. if (alwaysVisible) {
  175. return;
  176. }
  177. dispatch(clearToolboxTimeout());
  178. if (!force
  179. && (hovered
  180. || state['features/jwt'].callOverlayVisible
  181. || SideContainerToggler.isVisible())) {
  182. dispatch(
  183. setToolboxTimeout(
  184. () => dispatch(hideToolbox()),
  185. timeoutMS));
  186. } else {
  187. dispatch(setToolboxVisible(false));
  188. dispatch(setSubjectSlideIn(false));
  189. }
  190. };
  191. }
  192. /**
  193. * Dispatches an action to show the popup associated with a button. Sets a
  194. * timeout to be fired which will dismiss the popup.
  195. *
  196. * @param {string} buttonName - The name of the button as specified in the
  197. * button configurations for the toolbar.
  198. * @param {string} popupName - The id of the popup to show as specified in
  199. * the button configurations for the toolbar.
  200. * @param {number} timeout - The time in milliseconds to show the popup.
  201. * @returns {Function}
  202. */
  203. export function setButtonPopupTimeout(buttonName, popupName, timeout) {
  204. return (dispatch, getState) => {
  205. _clearPopupTimeout(buttonName, getState());
  206. const newTimeoutId = setTimeout(() => {
  207. dispatch(clearButtonPopup(buttonName));
  208. }, timeout);
  209. dispatch(setToolbarButton(buttonName, {
  210. popupDisplay: {
  211. popupID: popupName,
  212. timeoutID: newTimeoutId
  213. }
  214. }));
  215. };
  216. }
  217. /**
  218. * Sets the default toolbar buttons of the Toolbox.
  219. *
  220. * @returns {Function}
  221. */
  222. export function setDefaultToolboxButtons(): Function {
  223. return (dispatch: Dispatch, getState: Function) => {
  224. // Save dispatch function in closure.
  225. const buttonHandlers = _getButtonHandlers(dispatch, getState);
  226. const toolboxButtons = getDefaultToolboxButtons(buttonHandlers);
  227. dispatch({
  228. type: SET_DEFAULT_TOOLBOX_BUTTONS,
  229. ...toolboxButtons
  230. });
  231. };
  232. }
  233. /**
  234. * Signals that unclickable property of profile button should change its value.
  235. *
  236. * @param {boolean} unclickable - Shows whether button is unclickable.
  237. * @returns {Function}
  238. */
  239. export function setProfileButtonUnclickable(unclickable: boolean): Function {
  240. return (dispatch: Dispatch<*>) => {
  241. const buttonName = 'profile';
  242. dispatch(setToolbarButton(buttonName, {
  243. unclickable
  244. }));
  245. };
  246. }
  247. /**
  248. * Shows desktop sharing button.
  249. *
  250. * @returns {Function}
  251. */
  252. export function showDesktopSharingButton(): Function {
  253. return (dispatch: Dispatch<*>) => {
  254. const buttonName = 'desktop';
  255. const disabledTooltipText
  256. = APP.conference.desktopSharingDisabledTooltip;
  257. const showTooltip
  258. = disabledTooltipText
  259. && APP.conference.isDesktopSharingDisabledByConfig;
  260. const visible
  261. = isButtonEnabled(buttonName)
  262. && (APP.conference.isDesktopSharingEnabled || showTooltip);
  263. const newState = {
  264. enabled: APP.conference.isDesktopSharingEnabled,
  265. hidden: !visible,
  266. tooltipText: showTooltip ? disabledTooltipText : undefined
  267. };
  268. dispatch(setToolbarButton(buttonName, newState));
  269. };
  270. }
  271. /**
  272. * Shows or hides the dialpad button.
  273. *
  274. * @param {boolean} show - Flag showing whether to show button or not.
  275. * @returns {Function}
  276. */
  277. export function showDialPadButton(show: boolean): Function {
  278. return (dispatch: Dispatch<*>) => {
  279. const buttonName = 'dialpad';
  280. if (show && isButtonEnabled(buttonName)) {
  281. dispatch(setToolbarButton(buttonName, {
  282. hidden: false
  283. }));
  284. }
  285. };
  286. }
  287. /**
  288. * Shows recording button.
  289. *
  290. * @returns {Function}
  291. */
  292. export function showRecordingButton(): Function {
  293. return (dispatch: Dispatch<*>) => {
  294. dispatch(setToolbarButton('recording', {
  295. hidden: false
  296. }));
  297. Recording.initRecordingButton();
  298. };
  299. }
  300. /**
  301. * Shows or hides the 'shared video' button.
  302. *
  303. * @returns {Function}
  304. */
  305. export function showSharedVideoButton(): Function {
  306. return (dispatch: Dispatch<*>) => {
  307. const buttonName = 'sharedvideo';
  308. if (isButtonEnabled(buttonName)
  309. && !config.disableThirdPartyRequests) {
  310. dispatch(setToolbarButton(buttonName, {
  311. hidden: false
  312. }));
  313. }
  314. };
  315. }
  316. /**
  317. * Shows the dial out button if it's required and appropriate
  318. * flag is passed.
  319. *
  320. * @param {boolean} show - Flag showing whether to show button or not.
  321. * @returns {Function}
  322. */
  323. export function showDialOutButton(show: boolean): Function {
  324. return (dispatch: Dispatch<*>, getState: Function) => {
  325. const buttonName = 'dialout';
  326. if (show
  327. && APP.conference.sipGatewayEnabled()
  328. && isButtonEnabled(buttonName)
  329. && (!config.enableUserRolesBasedOnToken
  330. || !getState()['features/jwt'].isGuest)) {
  331. dispatch(setToolbarButton(buttonName, {
  332. hidden: false
  333. }));
  334. }
  335. };
  336. }
  337. /**
  338. * Shows the toolbox for specified timeout.
  339. *
  340. * @param {number} timeout - Timeout for showing the toolbox.
  341. * @returns {Function}
  342. */
  343. export function showToolbox(timeout: number = 0): Object {
  344. return (dispatch: Dispatch<*>, getState: Function) => {
  345. const state = getState();
  346. const {
  347. alwaysVisible,
  348. enabled,
  349. timeoutMS,
  350. visible
  351. } = state['features/toolbox'];
  352. if (enabled && !visible) {
  353. dispatch(setToolboxVisible(true));
  354. dispatch(setSubjectSlideIn(true));
  355. // If the Toolbox is always visible, there's no need for a timeout
  356. // to toggle its visibility.
  357. if (!alwaysVisible) {
  358. dispatch(
  359. setToolboxTimeout(
  360. () => dispatch(hideToolbox()),
  361. timeout || timeoutMS));
  362. dispatch(setToolboxTimeoutMS(interfaceConfig.TOOLBAR_TIMEOUT));
  363. }
  364. }
  365. };
  366. }
  367. /**
  368. * Event handler for side toolbar container toggled event.
  369. *
  370. * @param {string} containerId - ID of the container.
  371. * @returns {Function}
  372. */
  373. export function toggleSideToolbarContainer(containerId: string): Function {
  374. return (dispatch: Dispatch, getState: Function) => {
  375. const { secondaryToolbarButtons } = getState()['features/toolbox'];
  376. for (const key of secondaryToolbarButtons.keys()) {
  377. const button = secondaryToolbarButtons.get(key);
  378. if (isButtonEnabled(key)
  379. && button.sideContainerId
  380. && button.sideContainerId === containerId) {
  381. dispatch(toggleToolbarButton(key));
  382. break;
  383. }
  384. }
  385. };
  386. }
  387. /**
  388. * Clears the timeout set for hiding a button popup.
  389. *
  390. * @param {string} buttonName - The name of the button as specified in the
  391. * button configurations for the toolbar.
  392. * @param {Object} state - The redux state in which the button is expected to
  393. * be defined.
  394. * @private
  395. * @returns {void}
  396. */
  397. function _clearPopupTimeout(buttonName, state) {
  398. const { popupDisplay } = getButton(buttonName, state);
  399. const { timeoutID } = popupDisplay || {};
  400. clearTimeout(timeoutID);
  401. }