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

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