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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* eslint-disable lines-around-comment */
  2. import type { Dispatch } from 'redux';
  3. // @ts-ignore
  4. import UIEvents from '../../../../service/UI/UIEvents';
  5. // @ts-ignore
  6. import { createAudioOnlyChangedEvent, sendAnalytics } from '../../analytics';
  7. import { SET_AUDIO_ONLY } from './actionTypes';
  8. import logger from './logger';
  9. declare let APP: any;
  10. /**
  11. * Sets the audio-only flag for the current JitsiConference.
  12. *
  13. * @param {boolean} audioOnly - True if the conference should be audio only;
  14. * false, otherwise.
  15. * @param {boolean} ensureVideoTrack - Define if conference should ensure
  16. * to create a video track.
  17. * @returns {{
  18. * type: SET_AUDIO_ONLY,
  19. * audioOnly: boolean,
  20. * ensureVideoTrack: boolean
  21. * }}
  22. */
  23. export function setAudioOnly(audioOnly: boolean, ensureVideoTrack = false) {
  24. return (dispatch: Dispatch<any>, getState: Function) => {
  25. const { enabled: oldValue } = getState()['features/base/audio-only'];
  26. if (oldValue !== audioOnly) {
  27. sendAnalytics(createAudioOnlyChangedEvent(audioOnly));
  28. logger.log(`Audio-only ${audioOnly ? 'enabled' : 'disabled'}`);
  29. dispatch({
  30. type: SET_AUDIO_ONLY,
  31. audioOnly,
  32. ensureVideoTrack
  33. });
  34. if (typeof APP !== 'undefined') {
  35. // TODO This should be a temporary solution that lasts only until video
  36. // tracks and all ui is moved into react/redux on the web.
  37. APP.UI.emitEvent(UIEvents.TOGGLE_AUDIO_ONLY, audioOnly);
  38. }
  39. }
  40. };
  41. }
  42. /**
  43. * Toggles the audio-only flag for the current JitsiConference.
  44. *
  45. * @returns {Function}
  46. */
  47. export function toggleAudioOnly() {
  48. return (dispatch: Dispatch<any>, getState: Function) => {
  49. const { enabled } = getState()['features/base/audio-only'];
  50. return dispatch(setAudioOnly(!enabled, true));
  51. };
  52. }