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

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