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.

InfoDialog.js 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. // @flow
  2. import React, { Component } from 'react';
  3. import type { Dispatch } from 'redux';
  4. import { setPassword } from '../../../../base/conference';
  5. import { getInviteURL } from '../../../../base/connection';
  6. import { Dialog } from '../../../../base/dialog';
  7. import { translate } from '../../../../base/i18n';
  8. import { Icon, IconInfo, IconCopy } from '../../../../base/icons';
  9. import { connect } from '../../../../base/redux';
  10. import {
  11. isLocalParticipantModerator,
  12. getLocalParticipant
  13. } from '../../../../base/participants';
  14. import {
  15. _decodeRoomURI,
  16. _getDefaultPhoneNumber,
  17. getDialInfoPageURL,
  18. shouldDisplayDialIn
  19. } from '../../../functions';
  20. import logger from '../../../logger';
  21. import DialInNumber from './DialInNumber';
  22. import PasswordForm from './PasswordForm';
  23. /**
  24. * The type of the React {@code Component} props of {@link InfoDialog}.
  25. */
  26. type Props = {
  27. /**
  28. * Whether or not the current user can modify the current password.
  29. */
  30. _canEditPassword: boolean,
  31. /**
  32. * The JitsiConference for which to display a lock state and change the
  33. * password.
  34. */
  35. _conference: Object,
  36. /**
  37. * The name of the current conference. Used as part of inviting users.
  38. */
  39. _conferenceName: string,
  40. /**
  41. * The number of digits to be used in the password.
  42. */
  43. _passwordNumberOfDigits: ?number,
  44. /**
  45. * The current url of the conference to be copied onto the clipboard.
  46. */
  47. _inviteURL: string,
  48. /**
  49. * The redux representation of the local participant.
  50. */
  51. _localParticipant: Object,
  52. /**
  53. * The current location url of the conference.
  54. */
  55. _locationURL: Object,
  56. /**
  57. * The value for how the conference is locked (or undefined if not locked)
  58. * as defined by room-lock constants.
  59. */
  60. _locked: string,
  61. /**
  62. * The current known password for the JitsiConference.
  63. */
  64. _password: string,
  65. /**
  66. * The object representing the dialIn feature.
  67. */
  68. dialIn: Object,
  69. /**
  70. * Invoked to open a dialog for adding participants to the conference.
  71. */
  72. dispatch: Dispatch<any>,
  73. /**
  74. * Whether is Atlaskit InlineDialog or a normal dialog.
  75. */
  76. isInlineDialog: boolean,
  77. /**
  78. * The current known URL for a live stream in progress.
  79. */
  80. liveStreamViewURL: string,
  81. /**
  82. * Callback invoked when the dialog should be closed.
  83. */
  84. onClose: Function,
  85. /**
  86. * Callback invoked when a mouse-related event has been detected.
  87. */
  88. onMouseOver: Function,
  89. /**
  90. * Invoked to obtain translated strings.
  91. */
  92. t: Function
  93. };
  94. /**
  95. * The type of the React {@code Component} state of {@link InfoDialog}.
  96. */
  97. type State = {
  98. /**
  99. * Whether or not to show the password in editing mode.
  100. */
  101. passwordEditEnabled: boolean,
  102. /**
  103. * The conference dial-in number to display.
  104. */
  105. phoneNumber: ?string
  106. };
  107. /**
  108. * A React Component with the contents for a dialog that shows information about
  109. * the current conference.
  110. *
  111. * @extends Component
  112. */
  113. class InfoDialog extends Component<Props, State> {
  114. _copyElement: ?Object;
  115. _copyUrlElement: ?Object;
  116. /**
  117. * Implements React's {@link Component#getDerivedStateFromProps()}.
  118. *
  119. * @inheritdoc
  120. */
  121. static getDerivedStateFromProps(props, state) {
  122. let phoneNumber = state.phoneNumber;
  123. if (!state.phoneNumber && props.dialIn.numbers) {
  124. phoneNumber = _getDefaultPhoneNumber(props.dialIn.numbers);
  125. }
  126. return {
  127. // Exit edit mode when a password is set locally or remotely.
  128. passwordEditEnabled: state.passwordEditEnabled && props._password
  129. ? false : state.passwordEditEnabled,
  130. phoneNumber
  131. };
  132. }
  133. /**
  134. * {@code InfoDialog} component's local state.
  135. *
  136. * @type {Object}
  137. * @property {boolean} passwordEditEnabled - Whether or not to show the
  138. * {@code PasswordForm} in its editing state.
  139. * @property {string} phoneNumber - The number to display for dialing into
  140. * the conference.
  141. */
  142. state = {
  143. passwordEditEnabled: false,
  144. phoneNumber: undefined
  145. };
  146. /**
  147. * Initializes new {@code InfoDialog} instance.
  148. *
  149. * @param {Object} props - The read-only properties with which the new
  150. * instance is to be initialized.
  151. */
  152. constructor(props: Props) {
  153. super(props);
  154. if (props.dialIn && props.dialIn.numbers) {
  155. this.state.phoneNumber
  156. = _getDefaultPhoneNumber(props.dialIn.numbers);
  157. }
  158. /**
  159. * The internal reference to the DOM/HTML element backing the React
  160. * {@code Component} text area. It is necessary for the implementation
  161. * of copying to the clipboard.
  162. *
  163. * @private
  164. * @type {HTMLTextAreaElement}
  165. */
  166. this._copyElement = null;
  167. // Bind event handlers so they are only bound once for every instance.
  168. this._onClickURLText = this._onClickURLText.bind(this);
  169. this._onCopyInviteInfo = this._onCopyInviteInfo.bind(this);
  170. this._onCopyInviteUrl = this._onCopyInviteUrl.bind(this);
  171. this._onPasswordRemove = this._onPasswordRemove.bind(this);
  172. this._onPasswordSubmit = this._onPasswordSubmit.bind(this);
  173. this._onTogglePasswordEditState
  174. = this._onTogglePasswordEditState.bind(this);
  175. this._setCopyElement = this._setCopyElement.bind(this);
  176. this._setCopyUrlElement = this._setCopyUrlElement.bind(this);
  177. }
  178. /**
  179. * Implements React's {@link Component#render()}.
  180. *
  181. * @inheritdoc
  182. * @returns {ReactElement}
  183. */
  184. render() {
  185. const {
  186. isInlineDialog,
  187. liveStreamViewURL,
  188. onMouseOver,
  189. t
  190. } = this.props;
  191. const inlineDialog = (
  192. <div
  193. className = 'info-dialog'
  194. onMouseOver = { onMouseOver } >
  195. <div className = 'info-dialog-column'>
  196. <h4 className = 'info-dialog-icon'>
  197. <Icon src = { IconInfo } />
  198. </h4>
  199. </div>
  200. <div className = 'info-dialog-column'>
  201. <div className = 'info-dialog-title'>
  202. { t('info.title') }
  203. </div>
  204. <div className = 'info-dialog-conference-url'>
  205. <span className = 'info-label'>
  206. { t('info.conferenceURL') }
  207. </span>
  208. <span className = 'spacer'>&nbsp;</span>
  209. <span className = 'info-value'>
  210. <a
  211. className = 'info-dialog-url-text info-dialog-url-text-unselectable'
  212. href = { this.props._inviteURL }
  213. onClick = { this._onClickURLText } >
  214. { decodeURI(this._getURLToDisplay()) }
  215. </a>
  216. </span>
  217. <span className = 'info-dialog-url-icon'>
  218. <Icon
  219. onClick = { this._onCopyInviteUrl }
  220. size = { 18 }
  221. src = { IconCopy } />
  222. </span>
  223. </div>
  224. <div className = 'info-dialog-dial-in'>
  225. { this._renderDialInDisplay() }
  226. </div>
  227. { liveStreamViewURL && this._renderLiveStreamURL() }
  228. <div className = 'info-dialog-password'>
  229. <PasswordForm
  230. editEnabled = { this.state.passwordEditEnabled }
  231. locked = { this.props._locked }
  232. onSubmit = { this._onPasswordSubmit }
  233. password = { this.props._password }
  234. passwordNumberOfDigits = { this.props._passwordNumberOfDigits } />
  235. </div>
  236. <div className = 'info-dialog-action-links'>
  237. <div className = 'info-dialog-action-link'>
  238. <a
  239. className = 'info-copy'
  240. onClick = { this._onCopyInviteInfo }>
  241. { t('dialog.copy') }
  242. </a>
  243. </div>
  244. { this._renderPasswordAction() }
  245. </div>
  246. </div>
  247. <textarea
  248. className = 'info-dialog-copy-element'
  249. readOnly = { true }
  250. ref = { this._setCopyElement }
  251. tabIndex = '-1'
  252. value = { this._getTextToCopy() } />
  253. <textarea
  254. className = 'info-dialog-copy-element'
  255. readOnly = { true }
  256. ref = { this._setCopyUrlElement }
  257. tabIndex = '-1'
  258. value = { this.props._inviteURL } />
  259. </div>
  260. );
  261. if (isInlineDialog) {
  262. return inlineDialog;
  263. }
  264. return (
  265. <Dialog
  266. cancelTitleKey = 'dialog.close'
  267. submitDisabled = { true }
  268. titleKey = 'info.label'
  269. width = 'small'>
  270. { inlineDialog }
  271. </Dialog>
  272. );
  273. }
  274. /**
  275. * Creates a message describing how to dial in to the conference.
  276. *
  277. * @private
  278. * @returns {string}
  279. */
  280. _getTextToCopy() {
  281. const { _localParticipant, liveStreamViewURL, t } = this.props;
  282. const _inviteURL = _decodeRoomURI(this.props._inviteURL);
  283. let invite = _localParticipant && _localParticipant.name
  284. ? t('info.inviteURLFirstPartPersonal', { name: _localParticipant.name })
  285. : t('info.inviteURLFirstPartGeneral');
  286. invite += t('info.inviteURLSecondPart', {
  287. url: _inviteURL
  288. });
  289. if (liveStreamViewURL) {
  290. const liveStream = t('info.inviteLiveStream', {
  291. url: liveStreamViewURL
  292. });
  293. invite = `${invite}\n${liveStream}`;
  294. }
  295. if (shouldDisplayDialIn(this.props.dialIn)) {
  296. const dial = t('info.invitePhone', {
  297. number: this.state.phoneNumber,
  298. conferenceID: this.props.dialIn.conferenceID
  299. });
  300. const moreNumbers = t('info.invitePhoneAlternatives', {
  301. url: getDialInfoPageURL(
  302. this.props._conferenceName,
  303. this.props._locationURL
  304. ),
  305. silentUrl: `${_inviteURL}#config.startSilent=true`
  306. });
  307. invite = `${invite}\n${dial}\n${moreNumbers}`;
  308. }
  309. return invite;
  310. }
  311. /**
  312. * Modifies the inviteURL for display in the modal.
  313. *
  314. * @private
  315. * @returns {string}
  316. */
  317. _getURLToDisplay() {
  318. return this.props._inviteURL.replace(/^https?:\/\//i, '');
  319. }
  320. _onClickURLText: (Object) => void;
  321. /**
  322. * Callback invoked when a displayed URL link is clicked to prevent actual
  323. * navigation from happening. The URL links have an href to display the
  324. * action "Copy Link Address" in the context menu but otherwise it should
  325. * not behave like links.
  326. *
  327. * @param {Object} event - The click event from clicking on the link.
  328. * @private
  329. * @returns {void}
  330. */
  331. _onClickURLText(event) {
  332. event.preventDefault();
  333. }
  334. _onCopyInviteInfo: () => void;
  335. /**
  336. * Callback invoked to copy the contents of {@code this._copyElement} to the
  337. * clipboard.
  338. *
  339. * @private
  340. * @returns {void}
  341. */
  342. _onCopyInviteInfo() {
  343. try {
  344. if (!this._copyElement) {
  345. throw new Error('No element to copy from.');
  346. }
  347. this._copyElement && this._copyElement.select();
  348. document.execCommand('copy');
  349. this._copyElement && this._copyElement.blur();
  350. } catch (err) {
  351. logger.error('error when copying the text', err);
  352. }
  353. }
  354. _onCopyInviteUrl: () => void;
  355. /**
  356. * Callback invoked to copy the contents of {@code this._copyUrlElement} to the clipboard.
  357. *
  358. * @private
  359. * @returns {void}
  360. */
  361. _onCopyInviteUrl() {
  362. try {
  363. if (!this._copyUrlElement) {
  364. throw new Error('No element to copy from.');
  365. }
  366. this._copyUrlElement && this._copyUrlElement.select();
  367. document.execCommand('copy');
  368. this._copyUrlElement && this._copyUrlElement.blur();
  369. } catch (err) {
  370. logger.error('error when copying the text', err);
  371. }
  372. }
  373. _onPasswordRemove: () => void;
  374. /**
  375. * Callback invoked to unlock the current JitsiConference.
  376. *
  377. * @private
  378. * @returns {void}
  379. */
  380. _onPasswordRemove() {
  381. this._onPasswordSubmit('');
  382. }
  383. _onPasswordSubmit: (string) => void;
  384. /**
  385. * Callback invoked to set a password on the current JitsiConference.
  386. *
  387. * @param {string} enteredPassword - The new password to be used to lock the
  388. * current JitsiConference.
  389. * @private
  390. * @returns {void}
  391. */
  392. _onPasswordSubmit(enteredPassword) {
  393. const { _conference } = this.props;
  394. this.props.dispatch(setPassword(
  395. _conference,
  396. _conference.lock,
  397. enteredPassword
  398. ));
  399. }
  400. _onTogglePasswordEditState: () => void;
  401. /**
  402. * Toggles whether or not the password should currently be shown as being
  403. * edited locally.
  404. *
  405. * @private
  406. * @returns {void}
  407. */
  408. _onTogglePasswordEditState() {
  409. this.setState({
  410. passwordEditEnabled: !this.state.passwordEditEnabled
  411. });
  412. }
  413. /**
  414. * Returns a ReactElement for showing how to dial into the conference, if
  415. * dialing in is available.
  416. *
  417. * @private
  418. * @returns {null|ReactElement}
  419. */
  420. _renderDialInDisplay() {
  421. if (!shouldDisplayDialIn(this.props.dialIn)) {
  422. return null;
  423. }
  424. return (
  425. <div>
  426. <DialInNumber
  427. conferenceID = { this.props.dialIn.conferenceID }
  428. phoneNumber = { this.state.phoneNumber } />
  429. <a
  430. className = 'more-numbers'
  431. href = {
  432. getDialInfoPageURL(
  433. this.props._conferenceName,
  434. this.props._locationURL
  435. )
  436. }
  437. rel = 'noopener noreferrer'
  438. target = '_blank'>
  439. { this.props.t('info.moreNumbers') }
  440. </a>
  441. </div>
  442. );
  443. }
  444. /**
  445. * Returns a ReactElement for interacting with the password field.
  446. *
  447. * @private
  448. * @returns {null|ReactElement}
  449. */
  450. _renderPasswordAction() {
  451. const { t } = this.props;
  452. let className, onClick, textKey;
  453. if (!this.props._canEditPassword) {
  454. // intentionally left blank to prevent rendering anything
  455. } else if (this.state.passwordEditEnabled) {
  456. className = 'cancel-password';
  457. onClick = this._onTogglePasswordEditState;
  458. textKey = 'info.cancelPassword';
  459. } else if (this.props._locked) {
  460. className = 'remove-password';
  461. onClick = this._onPasswordRemove;
  462. textKey = 'dialog.removePassword';
  463. } else {
  464. className = 'add-password';
  465. onClick = this._onTogglePasswordEditState;
  466. textKey = 'info.addPassword';
  467. }
  468. return className && onClick && textKey
  469. ? <div className = 'info-dialog-action-link'>
  470. <a
  471. className = { className }
  472. onClick = { onClick }>
  473. { t(textKey) }
  474. </a>
  475. </div>
  476. : null;
  477. }
  478. /**
  479. * Returns a ReactElement for display a link to the current url of a
  480. * live stream in progress.
  481. *
  482. * @private
  483. * @returns {null|ReactElement}
  484. */
  485. _renderLiveStreamURL() {
  486. const { liveStreamViewURL, t } = this.props;
  487. return (
  488. <div className = 'info-dialog-live-stream-url'>
  489. <span className = 'info-label'>
  490. { t('info.liveStreamURL') }
  491. </span>
  492. <span className = 'spacer'>&nbsp;</span>
  493. <span className = 'info-value'>
  494. <a
  495. className = 'info-dialog-url-text'
  496. href = { liveStreamViewURL }
  497. onClick = { this._onClickURLText } >
  498. { liveStreamViewURL }
  499. </a>
  500. </span>
  501. </div>
  502. );
  503. }
  504. _setCopyElement: () => void;
  505. /**
  506. * Sets the internal reference to the DOM/HTML element backing the React
  507. * {@code Component} input.
  508. *
  509. * @param {HTMLInputElement} element - The DOM/HTML element for this
  510. * {@code Component}'s input.
  511. * @private
  512. * @returns {void}
  513. */
  514. _setCopyElement(element: Object) {
  515. this._copyElement = element;
  516. }
  517. _setCopyUrlElement: () => void;
  518. /**
  519. * Sets the internal reference to the DOM/HTML element backing the React
  520. * {@code Component} input.
  521. *
  522. * @param {HTMLInputElement} element - The DOM/HTML element for this
  523. * {@code Component}'s input.
  524. * @private
  525. * @returns {void}
  526. */
  527. _setCopyUrlElement(element: Object) {
  528. this._copyUrlElement = element;
  529. }
  530. }
  531. /**
  532. * Maps (parts of) the Redux state to the associated props for the
  533. * {@code InfoDialog} component.
  534. *
  535. * @param {Object} state - The Redux state.
  536. * @private
  537. * @returns {{
  538. * _canEditPassword: boolean,
  539. * _conference: Object,
  540. * _conferenceName: string,
  541. * _inviteURL: string,
  542. * _locationURL: string,
  543. * _locked: string,
  544. * _password: string
  545. * }}
  546. */
  547. function _mapStateToProps(state) {
  548. const {
  549. conference,
  550. locked,
  551. password,
  552. room
  553. } = state['features/base/conference'];
  554. return {
  555. _canEditPassword: isLocalParticipantModerator(state, state['features/base/config'].lockRoomGuestEnabled),
  556. _conference: conference,
  557. _conferenceName: room,
  558. _passwordNumberOfDigits: state['features/base/config'].roomPasswordNumberOfDigits,
  559. _inviteURL: getInviteURL(state),
  560. _localParticipant: getLocalParticipant(state),
  561. _locationURL: state['features/base/connection'].locationURL,
  562. _locked: locked,
  563. _password: password
  564. };
  565. }
  566. export default translate(connect(_mapStateToProps)(InfoDialog));