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

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