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

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