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

InfoDialog.web.js 5.7KB

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