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.4KB

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