您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

actions.native.js 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /* @flow */
  2. import type { Dispatch } from 'redux-thunk';
  3. import {
  4. CLEAR_TOOLBOX_TIMEOUT,
  5. SET_TOOLBOX_ALWAYS_VISIBLE,
  6. SET_SUBJECT,
  7. SET_SUBJECT_SLIDE_IN,
  8. SET_TOOLBAR_BUTTON,
  9. SET_TOOLBAR_HOVERED,
  10. SET_TOOLBOX_TIMEOUT,
  11. SET_TOOLBOX_TIMEOUT_MS,
  12. SET_TOOLBOX_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/toolbox'];
  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 toolbox timeout should be cleared.
  32. *
  33. * @returns {{
  34. * type: CLEAR_TOOLBOX_TIMEOUT
  35. * }}
  36. */
  37. export function clearToolboxTimeout(): Object {
  38. return {
  39. type: CLEAR_TOOLBOX_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_TOOLBOX_ALWAYS_VISIBLE,
  48. * alwaysVisible: boolean
  49. * }}
  50. */
  51. export function setToolboxAlwaysVisible(alwaysVisible: boolean): Object {
  52. return {
  53. type: SET_TOOLBOX_ALWAYS_VISIBLE,
  54. alwaysVisible
  55. };
  56. }
  57. /**
  58. * Enables/disables audio toolbar button.
  59. *
  60. * @param {boolean} enabled - True if the button should be enabled; otherwise,
  61. * false.
  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): Object {
  83. return {
  84. type: SET_SUBJECT,
  85. subject
  86. };
  87. }
  88. /**
  89. * Signals that toolbox subject slide in value should be changed.
  90. *
  91. * @param {boolean} subjectSlideIn - True if the subject is shown; otherwise,
  92. * false.
  93. * @returns {{
  94. * type: SET_SUBJECT_SLIDE_IN,
  95. * subjectSlideIn: boolean
  96. * }}
  97. */
  98. export function setSubjectSlideIn(subjectSlideIn: boolean): Object {
  99. return {
  100. type: SET_SUBJECT_SLIDE_IN,
  101. subjectSlideIn
  102. };
  103. }
  104. /**
  105. * Signals that value of the button specified by key should be changed.
  106. *
  107. * @param {string} buttonName - Button key.
  108. * @param {Object} button - Button object.
  109. * @returns {{
  110. * type: SET_TOOLBAR_BUTTON,
  111. * button: Object,
  112. * buttonName: string
  113. * }}
  114. */
  115. export function setToolbarButton(buttonName: string, button: Object): Object {
  116. return {
  117. type: SET_TOOLBAR_BUTTON,
  118. button,
  119. buttonName
  120. };
  121. }
  122. /**
  123. * Signals that toolbar is hovered value should be changed.
  124. *
  125. * @param {boolean} hovered - Flag showing whether toolbar is hovered.
  126. * @returns {{
  127. * type: SET_TOOLBAR_HOVERED,
  128. * hovered: boolean
  129. * }}
  130. */
  131. export function setToolbarHovered(hovered: boolean): Object {
  132. return {
  133. type: SET_TOOLBAR_HOVERED,
  134. hovered
  135. };
  136. }
  137. /* eslint-disable flowtype/space-before-type-colon */
  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. * Enables/disables audio toolbar button.
  190. *
  191. * @param {boolean} enabled - True if the button should be enabled; otherwise,
  192. * false.
  193. * @returns {Function}
  194. */
  195. export function setVideoIconEnabled(enabled: boolean = false): Function {
  196. return (dispatch: Dispatch<*>) => {
  197. const i18nKey = enabled ? 'videomute' : 'cameraDisabled';
  198. const i18n = `[content]toolbar.${i18nKey}`;
  199. const button = {
  200. enabled,
  201. i18n,
  202. toggled: !enabled
  203. };
  204. dispatch(setToolbarButton('camera', button));
  205. };
  206. }
  207. /**
  208. * Shows etherpad button if it's not shown.
  209. *
  210. * @returns {Function}
  211. */
  212. export function showEtherpadButton(): Function {
  213. return (dispatch: Dispatch<*>) => {
  214. dispatch(setToolbarButton('etherpad', {
  215. hidden: false
  216. }));
  217. };
  218. }
  219. /**
  220. * Event handler for full screen toggled event.
  221. *
  222. * @param {boolean} isFullScreen - Flag showing whether app in full
  223. * screen mode.
  224. * @returns {Function}
  225. */
  226. export function toggleFullScreen(isFullScreen: boolean): Function {
  227. return (dispatch: Dispatch<*>, getState: Function) => {
  228. const state = getState();
  229. const { primaryToolbarButtons } = state['features/toolbox'];
  230. const buttonName = 'fullscreen';
  231. const button = primaryToolbarButtons.get(buttonName);
  232. button.toggled = isFullScreen;
  233. dispatch(setToolbarButton(buttonName, button));
  234. };
  235. }
  236. /**
  237. * Sets negation of button's toggle property.
  238. *
  239. * @param {string} buttonName - Button key.
  240. * @returns {Function}
  241. */
  242. export function toggleToolbarButton(buttonName: string): Function {
  243. return (dispatch: Dispatch, getState: Function) => {
  244. const state = getState();
  245. const {
  246. primaryToolbarButtons,
  247. secondaryToolbarButtons
  248. } = state['features/toolbox'];
  249. const button
  250. = primaryToolbarButtons.get(buttonName)
  251. || secondaryToolbarButtons.get(buttonName);
  252. dispatch(setToolbarButton(buttonName, {
  253. toggled: !button.toggled
  254. }));
  255. };
  256. }