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.native.js 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /* @flow */
  2. import type { Dispatch } from 'redux-thunk';
  3. import {
  4. CLEAR_TOOLBOX_TIMEOUT,
  5. SET_DEFAULT_TOOLBOX_BUTTONS,
  6. SET_SUBJECT,
  7. SET_SUBJECT_SLIDE_IN,
  8. SET_TOOLBAR_BUTTON,
  9. SET_TOOLBAR_HOVERED,
  10. SET_TOOLBOX_ALWAYS_VISIBLE,
  11. SET_TOOLBOX_ENABLED,
  12. SET_TOOLBOX_TIMEOUT,
  13. SET_TOOLBOX_TIMEOUT_MS,
  14. SET_TOOLBOX_VISIBLE
  15. } from './actionTypes';
  16. import { getDefaultToolboxButtons } from './functions';
  17. /**
  18. * Event handler for local raise hand changed event.
  19. *
  20. * @param {boolean} handRaised - Flag showing whether hand is raised.
  21. * @returns {Function}
  22. */
  23. export function changeLocalRaiseHand(handRaised: boolean): Function {
  24. return (dispatch: Dispatch<*>, getState: Function) => {
  25. const state = getState();
  26. const { secondaryToolbarButtons } = state['features/toolbox'];
  27. const buttonName = 'raisehand';
  28. const button = secondaryToolbarButtons.get(buttonName);
  29. button.toggled = handRaised;
  30. dispatch(setToolbarButton(buttonName, button));
  31. };
  32. }
  33. /**
  34. * Signals that toolbox timeout should be cleared.
  35. *
  36. * @returns {{
  37. * type: CLEAR_TOOLBOX_TIMEOUT
  38. * }}
  39. */
  40. export function clearToolboxTimeout(): Object {
  41. return {
  42. type: CLEAR_TOOLBOX_TIMEOUT
  43. };
  44. }
  45. /**
  46. * Enables/disables audio toolbar button.
  47. *
  48. * @param {boolean} enabled - True if the button should be enabled; otherwise,
  49. * false.
  50. * @returns {Function}
  51. */
  52. export function setAudioIconEnabled(enabled: boolean = false): Function {
  53. return (dispatch: Dispatch<*>) => {
  54. const i18nKey = enabled ? 'mute' : 'micDisabled';
  55. const i18n = `[content]toolbar.${i18nKey}`;
  56. const button = {
  57. enabled,
  58. i18n,
  59. toggled: !enabled
  60. };
  61. dispatch(setToolbarButton('microphone', button));
  62. };
  63. }
  64. /**
  65. * Sets the default toolbar buttons of the Toolbox.
  66. *
  67. * @returns {{
  68. * type: SET_DEFAULT_TOOLBOX_BUTTONS,
  69. * primaryToolbarButtons: Map,
  70. * secondaryToolbarButtons: Map
  71. * }}
  72. */
  73. export function setDefaultToolboxButtons(): Object {
  74. return {
  75. type: SET_DEFAULT_TOOLBOX_BUTTONS,
  76. ...getDefaultToolboxButtons()
  77. };
  78. }
  79. /**
  80. * Signals that value of conference subject should be changed.
  81. *
  82. * @param {string} subject - Conference subject string.
  83. * @returns {Object}
  84. */
  85. export function setSubject(subject: string): Object {
  86. return {
  87. type: SET_SUBJECT,
  88. subject
  89. };
  90. }
  91. /**
  92. * Signals that toolbox subject slide in value should be changed.
  93. *
  94. * @param {boolean} subjectSlideIn - True if the subject is shown; otherwise,
  95. * false.
  96. * @returns {{
  97. * type: SET_SUBJECT_SLIDE_IN,
  98. * subjectSlideIn: boolean
  99. * }}
  100. */
  101. export function setSubjectSlideIn(subjectSlideIn: boolean): Object {
  102. return {
  103. type: SET_SUBJECT_SLIDE_IN,
  104. subjectSlideIn
  105. };
  106. }
  107. /**
  108. * Signals that value of the button specified by key should be changed.
  109. *
  110. * @param {string} buttonName - Button key.
  111. * @param {Object} button - Button object.
  112. * @returns {{
  113. * type: SET_TOOLBAR_BUTTON,
  114. * button: Object,
  115. * buttonName: string
  116. * }}
  117. */
  118. export function setToolbarButton(buttonName: string, button: Object): Object {
  119. return {
  120. type: SET_TOOLBAR_BUTTON,
  121. button,
  122. buttonName
  123. };
  124. }
  125. /**
  126. * Signals that toolbar is hovered value should be changed.
  127. *
  128. * @param {boolean} hovered - Flag showing whether toolbar is hovered.
  129. * @returns {{
  130. * type: SET_TOOLBAR_HOVERED,
  131. * hovered: boolean
  132. * }}
  133. */
  134. export function setToolbarHovered(hovered: boolean): Object {
  135. return {
  136. type: SET_TOOLBAR_HOVERED,
  137. hovered
  138. };
  139. }
  140. /**
  141. * Signals that always visible toolbars value should be changed.
  142. *
  143. * @param {boolean} alwaysVisible - Value to be set in redux store.
  144. * @returns {{
  145. * type: SET_TOOLBOX_ALWAYS_VISIBLE,
  146. * alwaysVisible: boolean
  147. * }}
  148. */
  149. export function setToolboxAlwaysVisible(alwaysVisible: boolean): Object {
  150. return {
  151. type: SET_TOOLBOX_ALWAYS_VISIBLE,
  152. alwaysVisible
  153. };
  154. }
  155. /* eslint-disable flowtype/space-before-type-colon */
  156. /**
  157. * Enables/disables the toolbox.
  158. *
  159. * @param {boolean} enabled - True to enable the toolbox or false to disable it.
  160. * @returns {{
  161. * type: SET_TOOLBOX_ENABLED,
  162. * enabled: boolean
  163. * }}
  164. */
  165. export function setToolboxEnabled(enabled: boolean): Object {
  166. return {
  167. type: SET_TOOLBOX_ENABLED,
  168. enabled
  169. };
  170. }
  171. /**
  172. * Dispatches an action which sets new timeout and clears the previous one.
  173. *
  174. * @param {Function} handler - Function to be invoked after the timeout.
  175. * @param {number} timeoutMS - Delay.
  176. * @returns {{
  177. * type: SET_TOOLBOX_TIMEOUT,
  178. * handler: Function,
  179. * timeoutMS: number
  180. * }}
  181. */
  182. export function setToolboxTimeout(handler: Function, timeoutMS: number)
  183. : Object {
  184. return {
  185. type: SET_TOOLBOX_TIMEOUT,
  186. handler,
  187. timeoutMS
  188. };
  189. }
  190. /* eslint-enable flowtype/space-before-type-colon */
  191. /**
  192. * Dispatches an action which sets new toolbox timeout value.
  193. *
  194. * @param {number} timeoutMS - Delay.
  195. * @returns {{
  196. * type: SET_TOOLBOX_TIMEOUT_MS,
  197. * timeoutMS: number
  198. * }}
  199. */
  200. export function setToolboxTimeoutMS(timeoutMS: number): Object {
  201. return {
  202. type: SET_TOOLBOX_TIMEOUT_MS,
  203. timeoutMS
  204. };
  205. }
  206. /**
  207. * Shows/hides the toolbox.
  208. *
  209. * @param {boolean} visible - True to show the toolbox or false to hide it.
  210. * @returns {{
  211. * type: SET_TOOLBOX_VISIBLE,
  212. * visible: boolean
  213. * }}
  214. */
  215. export function setToolboxVisible(visible: boolean): Object {
  216. return {
  217. type: SET_TOOLBOX_VISIBLE,
  218. visible
  219. };
  220. }
  221. /**
  222. * Enables/disables audio toolbar button.
  223. *
  224. * @param {boolean} enabled - True if the button should be enabled; otherwise,
  225. * false.
  226. * @returns {Function}
  227. */
  228. export function setVideoIconEnabled(enabled: boolean = false): Function {
  229. return (dispatch: Dispatch<*>) => {
  230. const i18nKey = enabled ? 'videomute' : 'cameraDisabled';
  231. const i18n = `[content]toolbar.${i18nKey}`;
  232. const button = {
  233. enabled,
  234. i18n,
  235. toggled: !enabled
  236. };
  237. dispatch(setToolbarButton('camera', button));
  238. };
  239. }
  240. /**
  241. * Shows etherpad button if it's not shown.
  242. *
  243. * @returns {Function}
  244. */
  245. export function showEtherpadButton(): Function {
  246. return (dispatch: Dispatch<*>) => {
  247. dispatch(setToolbarButton('etherpad', {
  248. hidden: false
  249. }));
  250. };
  251. }
  252. /**
  253. * Event handler for full screen toggled event.
  254. *
  255. * @param {boolean} isFullScreen - Flag showing whether app in full
  256. * screen mode.
  257. * @returns {Function}
  258. */
  259. export function toggleFullScreen(isFullScreen: boolean): Function {
  260. return (dispatch: Dispatch<*>, getState: Function) => {
  261. const state = getState();
  262. const { primaryToolbarButtons } = state['features/toolbox'];
  263. const buttonName = 'fullscreen';
  264. const button = primaryToolbarButtons.get(buttonName);
  265. button.toggled = isFullScreen;
  266. dispatch(setToolbarButton(buttonName, button));
  267. };
  268. }
  269. /**
  270. * Sets negation of button's toggle property.
  271. *
  272. * @param {string} buttonName - Button key.
  273. * @returns {Function}
  274. */
  275. export function toggleToolbarButton(buttonName: string): Function {
  276. return (dispatch: Dispatch, getState: Function) => {
  277. const state = getState();
  278. const {
  279. primaryToolbarButtons,
  280. secondaryToolbarButtons
  281. } = state['features/toolbox'];
  282. const button
  283. = primaryToolbarButtons.get(buttonName)
  284. || secondaryToolbarButtons.get(buttonName);
  285. dispatch(setToolbarButton(buttonName, {
  286. toggled: !button.toggled
  287. }));
  288. };
  289. }