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.any.ts 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import { VIDEO_MUTE, createToolbarEvent } from '../analytics/AnalyticsEvents';
  2. import { sendAnalytics } from '../analytics/functions';
  3. import { IStore } from '../app/types';
  4. import { setAudioOnly } from '../base/audio-only/actions';
  5. import { setVideoMuted } from '../base/media/actions';
  6. import { VIDEO_MUTISM_AUTHORITY } from '../base/media/constants';
  7. import {
  8. SET_TOOLBOX_ENABLED,
  9. SET_TOOLBOX_SHIFT_UP,
  10. SET_TOOLBOX_VISIBLE,
  11. TOGGLE_TOOLBOX_VISIBLE
  12. } from './actionTypes';
  13. /**
  14. * Enables/disables the toolbox.
  15. *
  16. * @param {boolean} enabled - True to enable the toolbox or false to disable it.
  17. * @returns {{
  18. * type: SET_TOOLBOX_ENABLED,
  19. * enabled: boolean
  20. * }}
  21. */
  22. export function setToolboxEnabled(enabled: boolean) {
  23. return {
  24. type: SET_TOOLBOX_ENABLED,
  25. enabled
  26. };
  27. }
  28. /**
  29. * Shows/hides the toolbox.
  30. *
  31. * @param {boolean} visible - True to show the toolbox or false to hide it.
  32. * @returns {Function}
  33. */
  34. export function setToolboxVisible(visible: boolean) {
  35. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  36. const { toolbarConfig } = getState()['features/base/config'];
  37. const alwaysVisible = toolbarConfig?.alwaysVisible;
  38. if (!visible && alwaysVisible) {
  39. return;
  40. }
  41. dispatch({
  42. type: SET_TOOLBOX_VISIBLE,
  43. visible
  44. });
  45. };
  46. }
  47. /**
  48. * Action to toggle the toolbox visibility.
  49. *
  50. * @returns {Function}
  51. */
  52. export function toggleToolboxVisible() {
  53. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  54. const state = getState();
  55. const { toolbarConfig } = getState()['features/base/config'];
  56. const alwaysVisible = toolbarConfig?.alwaysVisible;
  57. const { visible } = state['features/toolbox'];
  58. if (visible && alwaysVisible) {
  59. return;
  60. }
  61. dispatch({
  62. type: TOGGLE_TOOLBOX_VISIBLE
  63. });
  64. };
  65. }
  66. /**
  67. * Action to handle toggle video from toolbox's video buttons.
  68. *
  69. * @param {boolean} muted - Whether to mute or unmute.
  70. * @param {boolean} showUI - When set to false will not display any error.
  71. * @param {boolean} ensureTrack - True if we want to ensure that a new track is
  72. * created if missing.
  73. * @returns {Function}
  74. */
  75. export function handleToggleVideoMuted(muted: boolean, showUI: boolean, ensureTrack: boolean) {
  76. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  77. const state = getState();
  78. const { enabled: audioOnly } = state['features/base/audio-only'];
  79. sendAnalytics(createToolbarEvent(VIDEO_MUTE, { enable: muted }));
  80. if (audioOnly) {
  81. dispatch(setAudioOnly(false));
  82. }
  83. dispatch(
  84. setVideoMuted(
  85. muted,
  86. VIDEO_MUTISM_AUTHORITY.USER,
  87. ensureTrack));
  88. // FIXME: The old conference logic still relies on this event being
  89. // emitted.
  90. typeof APP === 'undefined'
  91. || APP.conference.muteVideo(muted, showUI);
  92. };
  93. }
  94. /**
  95. * Sets whether the toolbox should be shifted up or not.
  96. *
  97. * @param {boolean} shiftUp - Whether the toolbox should shift up or not.
  98. * @returns {Object}
  99. */
  100. export function setShiftUp(shiftUp: boolean) {
  101. return {
  102. type: SET_TOOLBOX_SHIFT_UP,
  103. shiftUp
  104. };
  105. }