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.

RemoteControlAuthorizationDialog.js 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { Dialog, hideDialog } from '../../base/dialog';
  4. import { translate } from '../../base/i18n';
  5. import { getParticipantById } from '../../base/participants';
  6. import { connect } from '../../base/redux';
  7. import { getLocalVideoTrack } from '../../base/tracks';
  8. import { grant, deny } 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. okKey = { 'dialog.allow' }
  60. onCancel = { this._onCancel }
  61. onSubmit = { this._onSubmit }
  62. titleKey = 'dialog.remoteControlTitle'
  63. width = 'small'>
  64. {
  65. this.props.t(
  66. 'dialog.remoteControlRequestMessage',
  67. { user: this.props._displayName })
  68. }
  69. {
  70. this._getAdditionalMessage()
  71. }
  72. </Dialog>
  73. );
  74. }
  75. /**
  76. * Renders additional message text for the dialog.
  77. *
  78. * @private
  79. * @returns {ReactElement}
  80. */
  81. _getAdditionalMessage() {
  82. const { _isScreenSharing, _sourceType } = this.props;
  83. if (_isScreenSharing && _sourceType === 'screen') {
  84. return null;
  85. }
  86. return (
  87. <div>
  88. <br />
  89. { this.props.t('dialog.remoteControlShareScreenWarning') }
  90. </div>
  91. );
  92. }
  93. _onCancel: () => boolean;
  94. /**
  95. * Notifies the remote control module about the denial of the remote control
  96. * request.
  97. *
  98. * @private
  99. * @returns {boolean} Returns true to close the dialog.
  100. */
  101. _onCancel() {
  102. const { dispatch, participantId } = this.props;
  103. dispatch(deny(participantId));
  104. return true;
  105. }
  106. _onSubmit: () => boolean;
  107. /**
  108. * Notifies the remote control module that the remote control request is
  109. * accepted.
  110. *
  111. * @private
  112. * @returns {boolean} Returns false to prevent closure because the dialog is
  113. * closed manually to be sure that if the desktop picker dialog can be
  114. * displayed (if this dialog is displayed when we try to display the desktop
  115. * picker window, the action will be ignored).
  116. */
  117. _onSubmit() {
  118. const { dispatch, participantId } = this.props;
  119. dispatch(hideDialog());
  120. dispatch(grant(participantId));
  121. return false;
  122. }
  123. }
  124. /**
  125. * Maps (parts of) the Redux state to the RemoteControlAuthorizationDialog's
  126. * props.
  127. *
  128. * @param {Object} state - The Redux state.
  129. * @param {Object} ownProps - The React Component props passed to the associated
  130. * (instance of) RemoteControlAuthorizationDialog.
  131. * @private
  132. * @returns {{
  133. * _displayName: string,
  134. * _isScreenSharing: boolean,
  135. * _sourceId: string,
  136. * _sourceType: string
  137. * }}
  138. */
  139. function _mapStateToProps(state, ownProps) {
  140. const { _displayName, participantId } = ownProps;
  141. const participant = getParticipantById(state, participantId);
  142. const tracks = state['features/base/tracks'];
  143. const track = getLocalVideoTrack(tracks);
  144. const _isScreenSharing = track?.videoType === 'desktop';
  145. const { sourceType } = track?.jitsiTrack || {};
  146. return {
  147. _displayName: participant ? participant.name : _displayName,
  148. _isScreenSharing,
  149. _sourceType: sourceType
  150. };
  151. }
  152. export default translate(
  153. connect(_mapStateToProps)(RemoteControlAuthorizationDialog));