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 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. * FIXME: We should make sure all common functions for native and web are
  17. * merged in a global functions file.
  18. */
  19. import { getButton } from './functions.native';
  20. /**
  21. * Event handler for local raise hand changed event.
  22. *
  23. * @param {boolean} handRaised - Flag showing whether hand is raised.
  24. * @returns {Function}
  25. */
  26. export function changeLocalRaiseHand(handRaised: boolean): Function {
  27. return (dispatch: Dispatch<*>, getState: Function) => {
  28. const buttonName = 'raisehand';
  29. const button = getButton(buttonName, getState());
  30. button.toggled = handRaised;
  31. dispatch(setToolbarButton(buttonName, button));
  32. };
  33. }
  34. /**
  35. * Signals that toolbox timeout should be cleared.
  36. *
  37. * @returns {{
  38. * type: CLEAR_TOOLBOX_TIMEOUT
  39. * }}
  40. */
  41. export function clearToolboxTimeout(): Object {
  42. return {
  43. type: CLEAR_TOOLBOX_TIMEOUT
  44. };
  45. }
  46. /**
  47. * Signals that value of conference subject should be changed.
  48. *
  49. * @param {string} subject - Conference subject string.
  50. * @returns {Object}
  51. */
  52. export function setSubject(subject: string): Object {
  53. return {
  54. type: SET_SUBJECT,
  55. subject
  56. };
  57. }
  58. /**
  59. * Signals that toolbox subject slide in value should be changed.
  60. *
  61. * @param {boolean} subjectSlideIn - True if the subject is shown; otherwise,
  62. * false.
  63. * @returns {{
  64. * type: SET_SUBJECT_SLIDE_IN,
  65. * subjectSlideIn: boolean
  66. * }}
  67. */
  68. export function setSubjectSlideIn(subjectSlideIn: boolean): Object {
  69. return {
  70. type: SET_SUBJECT_SLIDE_IN,
  71. subjectSlideIn
  72. };
  73. }
  74. /**
  75. * Signals that value of the button specified by key should be changed.
  76. *
  77. * @param {string} buttonName - Button key.
  78. * @param {Object} button - Button object.
  79. * @returns {{
  80. * type: SET_TOOLBAR_BUTTON,
  81. * button: Object,
  82. * buttonName: string
  83. * }}
  84. */
  85. export function setToolbarButton(buttonName: string, button: Object): Object {
  86. return {
  87. type: SET_TOOLBAR_BUTTON,
  88. button,
  89. buttonName
  90. };
  91. }
  92. /**
  93. * Signals that toolbar is hovered value should be changed.
  94. *
  95. * @param {boolean} hovered - Flag showing whether toolbar is hovered.
  96. * @returns {{
  97. * type: SET_TOOLBAR_HOVERED,
  98. * hovered: boolean
  99. * }}
  100. */
  101. export function setToolbarHovered(hovered: boolean): Object {
  102. return {
  103. type: SET_TOOLBAR_HOVERED,
  104. hovered
  105. };
  106. }
  107. /**
  108. * Signals that always visible toolbars value should be changed.
  109. *
  110. * @param {boolean} alwaysVisible - Value to be set in redux store.
  111. * @returns {{
  112. * type: SET_TOOLBOX_ALWAYS_VISIBLE,
  113. * alwaysVisible: boolean
  114. * }}
  115. */
  116. export function setToolboxAlwaysVisible(alwaysVisible: boolean): Object {
  117. return {
  118. type: SET_TOOLBOX_ALWAYS_VISIBLE,
  119. alwaysVisible
  120. };
  121. }
  122. /* eslint-disable flowtype/space-before-type-colon */
  123. /**
  124. * Enables/disables the toolbox.
  125. *
  126. * @param {boolean} enabled - True to enable the toolbox or false to disable it.
  127. * @returns {{
  128. * type: SET_TOOLBOX_ENABLED,
  129. * enabled: boolean
  130. * }}
  131. */
  132. export function setToolboxEnabled(enabled: boolean): Object {
  133. return {
  134. type: SET_TOOLBOX_ENABLED,
  135. enabled
  136. };
  137. }
  138. /**
  139. * Dispatches an action which sets new timeout and clears the previous one.
  140. *
  141. * @param {Function} handler - Function to be invoked after the timeout.
  142. * @param {number} timeoutMS - Delay.
  143. * @returns {{
  144. * type: SET_TOOLBOX_TIMEOUT,
  145. * handler: Function,
  146. * timeoutMS: number
  147. * }}
  148. */
  149. export function setToolboxTimeout(handler: Function, timeoutMS: number)
  150. : Object {
  151. return {
  152. type: SET_TOOLBOX_TIMEOUT,
  153. handler,
  154. timeoutMS
  155. };
  156. }
  157. /* eslint-enable flowtype/space-before-type-colon */
  158. /**
  159. * Dispatches an action which sets new toolbox timeout value.
  160. *
  161. * @param {number} timeoutMS - Delay.
  162. * @returns {{
  163. * type: SET_TOOLBOX_TIMEOUT_MS,
  164. * timeoutMS: number
  165. * }}
  166. */
  167. export function setToolboxTimeoutMS(timeoutMS: number): Object {
  168. return {
  169. type: SET_TOOLBOX_TIMEOUT_MS,
  170. timeoutMS
  171. };
  172. }
  173. /**
  174. * Shows/hides the toolbox.
  175. *
  176. * @param {boolean} visible - True to show the toolbox or false to hide it.
  177. * @returns {{
  178. * type: SET_TOOLBOX_VISIBLE,
  179. * visible: boolean
  180. * }}
  181. */
  182. export function setToolboxVisible(visible: boolean): Object {
  183. return {
  184. type: SET_TOOLBOX_VISIBLE,
  185. visible
  186. };
  187. }
  188. /**
  189. * Shows etherpad button if it's not shown.
  190. *
  191. * @returns {Function}
  192. */
  193. export function showEtherpadButton(): Function {
  194. return (dispatch: Dispatch<*>) => {
  195. dispatch(setToolbarButton('etherpad', {
  196. hidden: false
  197. }));
  198. };
  199. }
  200. /**
  201. * Event handler for full screen toggled event.
  202. *
  203. * @param {boolean} isFullScreen - Flag showing whether app in full
  204. * screen mode.
  205. * @returns {Function}
  206. */
  207. export function toggleFullScreen(isFullScreen: boolean): Function {
  208. return (dispatch: Dispatch<*>, getState: Function) => {
  209. const buttonName = 'fullscreen';
  210. const button = getButton(buttonName, getState());
  211. if (button) {
  212. button.toggled = isFullScreen;
  213. dispatch(setToolbarButton(buttonName, button));
  214. }
  215. };
  216. }
  217. /**
  218. * Sets negation of button's toggle property.
  219. *
  220. * @param {string} buttonName - Button key.
  221. * @returns {Function}
  222. */
  223. export function toggleToolbarButton(buttonName: string): Function {
  224. return (dispatch: Dispatch, getState: Function) => {
  225. const button = getButton(buttonName, getState());
  226. dispatch(setToolbarButton(buttonName, {
  227. toggled: !button.toggled
  228. }));
  229. };
  230. }