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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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_VISIBLE,
  12. TOGGLE_TOOLBOX_VISIBLE
  13. } from './actionTypes';
  14. /**
  15. * Enables/disables the toolbox.
  16. *
  17. * @param {boolean} enabled - True to enable the toolbox or false to disable it.
  18. * @returns {{
  19. * type: SET_TOOLBOX_ENABLED,
  20. * enabled: boolean
  21. * }}
  22. */
  23. export function setToolboxEnabled(enabled: boolean) {
  24. return {
  25. type: SET_TOOLBOX_ENABLED,
  26. enabled
  27. };
  28. }
  29. /**
  30. * Shows/hides the toolbox.
  31. *
  32. * @param {boolean} visible - True to show the toolbox or false to hide it.
  33. * @returns {Function}
  34. */
  35. export function setToolboxVisible(visible: boolean) {
  36. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  37. const { toolbarConfig } = getState()['features/base/config'];
  38. const alwaysVisible = toolbarConfig?.alwaysVisible;
  39. if (!visible && alwaysVisible) {
  40. return;
  41. }
  42. dispatch({
  43. type: SET_TOOLBOX_VISIBLE,
  44. visible
  45. });
  46. };
  47. }
  48. /**
  49. * Action to toggle the toolbox visibility.
  50. *
  51. * @returns {Function}
  52. */
  53. export function toggleToolboxVisible() {
  54. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  55. const state = getState();
  56. const { toolbarConfig } = getState()['features/base/config'];
  57. const alwaysVisible = toolbarConfig?.alwaysVisible;
  58. const { visible } = state['features/toolbox'];
  59. if (visible && alwaysVisible) {
  60. return;
  61. }
  62. dispatch({
  63. type: TOGGLE_TOOLBOX_VISIBLE
  64. });
  65. };
  66. }
  67. /**
  68. * Action to handle toggle video from toolbox's video buttons.
  69. *
  70. * @param {boolean} muted - Whether to mute or unmute.
  71. * @param {boolean} showUI - When set to false will not display any error.
  72. * @param {boolean} ensureTrack - True if we want to ensure that a new track is
  73. * created if missing.
  74. * @returns {Function}
  75. */
  76. export function handleToggleVideoMuted(muted: boolean, showUI: boolean, ensureTrack: boolean) {
  77. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  78. const state = getState();
  79. const { enabled: audioOnly } = state['features/base/audio-only'];
  80. sendAnalytics(createToolbarEvent(VIDEO_MUTE, { enable: muted }));
  81. if (audioOnly) {
  82. dispatch(setAudioOnly(false));
  83. }
  84. dispatch(
  85. setVideoMuted(
  86. muted,
  87. VIDEO_MUTISM_AUTHORITY.USER,
  88. ensureTrack));
  89. // FIXME: The old conference logic still relies on this event being
  90. // emitted.
  91. typeof APP === 'undefined'
  92. || APP.UI.emitEvent(UIEvents.VIDEO_MUTED, muted, showUI);
  93. };
  94. }