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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. * Enables/disables audio toolbar button.
  48. *
  49. * @param {boolean} enabled - True if the button should be enabled; otherwise,
  50. * false.
  51. * @returns {Function}
  52. */
  53. export function setAudioIconEnabled(enabled: boolean = false): Function {
  54. return (dispatch: Dispatch<*>) => {
  55. const i18nKey = enabled ? 'mute' : 'micDisabled';
  56. const i18n = `[content]toolbar.${i18nKey}`;
  57. const button = {
  58. enabled,
  59. i18n,
  60. toggled: !enabled
  61. };
  62. dispatch(setToolbarButton('microphone', button));
  63. };
  64. }
  65. /**
  66. * Signals that value of conference subject should be changed.
  67. *
  68. * @param {string} subject - Conference subject string.
  69. * @returns {Object}
  70. */
  71. export function setSubject(subject: string): Object {
  72. return {
  73. type: SET_SUBJECT,
  74. subject
  75. };
  76. }
  77. /**
  78. * Signals that toolbox subject slide in value should be changed.
  79. *
  80. * @param {boolean} subjectSlideIn - True if the subject is shown; otherwise,
  81. * false.
  82. * @returns {{
  83. * type: SET_SUBJECT_SLIDE_IN,
  84. * subjectSlideIn: boolean
  85. * }}
  86. */
  87. export function setSubjectSlideIn(subjectSlideIn: boolean): Object {
  88. return {
  89. type: SET_SUBJECT_SLIDE_IN,
  90. subjectSlideIn
  91. };
  92. }
  93. /**
  94. * Signals that value of the button specified by key should be changed.
  95. *
  96. * @param {string} buttonName - Button key.
  97. * @param {Object} button - Button object.
  98. * @returns {{
  99. * type: SET_TOOLBAR_BUTTON,
  100. * button: Object,
  101. * buttonName: string
  102. * }}
  103. */
  104. export function setToolbarButton(buttonName: string, button: Object): Object {
  105. return {
  106. type: SET_TOOLBAR_BUTTON,
  107. button,
  108. buttonName
  109. };
  110. }
  111. /**
  112. * Signals that toolbar is hovered value should be changed.
  113. *
  114. * @param {boolean} hovered - Flag showing whether toolbar is hovered.
  115. * @returns {{
  116. * type: SET_TOOLBAR_HOVERED,
  117. * hovered: boolean
  118. * }}
  119. */
  120. export function setToolbarHovered(hovered: boolean): Object {
  121. return {
  122. type: SET_TOOLBAR_HOVERED,
  123. hovered
  124. };
  125. }
  126. /**
  127. * Signals that always visible toolbars value should be changed.
  128. *
  129. * @param {boolean} alwaysVisible - Value to be set in redux store.
  130. * @returns {{
  131. * type: SET_TOOLBOX_ALWAYS_VISIBLE,
  132. * alwaysVisible: boolean
  133. * }}
  134. */
  135. export function setToolboxAlwaysVisible(alwaysVisible: boolean): Object {
  136. return {
  137. type: SET_TOOLBOX_ALWAYS_VISIBLE,
  138. alwaysVisible
  139. };
  140. }
  141. /* eslint-disable flowtype/space-before-type-colon */
  142. /**
  143. * Enables/disables the toolbox.
  144. *
  145. * @param {boolean} enabled - True to enable the toolbox or false to disable it.
  146. * @returns {{
  147. * type: SET_TOOLBOX_ENABLED,
  148. * enabled: boolean
  149. * }}
  150. */
  151. export function setToolboxEnabled(enabled: boolean): Object {
  152. return {
  153. type: SET_TOOLBOX_ENABLED,
  154. enabled
  155. };
  156. }
  157. /**
  158. * Dispatches an action which sets new timeout and clears the previous one.
  159. *
  160. * @param {Function} handler - Function to be invoked after the timeout.
  161. * @param {number} timeoutMS - Delay.
  162. * @returns {{
  163. * type: SET_TOOLBOX_TIMEOUT,
  164. * handler: Function,
  165. * timeoutMS: number
  166. * }}
  167. */
  168. export function setToolboxTimeout(handler: Function, timeoutMS: number)
  169. : Object {
  170. return {
  171. type: SET_TOOLBOX_TIMEOUT,
  172. handler,
  173. timeoutMS
  174. };
  175. }
  176. /* eslint-enable flowtype/space-before-type-colon */
  177. /**
  178. * Dispatches an action which sets new toolbox timeout value.
  179. *
  180. * @param {number} timeoutMS - Delay.
  181. * @returns {{
  182. * type: SET_TOOLBOX_TIMEOUT_MS,
  183. * timeoutMS: number
  184. * }}
  185. */
  186. export function setToolboxTimeoutMS(timeoutMS: number): Object {
  187. return {
  188. type: SET_TOOLBOX_TIMEOUT_MS,
  189. timeoutMS
  190. };
  191. }
  192. /**
  193. * Shows/hides the toolbox.
  194. *
  195. * @param {boolean} visible - True to show the toolbox or false to hide it.
  196. * @returns {{
  197. * type: SET_TOOLBOX_VISIBLE,
  198. * visible: boolean
  199. * }}
  200. */
  201. export function setToolboxVisible(visible: boolean): Object {
  202. return {
  203. type: SET_TOOLBOX_VISIBLE,
  204. visible
  205. };
  206. }
  207. /**
  208. * Enables/disables audio toolbar button.
  209. *
  210. * @param {boolean} enabled - True if the button should be enabled; otherwise,
  211. * false.
  212. * @returns {Function}
  213. */
  214. export function setVideoIconEnabled(enabled: boolean = false): Function {
  215. return (dispatch: Dispatch<*>) => {
  216. const i18nKey = enabled ? 'videomute' : 'cameraDisabled';
  217. const i18n = `[content]toolbar.${i18nKey}`;
  218. const button = {
  219. enabled,
  220. i18n,
  221. toggled: !enabled
  222. };
  223. dispatch(setToolbarButton('camera', button));
  224. };
  225. }
  226. /**
  227. * Shows etherpad button if it's not shown.
  228. *
  229. * @returns {Function}
  230. */
  231. export function showEtherpadButton(): Function {
  232. return (dispatch: Dispatch<*>) => {
  233. dispatch(setToolbarButton('etherpad', {
  234. hidden: false
  235. }));
  236. };
  237. }
  238. /**
  239. * Event handler for full screen toggled event.
  240. *
  241. * @param {boolean} isFullScreen - Flag showing whether app in full
  242. * screen mode.
  243. * @returns {Function}
  244. */
  245. export function toggleFullScreen(isFullScreen: boolean): Function {
  246. return (dispatch: Dispatch<*>, getState: Function) => {
  247. const buttonName = 'fullscreen';
  248. const button = getButton(buttonName, getState());
  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 button = getButton(buttonName, getState());
  262. dispatch(setToolbarButton(buttonName, {
  263. toggled: !button.toggled
  264. }));
  265. };
  266. }