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

RemoteControlAuthorizationDialog.tsx 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. import { IReduxState, IStore } from '../../app/types';
  4. import { translate } from '../../base/i18n/functions';
  5. import { getParticipantById } from '../../base/participants/functions';
  6. import { getLocalVideoTrack } from '../../base/tracks/functions.any';
  7. import Dialog from '../../base/ui/components/web/Dialog';
  8. import { deny, grant } from '../actions';
  9. /**
  10. * The type of the React {@code Component} props of
  11. * {@link RemoteControlAuthorizationDialog}.
  12. */
  13. interface IProps {
  14. /**
  15. * The display name of the participant who is requesting authorization for
  16. * remote desktop control session.
  17. */
  18. _displayName: string;
  19. _isScreenSharing: boolean;
  20. _sourceType: string;
  21. /**
  22. * Used to show/hide the dialog on cancel.
  23. */
  24. dispatch: IStore['dispatch'];
  25. /**
  26. * The ID of the participant who is requesting authorization for remote
  27. * desktop control session.
  28. */
  29. participantId: string;
  30. /**
  31. * Invoked to obtain translated strings.
  32. */
  33. t: Function;
  34. }
  35. /**
  36. * Implements a dialog for remote control authorization.
  37. */
  38. class RemoteControlAuthorizationDialog extends Component<IProps> {
  39. /**
  40. * Initializes a new RemoteControlAuthorizationDialog instance.
  41. *
  42. * @param {Object} props - The read-only properties with which the new
  43. * instance is to be initialized.
  44. */
  45. constructor(props: IProps) {
  46. super(props);
  47. this._onCancel = this._onCancel.bind(this);
  48. this._onSubmit = this._onSubmit.bind(this);
  49. }
  50. /**
  51. * Implements React's {@link Component#render()}.
  52. *
  53. * @inheritdoc
  54. */
  55. render() {
  56. return (
  57. <Dialog
  58. ok = {{ translationKey: 'dialog.allow' }}
  59. onCancel = { this._onCancel }
  60. onSubmit = { this._onSubmit }
  61. titleKey = 'dialog.remoteControlTitle'>
  62. {
  63. this.props.t(
  64. 'dialog.remoteControlRequestMessage',
  65. { user: this.props._displayName })
  66. }
  67. {
  68. this._getAdditionalMessage()
  69. }
  70. </Dialog>
  71. );
  72. }
  73. /**
  74. * Renders additional message text for the dialog.
  75. *
  76. * @private
  77. * @returns {ReactElement}
  78. */
  79. _getAdditionalMessage() {
  80. const { _isScreenSharing, _sourceType } = this.props;
  81. if (_isScreenSharing && _sourceType === 'screen') {
  82. return null;
  83. }
  84. return (
  85. <div>
  86. <br />
  87. { this.props.t('dialog.remoteControlShareScreenWarning') }
  88. </div>
  89. );
  90. }
  91. /**
  92. * Notifies the remote control module about the denial of the remote control
  93. * request.
  94. *
  95. * @private
  96. * @returns {boolean} Returns true to close the dialog.
  97. */
  98. _onCancel() {
  99. const { dispatch, participantId } = this.props;
  100. dispatch(deny(participantId));
  101. return true;
  102. }
  103. /**
  104. * Notifies the remote control module that the remote control request is
  105. * accepted.
  106. *
  107. * @private
  108. * @returns {boolean} Returns false to prevent closure because the dialog is
  109. * closed manually to be sure that if the desktop picker dialog can be
  110. * displayed (if this dialog is displayed when we try to display the desktop
  111. * picker window, the action will be ignored).
  112. */
  113. _onSubmit() {
  114. const { dispatch, participantId } = this.props;
  115. dispatch(grant(participantId));
  116. return false;
  117. }
  118. }
  119. /**
  120. * Maps (parts of) the Redux state to the RemoteControlAuthorizationDialog's
  121. * props.
  122. *
  123. * @param {Object} state - The Redux state.
  124. * @param {Object} ownProps - The React Component props passed to the associated
  125. * (instance of) RemoteControlAuthorizationDialog.
  126. * @private
  127. * @returns {{
  128. * _displayName: string,
  129. * _isScreenSharing: boolean,
  130. * _sourceId: string,
  131. * _sourceType: string
  132. * }}
  133. */
  134. function _mapStateToProps(state: IReduxState, ownProps: any) {
  135. const { _displayName, participantId } = ownProps;
  136. const participant = getParticipantById(state, participantId);
  137. const tracks = state['features/base/tracks'];
  138. const track = getLocalVideoTrack(tracks);
  139. const _isScreenSharing = track?.videoType === 'desktop';
  140. const { sourceType } = track?.jitsiTrack || {};
  141. return {
  142. _displayName: participant ? participant.name : _displayName,
  143. _isScreenSharing,
  144. _sourceType: sourceType
  145. };
  146. }
  147. export default translate(
  148. connect(_mapStateToProps)(RemoteControlAuthorizationDialog));