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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. /* @flow */
  2. import Recording from '../../../modules/UI/recording/Recording';
  3. import SideContainerToggler
  4. from '../../../modules/UI/side_pannels/SideContainerToggler';
  5. import { removeTooltip } from '../../../modules/UI/util/Tooltip';
  6. import UIEvents from '../../../service/UI/UIEvents';
  7. import {
  8. changeLocalRaiseHand,
  9. clearToolboxTimeout,
  10. setSubjectSlideIn,
  11. setToolbarButton,
  12. setToolboxTimeout,
  13. setToolboxTimeoutMS,
  14. setToolboxVisible,
  15. toggleFullScreen,
  16. toggleToolbarButton
  17. } from './actions.native';
  18. import { SET_DEFAULT_TOOLBOX_BUTTONS } from './actionTypes';
  19. import {
  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. * Docks/undocks the Toolbox.
  46. *
  47. * @param {boolean} dock - True if dock, false otherwise.
  48. * @returns {Function}
  49. */
  50. export function dockToolbox(dock: boolean): Function {
  51. return (dispatch: Dispatch<*>, getState: Function) => {
  52. if (interfaceConfig.filmStripOnly) {
  53. return;
  54. }
  55. const { timeoutMS, visible } = getState()['features/toolbox'];
  56. if (dock) {
  57. // First make sure the toolbox is shown.
  58. visible || dispatch(showToolbox());
  59. dispatch(clearToolboxTimeout());
  60. } else if (visible) {
  61. dispatch(
  62. setToolboxTimeout(
  63. () => dispatch(hideToolbox()),
  64. timeoutMS));
  65. } else {
  66. dispatch(showToolbox());
  67. }
  68. };
  69. }
  70. /**
  71. * Returns button on mount/unmount handlers with dispatch function stored in
  72. * closure.
  73. *
  74. * @param {Function} dispatch - Redux action dispatcher.
  75. * @param {Function} getState - The function fetching the Redux state.
  76. * @returns {Object} Button on mount/unmount handlers.
  77. * @private
  78. */
  79. function _getButtonHandlers(dispatch, getState) {
  80. const localRaiseHandHandler
  81. = (...args) => dispatch(changeLocalRaiseHand(...args));
  82. const toggleFullScreenHandler
  83. = (...args) => dispatch(toggleFullScreen(...args));
  84. return {
  85. /**
  86. * Mount handler for desktop button.
  87. *
  88. * @type {Object}
  89. */
  90. desktop: {
  91. onMount: () => dispatch(showDesktopSharingButton())
  92. },
  93. /**
  94. * Mount/Unmount handler for toggling fullscreen button.
  95. *
  96. * @type {Object}
  97. */
  98. fullscreen: {
  99. onMount: () =>
  100. APP.UI.addListener(
  101. UIEvents.FULLSCREEN_TOGGLED,
  102. toggleFullScreenHandler),
  103. onUnmount: () =>
  104. APP.UI.removeListener(
  105. UIEvents.FULLSCREEN_TOGGLED,
  106. toggleFullScreenHandler)
  107. },
  108. /**
  109. * Mount handler for profile button.
  110. *
  111. * @type {Object}
  112. */
  113. profile: {
  114. onMount: () =>
  115. getState()['features/jwt']
  116. || dispatch(setProfileButtonUnclickable(true))
  117. },
  118. /**
  119. * Mount/Unmount handlers for raisehand button.
  120. *
  121. * @type {button}
  122. */
  123. raisehand: {
  124. onMount: () =>
  125. APP.UI.addListener(
  126. UIEvents.LOCAL_RAISE_HAND_CHANGED,
  127. localRaiseHandHandler),
  128. onUnmount: () =>
  129. APP.UI.removeListener(
  130. UIEvents.LOCAL_RAISE_HAND_CHANGED,
  131. localRaiseHandHandler)
  132. },
  133. /**
  134. * Mount handler for recording button.
  135. *
  136. * @type {Object}
  137. */
  138. recording: {
  139. onMount: () =>
  140. config.enableRecording && dispatch(showRecordingButton())
  141. }
  142. };
  143. }
  144. /**
  145. * Hides the toolbox.
  146. *
  147. * @param {boolean} force - True to force the hiding of the toolbox without
  148. * caring about the extended toolbar side panels.
  149. * @returns {Function}
  150. */
  151. export function hideToolbox(force: boolean = false): Function {
  152. return (dispatch: Dispatch<*>, getState: Function) => {
  153. const state = getState();
  154. const {
  155. alwaysVisible,
  156. hovered,
  157. timeoutMS
  158. } = state['features/toolbox'];
  159. if (alwaysVisible) {
  160. return;
  161. }
  162. dispatch(clearToolboxTimeout());
  163. if (!force
  164. && (hovered
  165. || state['features/jwt'].callOverlayVisible
  166. || SideContainerToggler.isVisible())) {
  167. dispatch(
  168. setToolboxTimeout(
  169. () => dispatch(hideToolbox()),
  170. timeoutMS));
  171. } else {
  172. dispatch(setToolboxVisible(false));
  173. dispatch(setSubjectSlideIn(false));
  174. }
  175. };
  176. }
  177. /**
  178. * Sets the default toolbar buttons of the Toolbox.
  179. *
  180. * @returns {Function}
  181. */
  182. export function setDefaultToolboxButtons(): Function {
  183. return (dispatch: Dispatch, getState: Function) => {
  184. // Save dispatch function in closure.
  185. const buttonHandlers = _getButtonHandlers(dispatch, getState);
  186. const toolboxButtons = getDefaultToolboxButtons(buttonHandlers);
  187. dispatch({
  188. type: SET_DEFAULT_TOOLBOX_BUTTONS,
  189. ...toolboxButtons
  190. });
  191. };
  192. }
  193. /**
  194. * Signals that unclickable property of profile button should change its value.
  195. *
  196. * @param {boolean} unclickable - Shows whether button is unclickable.
  197. * @returns {Function}
  198. */
  199. export function setProfileButtonUnclickable(unclickable: boolean): Function {
  200. return (dispatch: Dispatch<*>) => {
  201. const buttonName = 'profile';
  202. dispatch(setToolbarButton(buttonName, {
  203. unclickable
  204. }));
  205. removeTooltip(document.getElementById('toolbar_button_profile'));
  206. };
  207. }
  208. /**
  209. * Shows desktop sharing button.
  210. *
  211. * @returns {Function}
  212. */
  213. export function showDesktopSharingButton(): Function {
  214. return (dispatch: Dispatch<*>) => {
  215. const buttonName = 'desktop';
  216. const disabledTooltipText
  217. = APP.conference.desktopSharingDisabledTooltip;
  218. const showTooltip
  219. = disabledTooltipText
  220. && APP.conference.isDesktopSharingDisabledByConfig;
  221. const visible
  222. = isButtonEnabled(buttonName)
  223. && (APP.conference.isDesktopSharingEnabled || showTooltip);
  224. const newState = {
  225. enabled: APP.conference.isDesktopSharingEnabled,
  226. hidden: !visible,
  227. tooltipText: showTooltip ? disabledTooltipText : undefined
  228. };
  229. dispatch(setToolbarButton(buttonName, newState));
  230. };
  231. }
  232. /**
  233. * Shows or hides the dialpad button.
  234. *
  235. * @param {boolean} show - Flag showing whether to show button or not.
  236. * @returns {Function}
  237. */
  238. export function showDialPadButton(show: boolean): Function {
  239. return (dispatch: Dispatch<*>) => {
  240. const buttonName = 'dialpad';
  241. if (show && isButtonEnabled(buttonName)) {
  242. dispatch(setToolbarButton(buttonName, {
  243. hidden: false
  244. }));
  245. }
  246. };
  247. }
  248. /**
  249. * Shows recording button.
  250. *
  251. * @returns {Function}
  252. */
  253. export function showRecordingButton(): Function {
  254. return (dispatch: Dispatch<*>) => {
  255. dispatch(setToolbarButton('recording', {
  256. hidden: false
  257. }));
  258. Recording.initRecordingButton();
  259. };
  260. }
  261. /**
  262. * Shows or hides the 'shared video' button.
  263. *
  264. * @returns {Function}
  265. */
  266. export function showSharedVideoButton(): Function {
  267. return (dispatch: Dispatch<*>) => {
  268. const buttonName = 'sharedvideo';
  269. if (isButtonEnabled(buttonName)
  270. && !config.disableThirdPartyRequests) {
  271. dispatch(setToolbarButton(buttonName, {
  272. hidden: false
  273. }));
  274. }
  275. };
  276. }
  277. /**
  278. * Shows the dial out button if it's required and appropriate
  279. * flag is passed.
  280. *
  281. * @param {boolean} show - Flag showing whether to show button or not.
  282. * @returns {Function}
  283. */
  284. export function showDialOutButton(show: boolean): Function {
  285. return (dispatch: Dispatch<*>, getState: Function) => {
  286. const buttonName = 'dialout';
  287. if (show
  288. && APP.conference.sipGatewayEnabled()
  289. && isButtonEnabled(buttonName)
  290. && (!config.enableUserRolesBasedOnToken
  291. || !getState()['features/jwt'].isGuest)) {
  292. dispatch(setToolbarButton(buttonName, {
  293. hidden: false
  294. }));
  295. }
  296. };
  297. }
  298. /**
  299. * Shows the toolbox for specified timeout.
  300. *
  301. * @param {number} timeout - Timeout for showing the toolbox.
  302. * @returns {Function}
  303. */
  304. export function showToolbox(timeout: number = 0): Object {
  305. return (dispatch: Dispatch<*>, getState: Function) => {
  306. const state = getState();
  307. const {
  308. alwaysVisible,
  309. enabled,
  310. timeoutMS,
  311. visible
  312. } = state['features/toolbox'];
  313. if (enabled && !visible) {
  314. dispatch(setToolboxVisible(true));
  315. dispatch(setSubjectSlideIn(true));
  316. // If the Toolbox is always visible, there's no need for a timeout
  317. // to toggle its visibility.
  318. if (!alwaysVisible) {
  319. dispatch(
  320. setToolboxTimeout(
  321. () => dispatch(hideToolbox()),
  322. timeout || timeoutMS));
  323. dispatch(setToolboxTimeoutMS(interfaceConfig.TOOLBAR_TIMEOUT));
  324. }
  325. }
  326. };
  327. }
  328. /**
  329. * Event handler for side toolbar container toggled event.
  330. *
  331. * @param {string} containerId - ID of the container.
  332. * @returns {Function}
  333. */
  334. export function toggleSideToolbarContainer(containerId: string): Function {
  335. return (dispatch: Dispatch, getState: Function) => {
  336. const { secondaryToolbarButtons } = getState()['features/toolbox'];
  337. for (const key of secondaryToolbarButtons.keys()) {
  338. const button = secondaryToolbarButtons.get(key);
  339. if (isButtonEnabled(key)
  340. && button.sideContainerId
  341. && button.sideContainerId === containerId) {
  342. dispatch(toggleToolbarButton(key));
  343. break;
  344. }
  345. }
  346. };
  347. }