Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

AbstractMuteEveryonesVideoDialog.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // @flow
  2. import React from 'react';
  3. import { requestDisableVideoModeration, requestEnableVideoModeration } from '../../av-moderation/actions';
  4. import { isEnabledFromState, isSupported } from '../../av-moderation/functions';
  5. import { Dialog } from '../../base/dialog';
  6. import { MEDIA_TYPE } from '../../base/media';
  7. import { getLocalParticipant, getParticipantDisplayName } from '../../base/participants';
  8. import { muteAllParticipants } from '../actions';
  9. import AbstractMuteRemoteParticipantsVideoDialog, {
  10. type Props as AbstractProps
  11. } from './AbstractMuteRemoteParticipantsVideoDialog';
  12. /**
  13. * The type of the React {@code Component} props of
  14. * {@link AbstractMuteEveryonesVideoDialog}.
  15. */
  16. export type Props = AbstractProps & {
  17. content: string,
  18. exclude: Array<string>,
  19. title: string,
  20. showAdvancedModerationToggle: boolean,
  21. isVideoModerationEnabled: boolean,
  22. isModerationSupported: boolean
  23. };
  24. type State = {
  25. moderationEnabled: boolean;
  26. content: string;
  27. };
  28. /**
  29. *
  30. * An abstract Component with the contents for a dialog that asks for confirmation
  31. * from the user before disabling all remote participants cameras.
  32. *
  33. * @augments AbstractMuteRemoteParticipantsVideoDialog
  34. */
  35. export default class AbstractMuteEveryonesVideoDialog<P: Props>
  36. extends AbstractMuteRemoteParticipantsVideoDialog<P, State> {
  37. static defaultProps = {
  38. exclude: [],
  39. muteLocal: false
  40. };
  41. /**
  42. * Initializes a new {@code AbstractMuteRemoteParticipantsVideoDialog} instance.
  43. *
  44. * @param {Object} props - The read-only properties with which the new
  45. * instance is to be initialized.
  46. */
  47. constructor(props: P) {
  48. super(props);
  49. this.state = {
  50. moderationEnabled: props.isVideoModerationEnabled,
  51. content: props.content || props.t(props.isVideoModerationEnabled
  52. ? 'dialog.muteEveryonesVideoDialogModerationOn' : 'dialog.muteEveryonesVideoDialog'
  53. )
  54. };
  55. // Bind event handlers so they are only bound once per instance.
  56. this._onSubmit = this._onSubmit.bind(this);
  57. this._onToggleModeration = this._onToggleModeration.bind(this);
  58. }
  59. /**
  60. * Implements React's {@link Component#render()}.
  61. *
  62. * @inheritdoc
  63. * @returns {ReactElement}
  64. */
  65. render() {
  66. const { content, title } = this.props;
  67. return (
  68. <Dialog
  69. okKey = 'dialog.muteParticipantsVideoButton'
  70. onSubmit = { this._onSubmit }
  71. titleString = { title }
  72. width = 'small'>
  73. <div>
  74. { content }
  75. </div>
  76. </Dialog>
  77. );
  78. }
  79. _onSubmit: () => boolean;
  80. _onToggleModeration: () => void;
  81. /**
  82. * Callback to be invoked when the value of this dialog is submitted.
  83. *
  84. * @returns {boolean}
  85. */
  86. _onSubmit() {
  87. const {
  88. dispatch,
  89. exclude
  90. } = this.props;
  91. dispatch(muteAllParticipants(exclude, MEDIA_TYPE.VIDEO));
  92. if (this.state.moderationEnabled) {
  93. dispatch(requestEnableVideoModeration());
  94. } else if (this.state.moderationEnabled !== undefined) {
  95. dispatch(requestDisableVideoModeration());
  96. }
  97. return true;
  98. }
  99. }
  100. /**
  101. * Maps (parts of) the Redux state to the associated {@code AbstractMuteEveryonesVideoDialog}'s props.
  102. *
  103. * @param {Object} state - The redux state.
  104. * @param {Object} ownProps - The properties explicitly passed to the component.
  105. * @returns {Props}
  106. */
  107. export function abstractMapStateToProps(state: Object, ownProps: Props) {
  108. const { exclude = [], t } = ownProps;
  109. const isVideoModerationEnabled = isEnabledFromState(MEDIA_TYPE.VIDEO, state);
  110. const whom = exclude
  111. // eslint-disable-next-line no-confusing-arrow
  112. .map(id => id === getLocalParticipant(state).id
  113. ? t('dialog.muteEveryoneSelf')
  114. : getParticipantDisplayName(state, id))
  115. .join(', ');
  116. return whom.length ? {
  117. content: t('dialog.muteEveryoneElsesVideoDialog'),
  118. title: t('dialog.muteEveryoneElsesVideoTitle', { whom })
  119. } : {
  120. title: t('dialog.muteEveryonesVideoTitle'),
  121. isVideoModerationEnabled,
  122. isModerationSupported: isSupported()(state)
  123. };
  124. }