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.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // @flow
  2. import React from 'react';
  3. import { requestDisableVideoModeration, requestEnableVideoModeration } from '../../av-moderation/actions';
  4. import { isEnabledFromState } 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. };
  23. type State = {
  24. moderationEnabled: boolean;
  25. content: string;
  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. * @extends AbstractMuteRemoteParticipantsVideoDialog
  33. */
  34. export default class AbstractMuteEveryonesVideoDialog<P: Props>
  35. extends AbstractMuteRemoteParticipantsVideoDialog<P, State> {
  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. * Implements React's {@link Component#render()}.
  60. *
  61. * @inheritdoc
  62. * @returns {ReactElement}
  63. */
  64. render() {
  65. const { content, title } = this.props;
  66. return (
  67. <Dialog
  68. okKey = 'dialog.muteParticipantsVideoButton'
  69. onSubmit = { this._onSubmit }
  70. titleString = { title }
  71. width = 'small'>
  72. <div>
  73. { content }
  74. </div>
  75. </Dialog>
  76. );
  77. }
  78. _onSubmit: () => boolean;
  79. _onToggleModeration: () => void;
  80. /**
  81. * Callback to be invoked when the value of this dialog is submitted.
  82. *
  83. * @returns {boolean}
  84. */
  85. _onSubmit() {
  86. const {
  87. dispatch,
  88. exclude
  89. } = this.props;
  90. dispatch(muteAllParticipants(exclude, MEDIA_TYPE.VIDEO));
  91. if (this.state.moderationEnabled) {
  92. dispatch(requestEnableVideoModeration());
  93. } else {
  94. dispatch(requestDisableVideoModeration());
  95. }
  96. return true;
  97. }
  98. }
  99. /**
  100. * Maps (parts of) the Redux state to the associated {@code AbstractMuteEveryonesVideoDialog}'s props.
  101. *
  102. * @param {Object} state - The redux state.
  103. * @param {Object} ownProps - The properties explicitly passed to the component.
  104. * @returns {Props}
  105. */
  106. export function abstractMapStateToProps(state: Object, ownProps: Props) {
  107. const { exclude = [], t } = ownProps;
  108. const isVideoModerationEnabled = isEnabledFromState(MEDIA_TYPE.VIDEO, state);
  109. const whom = exclude
  110. // eslint-disable-next-line no-confusing-arrow
  111. .map(id => id === getLocalParticipant(state).id
  112. ? t('dialog.muteEveryoneSelf')
  113. : getParticipantDisplayName(state, id))
  114. .join(', ');
  115. return whom.length ? {
  116. content: t('dialog.muteEveryoneElsesVideoDialog'),
  117. title: t('dialog.muteEveryoneElsesVideoTitle', { whom })
  118. } : {
  119. title: t('dialog.muteEveryonesVideoTitle'),
  120. isVideoModerationEnabled
  121. };
  122. }