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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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 UIUtil from '../../../modules/UI/util/UIUtil';
  7. import {
  8. clearToolbarTimeout,
  9. setAlwaysVisibleToolbar,
  10. setSubjectSlideIn,
  11. setToolbarButton,
  12. setToolbarTimeout,
  13. setToolbarTimeoutNumber,
  14. setToolbarVisible,
  15. toggleToolbarButton
  16. } from './actions.native';
  17. export * from './actions.native';
  18. declare var $: Function;
  19. declare var APP: Object;
  20. declare var config: Object;
  21. declare var interfaceConfig: Object;
  22. /**
  23. * Checks whether desktop sharing is enabled and whether
  24. * we have params to start automatically sharing.
  25. *
  26. * @returns {Function}
  27. */
  28. export function checkAutoEnableDesktopSharing(): Function {
  29. return () => {
  30. // XXX Should use dispatcher to toggle screensharing but screensharing
  31. // hasn't been React-ified yet.
  32. if (UIUtil.isButtonEnabled('desktop')
  33. && config.autoEnableDesktopSharing) {
  34. APP.UI.eventEmitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  35. }
  36. };
  37. }
  38. /**
  39. * Docks/undocks toolbar based on its parameter.
  40. *
  41. * @param {boolean} dock - True if dock, false otherwise.
  42. * @returns {Function}
  43. */
  44. export function dockToolbar(dock: boolean): Function {
  45. return (dispatch: Dispatch<*>, getState: Function) => {
  46. if (interfaceConfig.filmStripOnly) {
  47. return;
  48. }
  49. const state = getState();
  50. const { toolbarTimeout, visible } = state['features/toolbar'];
  51. if (dock) {
  52. // First make sure the toolbar is shown.
  53. visible || dispatch(showToolbar());
  54. dispatch(clearToolbarTimeout());
  55. } else if (visible) {
  56. dispatch(
  57. setToolbarTimeout(
  58. () => dispatch(hideToolbar()),
  59. toolbarTimeout));
  60. } else {
  61. dispatch(showToolbar());
  62. }
  63. };
  64. }
  65. /**
  66. * Hides the toolbar.
  67. *
  68. * @param {boolean} force - True to force the hiding of the toolbar without
  69. * caring about the extended toolbar side panels.
  70. * @returns {Function}
  71. */
  72. export function hideToolbar(force: boolean = false): Function {
  73. return (dispatch: Dispatch<*>, getState: Function) => {
  74. const state = getState();
  75. const {
  76. alwaysVisible,
  77. hovered,
  78. toolbarTimeout
  79. } = state['features/toolbar'];
  80. if (alwaysVisible) {
  81. return;
  82. }
  83. dispatch(clearToolbarTimeout());
  84. if (!force
  85. && (hovered
  86. || APP.UI.isRingOverlayVisible()
  87. || SideContainerToggler.isVisible())) {
  88. dispatch(
  89. setToolbarTimeout(
  90. () => dispatch(hideToolbar()),
  91. toolbarTimeout));
  92. } else {
  93. dispatch(setToolbarVisible(false));
  94. dispatch(setSubjectSlideIn(false));
  95. }
  96. };
  97. }
  98. /**
  99. * Action that reset always visible toolbar to default state.
  100. *
  101. * @returns {Function}
  102. */
  103. export function resetAlwaysVisibleToolbar(): Function {
  104. return (dispatch: Dispatch<*>) => {
  105. const alwaysVisible = config.alwaysVisibleToolbar === true;
  106. dispatch(setAlwaysVisibleToolbar(alwaysVisible));
  107. };
  108. }
  109. /**
  110. * Signals that unclickable property of profile button should change its value.
  111. *
  112. * @param {boolean} unclickable - Shows whether button is unclickable.
  113. * @returns {Function}
  114. */
  115. export function setProfileButtonUnclickable(unclickable: boolean): Function {
  116. return (dispatch: Dispatch<*>) => {
  117. const buttonName = 'profile';
  118. dispatch(setToolbarButton(buttonName, {
  119. unclickable
  120. }));
  121. UIUtil.removeTooltip(document.getElementById('toolbar_button_profile'));
  122. };
  123. }
  124. /**
  125. * Shows desktop sharing button.
  126. *
  127. * @returns {Function}
  128. */
  129. export function showDesktopSharingButton(): Function {
  130. return (dispatch: Dispatch<*>) => {
  131. const buttonName = 'desktop';
  132. const visible
  133. = APP.conference.isDesktopSharingEnabled
  134. && UIUtil.isButtonEnabled(buttonName);
  135. dispatch(setToolbarButton(buttonName, {
  136. hidden: !visible
  137. }));
  138. };
  139. }
  140. /**
  141. * Shows or hides the dialpad button.
  142. *
  143. * @param {boolean} show - Flag showing whether to show button or not.
  144. * @returns {Function}
  145. */
  146. export function showDialPadButton(show: boolean): Function {
  147. return (dispatch: Dispatch<*>) => {
  148. const buttonName = 'dialpad';
  149. const shouldShow = UIUtil.isButtonEnabled(buttonName) && show;
  150. if (shouldShow) {
  151. dispatch(setToolbarButton(buttonName, {
  152. hidden: false
  153. }));
  154. }
  155. };
  156. }
  157. /**
  158. * Shows recording button.
  159. *
  160. * @returns {Function}
  161. */
  162. export function showRecordingButton(): Function {
  163. return (dispatch: Dispatch<*>) => {
  164. const eventEmitter = APP.UI.eventEmitter;
  165. const buttonName = 'recording';
  166. dispatch(setToolbarButton(buttonName, {
  167. hidden: false
  168. }));
  169. Recording.init(eventEmitter, config.recordingType);
  170. };
  171. }
  172. /**
  173. * Shows or hides the 'shared video' button.
  174. *
  175. * @returns {Function}
  176. */
  177. export function showSharedVideoButton(): Function {
  178. return (dispatch: Dispatch<*>) => {
  179. const buttonName = 'sharedvideo';
  180. const shouldShow
  181. = UIUtil.isButtonEnabled(buttonName)
  182. && !config.disableThirdPartyRequests;
  183. if (shouldShow) {
  184. dispatch(setToolbarButton(buttonName, {
  185. hidden: false
  186. }));
  187. }
  188. };
  189. }
  190. /**
  191. * Shows SIP call button if it's required and appropriate
  192. * flag is passed.
  193. *
  194. * @param {boolean} show - Flag showing whether to show button or not.
  195. * @returns {Function}
  196. */
  197. export function showSIPCallButton(show: boolean): Function {
  198. return (dispatch: Dispatch<*>) => {
  199. const buttonName = 'sip';
  200. const shouldShow
  201. = APP.conference.sipGatewayEnabled()
  202. && UIUtil.isButtonEnabled(buttonName)
  203. && show;
  204. if (shouldShow) {
  205. dispatch(setToolbarButton(buttonName, {
  206. hidden: !shouldShow
  207. }));
  208. }
  209. };
  210. }
  211. /**
  212. * Shows the toolbar for specified timeout.
  213. *
  214. * @param {number} timeout - Timeout for showing the toolbar.
  215. * @returns {Function}
  216. */
  217. export function showToolbar(timeout: number = 0): Object {
  218. return (dispatch: Dispatch<*>, getState: Function) => {
  219. if (interfaceConfig.filmStripOnly) {
  220. return;
  221. }
  222. const state = getState();
  223. const { toolbarTimeout, visible } = state['features/toolbar'];
  224. const finalTimeout = timeout || toolbarTimeout;
  225. if (!visible) {
  226. dispatch(setToolbarVisible(true));
  227. dispatch(setSubjectSlideIn(true));
  228. dispatch(
  229. setToolbarTimeout(() => dispatch(hideToolbar()), finalTimeout));
  230. dispatch(setToolbarTimeoutNumber(interfaceConfig.TOOLBAR_TIMEOUT));
  231. }
  232. };
  233. }
  234. /**
  235. * Event handler for side toolbar container toggled event.
  236. *
  237. * @param {string} containerId - ID of the container.
  238. * @returns {void}
  239. */
  240. export function toggleSideToolbarContainer(containerId: string): Function {
  241. return (dispatch: Dispatch, getState: Function) => {
  242. const state = getState();
  243. const { secondaryToolbarButtons } = state['features/toolbar'];
  244. for (const key of secondaryToolbarButtons.keys()) {
  245. const isButtonEnabled = UIUtil.isButtonEnabled(key);
  246. const button = secondaryToolbarButtons.get(key);
  247. if (isButtonEnabled
  248. && button.sideContainerId
  249. && button.sideContainerId === containerId) {
  250. dispatch(toggleToolbarButton(key));
  251. break;
  252. }
  253. }
  254. };
  255. }