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.any.js 3.1KB

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