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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 still relies on this event being emitted.
  42. typeof APP === 'undefined'
  43. || APP.UI.emitEvent(isAudio ? UIEvents.AUDIO_MUTED : UIEvents.VIDEO_MUTED, enable);
  44. };
  45. }
  46. /**
  47. * Mutes the remote participant with the given ID.
  48. *
  49. * @param {string} participantId - ID of the participant to mute.
  50. * @param {MEDIA_TYPE} mediaType - The type of the media channel to mute.
  51. * @returns {Function}
  52. */
  53. export function muteRemote(participantId: string, mediaType: MEDIA_TYPE) {
  54. return (dispatch: Dispatch<any>) => {
  55. if (mediaType !== MEDIA_TYPE.AUDIO && mediaType !== MEDIA_TYPE.VIDEO) {
  56. logger.error(`Unsupported media type: ${mediaType}`);
  57. return;
  58. }
  59. sendAnalytics(createRemoteMuteConfirmedEvent(participantId, mediaType));
  60. dispatch(muteRemoteParticipant(participantId, mediaType));
  61. };
  62. }
  63. /**
  64. * Mutes all participants.
  65. *
  66. * @param {Array<string>} exclude - Array of participant IDs to not mute.
  67. * @param {MEDIA_TYPE} mediaType - The media type to mute.
  68. * @returns {Function}
  69. */
  70. export function muteAllParticipants(exclude: Array<string>, mediaType: MEDIA_TYPE) {
  71. return (dispatch: Dispatch<any>, getState: Function) => {
  72. const state = getState();
  73. const localId = getLocalParticipant(state).id;
  74. const participantIds = state['features/base/participants']
  75. .map(p => p.id);
  76. /* eslint-disable no-confusing-arrow */
  77. participantIds
  78. .filter(id => !exclude.includes(id))
  79. .map(id => id === localId ? muteLocal(true, mediaType) : muteRemote(id, mediaType))
  80. .map(dispatch);
  81. /* eslint-enable no-confusing-arrow */
  82. };
  83. }