您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

RemoteControlAuthorizationDialog.js 4.6KB

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