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

InfoDialog.web.js 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import { getInviteURL } from '../../base/connection';
  5. import { openDialog } from '../../base/dialog';
  6. import { translate } from '../../base/i18n';
  7. import AddPeopleDialog from './AddPeopleDialog';
  8. const logger = require('jitsi-meet-logger').getLogger(__filename);
  9. declare var interfaceConfig: Object;
  10. /**
  11. * A React Component with the contents for a dialog that shows information about
  12. * the current conference and provides ways to invite other participants.
  13. *
  14. * @extends Component
  15. */
  16. class InfoDialog extends Component {
  17. /**
  18. * {@code InfoDialog} component's property types.
  19. *
  20. * @static
  21. */
  22. static propTypes = {
  23. /**
  24. * The current url of the conference to be copied onto the clipboard.
  25. */
  26. _inviteURL: PropTypes.string,
  27. /**
  28. * Whether or not the link to open the {@code AddPeopleDialog} should be
  29. * displayed.
  30. */
  31. _showAddPeople: PropTypes.bool,
  32. /**
  33. * Invoked to open a dialog for adding participants to the conference.
  34. */
  35. dispatch: PropTypes.func,
  36. /**
  37. * Callback invoked when the dialog should be closed.
  38. */
  39. onClose: PropTypes.func,
  40. /**
  41. * Callback invoked when a mouse-related event has been detected.
  42. */
  43. onMouseOver: PropTypes.func,
  44. /**
  45. * Invoked to obtain translated strings.
  46. */
  47. t: PropTypes.func
  48. };
  49. /**
  50. * Initializes new {@code InfoDialog} instance.
  51. *
  52. * @param {Object} props - The read-only properties with which the new
  53. * instance is to be initialized.
  54. */
  55. constructor(props) {
  56. super(props);
  57. /**
  58. * The internal reference to the DOM/HTML element backing the React
  59. * {@code Component} input. It is necessary for the implementation
  60. * of copying to the clipboard.
  61. *
  62. * @private
  63. * @type {HTMLInputElement}
  64. */
  65. this._copyElement = null;
  66. // Bind event handlers so they are only bound once for every instance.
  67. this._onCopyInviteURL = this._onCopyInviteURL.bind(this);
  68. this._onOpenInviteDialog = this._onOpenInviteDialog.bind(this);
  69. this._setCopyElement = this._setCopyElement.bind(this);
  70. }
  71. /**
  72. * Implements React's {@link Component#render()}.
  73. *
  74. * @inheritdoc
  75. * @returns {ReactElement}
  76. */
  77. render() {
  78. return (
  79. <div
  80. className = 'info-dialog'
  81. onMouseOver = { this.props.onMouseOver } >
  82. <div className = 'info-dialog-column'>
  83. <h4 className = 'info-dialog-icon'>
  84. <i className = 'icon-info' />
  85. </h4>
  86. </div>
  87. <div className = 'info-dialog-column'>
  88. <div className = 'info-dialog-title'>
  89. { this.props.t('info.title') }
  90. </div>
  91. <div
  92. className = 'info-dialog-conference-url'
  93. ref = { this._inviteUrlElement }>
  94. { this.props._inviteURL }
  95. <input
  96. className = 'info-dialog-copy-element'
  97. readOnly = { true }
  98. ref = { this._setCopyElement }
  99. tabIndex = '-1'
  100. value = { this.props._inviteURL } />
  101. </div>
  102. <div className = 'info-dialog-action-links'>
  103. <div className = 'info-dialog-action-link'>
  104. <a onClick = { this._onCopyInviteURL }>
  105. { this.props.t('info.copy') }
  106. </a>
  107. </div>
  108. { this.props._showAddPeople
  109. ? <div className = 'info-dialog-action-link'>
  110. <a onClick = { this._onOpenInviteDialog }>
  111. { this.props.t('info.invite', {
  112. app: interfaceConfig.ADD_PEOPLE_APP_NAME
  113. }) }
  114. </a>
  115. </div>
  116. : null }
  117. </div>
  118. </div>
  119. </div>
  120. );
  121. }
  122. /**
  123. * Callback invoked to copy the contents of {@code this._copyElement} to the
  124. * clipboard.
  125. *
  126. * @private
  127. * @returns {void}
  128. */
  129. _onCopyInviteURL() {
  130. try {
  131. this._copyElement.select();
  132. document.execCommand('copy');
  133. this._copyElement.blur();
  134. } catch (err) {
  135. logger.error('error when copying the text', err);
  136. }
  137. }
  138. /**
  139. * Callback invoked to open the {@code AddPeople} dialog.
  140. *
  141. * @private
  142. * @returns {void}
  143. */
  144. _onOpenInviteDialog() {
  145. this.props.dispatch(openDialog(AddPeopleDialog));
  146. if (this.props.onClose) {
  147. this.props.onClose();
  148. }
  149. }
  150. /**
  151. * Sets the internal reference to the DOM/HTML element backing the React
  152. * {@code Component} input.
  153. *
  154. * @param {HTMLInputElement} element - The DOM/HTML element for this
  155. * {@code Component}'s input.
  156. * @private
  157. * @returns {void}
  158. */
  159. _setCopyElement(element) {
  160. this._copyElement = element;
  161. }
  162. }
  163. /**
  164. * Maps (parts of) the Redux state to the associated props for the
  165. * {@code InfoDialog} component.
  166. *
  167. * @param {Object} state - The Redux state.
  168. * @private
  169. * @returns {{
  170. * _inviteURL: string
  171. * }}
  172. */
  173. function _mapStateToProps(state) {
  174. return {
  175. _inviteURL: getInviteURL(state),
  176. _showAddPeople: !state['features/base/jwt'].isGuest
  177. };
  178. }
  179. export default translate(connect(_mapStateToProps)(InfoDialog));