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 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import UIEvents from '../../../service/UI/UIEvents';
  4. import {
  5. AUDIO_MUTE,
  6. createRemoteMuteConfirmedEvent,
  7. createToolbarEvent,
  8. sendAnalytics
  9. } from '../analytics';
  10. import { hideDialog } from '../base/dialog';
  11. import { setAudioMuted } from '../base/media';
  12. import {
  13. getLocalParticipant,
  14. muteRemoteParticipant
  15. } from '../base/participants';
  16. import { RemoteVideoMenu } from './components';
  17. declare var APP: Object;
  18. /**
  19. * Hides the remote video menu.
  20. *
  21. * @returns {Function}
  22. */
  23. export function hideRemoteVideoMenu() {
  24. return hideDialog(RemoteVideoMenu);
  25. }
  26. /**
  27. * Mutes the local participant.
  28. *
  29. * @param {boolean} enable - Whether to mute or unmute.
  30. * @returns {Function}
  31. */
  32. export function muteLocal(enable: boolean) {
  33. return (dispatch: Dispatch<any>) => {
  34. sendAnalytics(createToolbarEvent(AUDIO_MUTE, { enable }));
  35. dispatch(setAudioMuted(enable, /* ensureTrack */ true));
  36. // FIXME: The old conference logic as well as the shared video feature
  37. // still rely on this event being emitted.
  38. typeof APP === 'undefined'
  39. || APP.UI.emitEvent(UIEvents.AUDIO_MUTED, enable, true);
  40. };
  41. }
  42. /**
  43. * Mutes the remote participant with the given ID.
  44. *
  45. * @param {string} participantId - ID of the participant to mute.
  46. * @returns {Function}
  47. */
  48. export function muteRemote(participantId: string) {
  49. return (dispatch: Dispatch<any>) => {
  50. sendAnalytics(createRemoteMuteConfirmedEvent(participantId));
  51. dispatch(muteRemoteParticipant(participantId));
  52. };
  53. }
  54. /**
  55. * Mutes all participants.
  56. *
  57. * @param {Array<string>} exclude - Array of participant IDs to not mute.
  58. * @returns {Function}
  59. */
  60. export function muteAllParticipants(exclude: Array<string>) {
  61. return (dispatch: Dispatch<any>, getState: Function) => {
  62. const state = getState();
  63. const localId = getLocalParticipant(state).id;
  64. const participantIds = state['features/base/participants']
  65. .map(p => p.id);
  66. /* eslint-disable no-confusing-arrow */
  67. participantIds
  68. .filter(id => !exclude.includes(id))
  69. .map(id => id === localId ? muteLocal(true) : muteRemote(id))
  70. .map(dispatch);
  71. /* eslint-enable no-confusing-arrow */
  72. };
  73. }