Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

actions.js 3.3KB

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