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.

AbstractMuteEveryonesVideoDialog.ts 4.2KB

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