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

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