Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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