Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

actions.web.js 7.9KB

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