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

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