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.1KB

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