Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. import PropTypes from 'prop-types';
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. import { setPassword } from '../../../base/conference';
  5. import { getInviteURL } from '../../../base/connection';
  6. import { translate } from '../../../base/i18n';
  7. import {
  8. PARTICIPANT_ROLE,
  9. getLocalParticipant
  10. } from '../../../base/participants';
  11. import { updateDialInNumbers } from '../../actions';
  12. import DialInNumber from './DialInNumber';
  13. import PasswordForm from './PasswordForm';
  14. const logger = require('jitsi-meet-logger').getLogger(__filename);
  15. /**
  16. * A React Component with the contents for a dialog that shows information about
  17. * the current conference.
  18. *
  19. * @extends Component
  20. */
  21. class InfoDialog extends Component {
  22. /**
  23. * Default values for {@code InfoDialog} component's properties.
  24. *
  25. * @static
  26. */
  27. static defaultProps = {
  28. autoUpdateNumbers: true
  29. };
  30. /**
  31. * {@code InfoDialog} component's property types.
  32. *
  33. * @static
  34. */
  35. static propTypes = {
  36. /**
  37. * Whether or not the current user can modify the current password.
  38. */
  39. _canEditPassword: PropTypes.bool,
  40. /**
  41. * The JitsiConference for which to display a lock state and change the
  42. * password.
  43. *
  44. * @type {JitsiConference}
  45. */
  46. _conference: PropTypes.object,
  47. /**
  48. * The name of the current conference. Used as part of inviting users.
  49. */
  50. _conferenceName: PropTypes.string,
  51. /**
  52. * The redux state representing the dial-in numbers feature.
  53. */
  54. _dialIn: PropTypes.object,
  55. /**
  56. * The current url of the conference to be copied onto the clipboard.
  57. */
  58. _inviteURL: PropTypes.string,
  59. /**
  60. * The value for how the conference is locked (or undefined if not
  61. * locked) as defined by room-lock constants.
  62. */
  63. _locked: PropTypes.string,
  64. /**
  65. * The current known password for the JitsiConference.
  66. */
  67. _password: PropTypes.string,
  68. /**
  69. * Whether or not this component should make a request for dial-in
  70. * numbers. If false, this component will rely on an outside source
  71. * updating and passing in numbers through the _dialIn prop.
  72. */
  73. autoUpdateNumbers: PropTypes.bool,
  74. /**
  75. * Invoked to open a dialog for adding participants to the conference.
  76. */
  77. dispatch: PropTypes.func,
  78. /**
  79. * Callback invoked when the dialog should be closed.
  80. */
  81. onClose: PropTypes.func,
  82. /**
  83. * Callback invoked when a mouse-related event has been detected.
  84. */
  85. onMouseOver: PropTypes.func,
  86. /**
  87. * Invoked to obtain translated strings.
  88. */
  89. t: PropTypes.func
  90. };
  91. /**
  92. * {@code InfoDialog} component's local state.
  93. *
  94. * @type {Object}
  95. * @property {boolean} passwordEditEnabled - Whether or not to show the
  96. * {@code PasswordForm} in its editing state.
  97. * @property {string} phoneNumber - The number to display for dialing into
  98. * the conference.
  99. */
  100. state = {
  101. passwordEditEnabled: false,
  102. phoneNumber: ''
  103. };
  104. /**
  105. * Initializes new {@code InfoDialog} instance.
  106. *
  107. * @param {Object} props - The read-only properties with which the new
  108. * instance is to be initialized.
  109. */
  110. constructor(props) {
  111. super(props);
  112. const { defaultCountry, numbers } = props._dialIn;
  113. if (numbers) {
  114. this.state.phoneNumber
  115. = this._getDefaultPhoneNumber(numbers, defaultCountry);
  116. }
  117. /**
  118. * The internal reference to the DOM/HTML element backing the React
  119. * {@code Component} text area. It is necessary for the implementation
  120. * of copying to the clipboard.
  121. *
  122. * @private
  123. * @type {HTMLTextAreaElement}
  124. */
  125. this._copyElement = null;
  126. // Bind event handlers so they are only bound once for every instance.
  127. this._onClickInviteURL = this._onClickInviteURL.bind(this);
  128. this._onCopyInviteURL = this._onCopyInviteURL.bind(this);
  129. this._onPasswordRemove = this._onPasswordRemove.bind(this);
  130. this._onPasswordSubmit = this._onPasswordSubmit.bind(this);
  131. this._onTogglePasswordEditState
  132. = this._onTogglePasswordEditState.bind(this);
  133. this._setCopyElement = this._setCopyElement.bind(this);
  134. }
  135. /**
  136. * Implements {@link Component#componentDidMount()}. Invoked immediately
  137. * after this component is mounted. Requests dial-in numbers if not
  138. * already known.
  139. *
  140. * @inheritdoc
  141. * @returns {void}
  142. */
  143. componentDidMount() {
  144. if (!this.state.phoneNumber && this.props.autoUpdateNumbers) {
  145. this.props.dispatch(updateDialInNumbers());
  146. }
  147. }
  148. /**
  149. * Implements React's {@link Component#componentWillReceiveProps()}. Invoked
  150. * before this mounted component receives new props.
  151. *
  152. * @inheritdoc
  153. * @param {Props} nextProps - New props component will receive.
  154. */
  155. componentWillReceiveProps(nextProps) {
  156. if (!this.props._password && nextProps._password) {
  157. this.setState({ passwordEditEnabled: false });
  158. }
  159. if (!this.state.phoneNumber && nextProps._dialIn.numbers) {
  160. const { defaultCountry, numbers } = nextProps._dialIn;
  161. this.setState({
  162. phoneNumber:
  163. this._getDefaultPhoneNumber(numbers, defaultCountry)
  164. });
  165. }
  166. }
  167. /**
  168. * Implements React's {@link Component#render()}.
  169. *
  170. * @inheritdoc
  171. * @returns {ReactElement}
  172. */
  173. render() {
  174. const { onMouseOver, t } = this.props;
  175. return (
  176. <div
  177. className = 'info-dialog'
  178. onMouseOver = { onMouseOver } >
  179. <div className = 'info-dialog-column'>
  180. <h4 className = 'info-dialog-icon'>
  181. <i className = 'icon-info' />
  182. </h4>
  183. </div>
  184. <div className = 'info-dialog-column'>
  185. <div className = 'info-dialog-title'>
  186. { t('info.title') }
  187. </div>
  188. <div className = 'info-dialog-conference-url'>
  189. <span className = 'info-label'>
  190. { t('info.conferenceURL') }
  191. </span>
  192. <span className = 'spacer'>&nbsp;</span>
  193. <span className = 'info-value'>
  194. <a
  195. className = 'info-dialog-invite-link'
  196. href = { this.props._inviteURL }
  197. onClick = { this._onClickInviteURL } >
  198. { this._getURLToDisplay() }
  199. </a>
  200. </span>
  201. </div>
  202. <div className = 'info-dialog-dial-in'>
  203. { this._renderDialInDisplay() }
  204. </div>
  205. <div className = 'info-dialog-password'>
  206. <PasswordForm
  207. editEnabled = { this.state.passwordEditEnabled }
  208. locked = { this.props._locked }
  209. onSubmit = { this._onPasswordSubmit }
  210. password = { this.props._password } />
  211. </div>
  212. <div className = 'info-dialog-action-links'>
  213. <div className = 'info-dialog-action-link'>
  214. <a
  215. className = 'info-copy'
  216. onClick = { this._onCopyInviteURL }>
  217. { t('dialog.copy') }
  218. </a>
  219. </div>
  220. { this._renderPasswordAction() }
  221. </div>
  222. </div>
  223. <textarea
  224. className = 'info-dialog-copy-element'
  225. readOnly = { true }
  226. ref = { this._setCopyElement }
  227. tabIndex = '-1'
  228. value = { this._getTextToCopy() } />
  229. </div>
  230. );
  231. }
  232. /**
  233. * Sets the internal state of which dial-in number to display.
  234. *
  235. * @param {Array<string>|Object} dialInNumbers - The array or object of
  236. * numbers to choose a number from.
  237. * @param {string} defaultCountry - The country code for the country
  238. * whose phone number should display.
  239. * @private
  240. * @returns {string|null}
  241. */
  242. _getDefaultPhoneNumber(dialInNumbers, defaultCountry = 'US') {
  243. if (Array.isArray(dialInNumbers)) {
  244. // Dumbly return the first number if an array.
  245. return dialInNumbers[0];
  246. } else if (Object.keys(dialInNumbers).length > 0) {
  247. const defaultNumbers = dialInNumbers[defaultCountry];
  248. if (defaultNumbers) {
  249. return defaultNumbers[0];
  250. }
  251. const firstRegion = Object.keys(dialInNumbers)[0];
  252. return firstRegion && firstRegion[0];
  253. }
  254. return null;
  255. }
  256. /**
  257. * Generates the URL for the static dial in info page.
  258. *
  259. * @private
  260. * @returns {string}
  261. */
  262. _getDialInfoPageURL() {
  263. const origin = window.location.origin;
  264. const encodedConferenceName
  265. = encodeURIComponent(this.props._conferenceName);
  266. const pathParts = window.location.pathname.split('/');
  267. pathParts.length = pathParts.length - 1;
  268. const newPath = pathParts.reduce((accumulator, currentValue) => {
  269. if (currentValue) {
  270. return `${accumulator}/${currentValue}`;
  271. }
  272. return accumulator;
  273. }, '');
  274. return `${origin}${newPath}/static/dialInInfo.html?room=${
  275. encodedConferenceName}`;
  276. }
  277. /**
  278. * Creates a message describing how to dial in to the conference.
  279. *
  280. * @private
  281. * @returns {string}
  282. */
  283. _getTextToCopy() {
  284. const { t } = this.props;
  285. let invite = t('info.inviteURL', {
  286. url: this.props._inviteURL
  287. });
  288. if (this._shouldDisplayDialIn()) {
  289. const dial = t('info.invitePhone', {
  290. number: this.state.phoneNumber,
  291. conferenceID: this.props._dialIn.conferenceID
  292. });
  293. const moreNumbers = t('info.invitePhoneAlternatives', {
  294. url: this._getDialInfoPageURL()
  295. });
  296. invite = `${invite}\n${dial}\n${moreNumbers}`;
  297. }
  298. return invite;
  299. }
  300. /**
  301. * Modifies the inviteURL for display in the modal.
  302. *
  303. * @private
  304. * @returns {string}
  305. */
  306. _getURLToDisplay() {
  307. return this.props._inviteURL.replace(/^https?:\/\//i, '');
  308. }
  309. /**
  310. * Callback invoked when the displayed invite URL link is clicked to prevent
  311. * actual navigation from happening. The invite URL link has an href to
  312. * display "Copy Link Address" in the context menu but otherwise it should
  313. * not behave like a link.
  314. *
  315. * @param {Object} event - The click event from clicking on the link.
  316. * @private
  317. * @returns {void}
  318. */
  319. _onClickInviteURL(event) {
  320. event.preventDefault();
  321. }
  322. /**
  323. * Callback invoked to copy the contents of {@code this._copyElement} to the
  324. * clipboard.
  325. *
  326. * @private
  327. * @returns {void}
  328. */
  329. _onCopyInviteURL() {
  330. try {
  331. this._copyElement.select();
  332. document.execCommand('copy');
  333. this._copyElement.blur();
  334. } catch (err) {
  335. logger.error('error when copying the text', err);
  336. }
  337. }
  338. /**
  339. * Callback invoked to unlock the current JitsiConference.
  340. *
  341. * @private
  342. * @returns {void}
  343. */
  344. _onPasswordRemove() {
  345. this._onPasswordSubmit('');
  346. }
  347. /**
  348. * Callback invoked to set a password on the current JitsiConference.
  349. *
  350. * @param {string} enteredPassword - The new password to be used to lock the
  351. * current JitsiConference.
  352. * @private
  353. * @returns {void}
  354. */
  355. _onPasswordSubmit(enteredPassword) {
  356. const { _conference } = this.props;
  357. this.props.dispatch(setPassword(
  358. _conference,
  359. _conference.lock,
  360. enteredPassword
  361. ));
  362. }
  363. /**
  364. * Toggles whether or not the password should currently be shown as being
  365. * edited locally.
  366. *
  367. * @private
  368. * @returns {void}
  369. */
  370. _onTogglePasswordEditState() {
  371. this.setState({
  372. passwordEditEnabled: !this.state.passwordEditEnabled
  373. });
  374. }
  375. /**
  376. * Returns a ReactElement for showing how to dial into the conference, if
  377. * dialing in is available.
  378. *
  379. * @private
  380. * @returns {null|ReactElement}
  381. */
  382. _renderDialInDisplay() {
  383. if (!this._shouldDisplayDialIn()) {
  384. return null;
  385. }
  386. return (
  387. <div>
  388. <DialInNumber
  389. conferenceID = { this.props._dialIn.conferenceID }
  390. phoneNumber = { this.state.phoneNumber } />
  391. <a
  392. className = 'more-numbers'
  393. href = { this._getDialInfoPageURL() }
  394. rel = 'noopener noreferrer'
  395. target = '_blank'>
  396. { this.props.t('info.moreNumbers') }
  397. </a>
  398. </div>
  399. );
  400. }
  401. /**
  402. * Returns a ReactElement for interacting with the password field.
  403. *
  404. * @private
  405. * @returns {null|ReactElement}
  406. */
  407. _renderPasswordAction() {
  408. const { t } = this.props;
  409. let className, onClick, textKey;
  410. if (!this.props._canEditPassword) {
  411. // intentionally left blank to prevent rendering anything
  412. } else if (this.state.passwordEditEnabled) {
  413. className = 'cancel-password';
  414. onClick = this._onTogglePasswordEditState;
  415. textKey = 'info.cancelPassword';
  416. } else if (this.props._locked) {
  417. className = 'remove-password';
  418. onClick = this._onPasswordRemove;
  419. textKey = 'dialog.removePassword';
  420. } else {
  421. className = 'add-password';
  422. onClick = this._onTogglePasswordEditState;
  423. textKey = 'info.addPassword';
  424. }
  425. return className && onClick && textKey
  426. ? <div className = 'info-dialog-action-link'>
  427. <a
  428. className = { className }
  429. onClick = { onClick }>
  430. { t(textKey) }
  431. </a>
  432. </div>
  433. : null;
  434. }
  435. /**
  436. * Returns whether or not dial-in related UI should be displayed.
  437. *
  438. * @private
  439. * @returns {boolean}
  440. */
  441. _shouldDisplayDialIn() {
  442. const { conferenceID, numbers, numbersEnabled } = this.props._dialIn;
  443. const { phoneNumber } = this.state;
  444. return Boolean(
  445. conferenceID
  446. && numbers
  447. && numbersEnabled
  448. && phoneNumber);
  449. }
  450. /**
  451. * Sets the internal reference to the DOM/HTML element backing the React
  452. * {@code Component} input.
  453. *
  454. * @param {HTMLInputElement} element - The DOM/HTML element for this
  455. * {@code Component}'s input.
  456. * @private
  457. * @returns {void}
  458. */
  459. _setCopyElement(element) {
  460. this._copyElement = element;
  461. }
  462. }
  463. /**
  464. * Maps (parts of) the Redux state to the associated props for the
  465. * {@code InfoDialog} component.
  466. *
  467. * @param {Object} state - The Redux state.
  468. * @private
  469. * @returns {{
  470. * _canEditPassword: boolean,
  471. * _conference: Object,
  472. * _conferenceName: string,
  473. * _dialIn: Object,
  474. * _inviteURL: string,
  475. * _locked: string,
  476. * _password: string
  477. * }}
  478. */
  479. function _mapStateToProps(state) {
  480. const {
  481. conference,
  482. locked,
  483. password,
  484. room
  485. } = state['features/base/conference'];
  486. const isModerator
  487. = getLocalParticipant(state).role === PARTICIPANT_ROLE.MODERATOR;
  488. let canEditPassword;
  489. if (state['features/base/config'].enableUserRolesBasedOnToken) {
  490. canEditPassword = isModerator && !state['features/base/jwt'].isGuest;
  491. } else {
  492. canEditPassword = isModerator;
  493. }
  494. return {
  495. _canEditPassword: canEditPassword,
  496. _conference: conference,
  497. _conferenceName: room,
  498. _dialIn: state['features/invite'],
  499. _inviteURL: getInviteURL(state),
  500. _locked: locked,
  501. _password: password
  502. };
  503. }
  504. export default translate(connect(_mapStateToProps)(InfoDialog));