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

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