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

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