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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  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. } from '../../../functions';
  19. import logger from '../../../logger';
  20. import DialInNumber from './DialInNumber';
  21. import PasswordForm from './PasswordForm';
  22. /**
  23. * The type of the React {@code Component} props of {@link InfoDialog}.
  24. */
  25. type Props = {
  26. /**
  27. * Whether or not the current user can modify the current password.
  28. */
  29. _canEditPassword: boolean,
  30. /**
  31. * The JitsiConference for which to display a lock state and change the
  32. * password.
  33. */
  34. _conference: Object,
  35. /**
  36. * The name of the current conference. Used as part of inviting users.
  37. */
  38. _conferenceName: string,
  39. /**
  40. * The number of digits to be used in the password.
  41. */
  42. _passwordNumberOfDigits: ?number,
  43. /**
  44. * The current url of the conference to be copied onto the clipboard.
  45. */
  46. _inviteURL: string,
  47. /**
  48. * The redux representation of the local participant.
  49. */
  50. _localParticipant: Object,
  51. /**
  52. * The current location url of the conference.
  53. */
  54. _locationURL: Object,
  55. /**
  56. * The value for how the conference is locked (or undefined if not locked)
  57. * as defined by room-lock constants.
  58. */
  59. _locked: string,
  60. /**
  61. * The current known password for the JitsiConference.
  62. */
  63. _password: string,
  64. /**
  65. * The object representing the dialIn feature.
  66. */
  67. dialIn: Object,
  68. /**
  69. * Invoked to open a dialog for adding participants to the conference.
  70. */
  71. dispatch: Dispatch<any>,
  72. /**
  73. * Whether is Atlaskit InlineDialog or a normal dialog.
  74. */
  75. isInlineDialog: boolean,
  76. /**
  77. * The current known URL for a live stream in progress.
  78. */
  79. liveStreamViewURL: string,
  80. /**
  81. * Callback invoked when the dialog should be closed.
  82. */
  83. onClose: Function,
  84. /**
  85. * Callback invoked when a mouse-related event has been detected.
  86. */
  87. onMouseOver: Function,
  88. /**
  89. * Invoked to obtain translated strings.
  90. */
  91. t: Function
  92. };
  93. /**
  94. * The type of the React {@code Component} state of {@link InfoDialog}.
  95. */
  96. type State = {
  97. /**
  98. * Whether or not to show the password in editing mode.
  99. */
  100. passwordEditEnabled: boolean,
  101. /**
  102. * The conference dial-in number to display.
  103. */
  104. phoneNumber: ?string
  105. };
  106. /**
  107. * A React Component with the contents for a dialog that shows information about
  108. * the current conference.
  109. *
  110. * @extends Component
  111. */
  112. class InfoDialog extends Component<Props, State> {
  113. _copyElement: ?Object;
  114. _copyUrlElement: ?Object;
  115. /**
  116. * Implements React's {@link Component#getDerivedStateFromProps()}.
  117. *
  118. * @inheritdoc
  119. */
  120. static getDerivedStateFromProps(props, state) {
  121. let phoneNumber = state.phoneNumber;
  122. if (!state.phoneNumber && props.dialIn.numbers) {
  123. phoneNumber = _getDefaultPhoneNumber(props.dialIn.numbers);
  124. }
  125. return {
  126. // Exit edit mode when a password is set locally or remotely.
  127. passwordEditEnabled: state.passwordEditEnabled && props._password
  128. ? false : state.passwordEditEnabled,
  129. phoneNumber
  130. };
  131. }
  132. /**
  133. * {@code InfoDialog} component's local state.
  134. *
  135. * @type {Object}
  136. * @property {boolean} passwordEditEnabled - Whether or not to show the
  137. * {@code PasswordForm} in its editing state.
  138. * @property {string} phoneNumber - The number to display for dialing into
  139. * the conference.
  140. */
  141. state = {
  142. passwordEditEnabled: false,
  143. phoneNumber: undefined
  144. };
  145. /**
  146. * Initializes new {@code InfoDialog} instance.
  147. *
  148. * @param {Object} props - The read-only properties with which the new
  149. * instance is to be initialized.
  150. */
  151. constructor(props: Props) {
  152. super(props);
  153. if (props.dialIn && props.dialIn.numbers) {
  154. this.state.phoneNumber
  155. = _getDefaultPhoneNumber(props.dialIn.numbers);
  156. }
  157. /**
  158. * The internal reference to the DOM/HTML element backing the React
  159. * {@code Component} text area. It is necessary for the implementation
  160. * of copying to the clipboard.
  161. *
  162. * @private
  163. * @type {HTMLTextAreaElement}
  164. */
  165. this._copyElement = null;
  166. // Bind event handlers so they are only bound once for every instance.
  167. this._onClickURLText = this._onClickURLText.bind(this);
  168. this._onCopyInviteInfo = this._onCopyInviteInfo.bind(this);
  169. this._onCopyInviteUrl = this._onCopyInviteUrl.bind(this);
  170. this._onPasswordRemove = this._onPasswordRemove.bind(this);
  171. this._onPasswordSubmit = this._onPasswordSubmit.bind(this);
  172. this._onTogglePasswordEditState
  173. = this._onTogglePasswordEditState.bind(this);
  174. this._setCopyElement = this._setCopyElement.bind(this);
  175. this._setCopyUrlElement = this._setCopyUrlElement.bind(this);
  176. }
  177. /**
  178. * Implements React's {@link Component#render()}.
  179. *
  180. * @inheritdoc
  181. * @returns {ReactElement}
  182. */
  183. render() {
  184. const {
  185. isInlineDialog,
  186. liveStreamViewURL,
  187. onMouseOver,
  188. t
  189. } = this.props;
  190. const inlineDialog = (
  191. <div
  192. className = 'info-dialog'
  193. onMouseOver = { onMouseOver } >
  194. <div className = 'info-dialog-column'>
  195. <h4 className = 'info-dialog-icon'>
  196. <Icon src = { IconInfo } />
  197. </h4>
  198. </div>
  199. <div className = 'info-dialog-column'>
  200. <div className = 'info-dialog-title'>
  201. { t('info.title') }
  202. </div>
  203. <div className = 'info-dialog-conference-url'>
  204. <span className = 'info-label'>
  205. { t('info.conferenceURL') }
  206. </span>
  207. <span className = 'spacer'>&nbsp;</span>
  208. <span className = 'info-value'>
  209. <a
  210. className = 'info-dialog-url-text info-dialog-url-text-unselectable'
  211. href = { this.props._inviteURL }
  212. onClick = { this._onClickURLText } >
  213. { decodeURI(this._getURLToDisplay()) }
  214. </a>
  215. </span>
  216. <span className = 'info-dialog-url-icon'>
  217. <Icon
  218. onClick = { this._onCopyInviteUrl }
  219. size = { 18 }
  220. src = { IconCopy } />
  221. </span>
  222. </div>
  223. <div className = 'info-dialog-dial-in'>
  224. { this._renderDialInDisplay() }
  225. </div>
  226. { liveStreamViewURL && this._renderLiveStreamURL() }
  227. <div className = 'info-dialog-password'>
  228. <PasswordForm
  229. editEnabled = { this.state.passwordEditEnabled }
  230. locked = { this.props._locked }
  231. onSubmit = { this._onPasswordSubmit }
  232. password = { this.props._password }
  233. passwordNumberOfDigits = { this.props._passwordNumberOfDigits } />
  234. </div>
  235. <div className = 'info-dialog-action-links'>
  236. <div className = 'info-dialog-action-link'>
  237. <a
  238. className = 'info-copy'
  239. onClick = { this._onCopyInviteInfo }>
  240. { t('dialog.copy') }
  241. </a>
  242. </div>
  243. { this._renderPasswordAction() }
  244. </div>
  245. </div>
  246. <textarea
  247. className = 'info-dialog-copy-element'
  248. readOnly = { true }
  249. ref = { this._setCopyElement }
  250. tabIndex = '-1'
  251. value = { this._getTextToCopy() } />
  252. <textarea
  253. className = 'info-dialog-copy-element'
  254. readOnly = { true }
  255. ref = { this._setCopyUrlElement }
  256. tabIndex = '-1'
  257. value = { this.props._inviteURL } />
  258. </div>
  259. );
  260. if (isInlineDialog) {
  261. return inlineDialog;
  262. }
  263. return (
  264. <Dialog
  265. cancelTitleKey = 'dialog.close'
  266. submitDisabled = { true }
  267. titleKey = 'info.label'
  268. width = 'small'>
  269. { inlineDialog }
  270. </Dialog>
  271. );
  272. }
  273. /**
  274. * Creates a message describing how to dial in to the conference.
  275. *
  276. * @private
  277. * @returns {string}
  278. */
  279. _getTextToCopy() {
  280. const { _localParticipant, liveStreamViewURL, t } = this.props;
  281. const shouldDisplayDialIn = this._shouldDisplayDialIn();
  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) {
  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 (!this._shouldDisplayDialIn()) {
  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. /**
  505. * Returns whether or not dial-in related UI should be displayed.
  506. *
  507. * @private
  508. * @returns {boolean}
  509. */
  510. _shouldDisplayDialIn() {
  511. const { conferenceID, numbers, numbersEnabled } = this.props.dialIn;
  512. const { phoneNumber } = this.state;
  513. return Boolean(
  514. conferenceID
  515. && numbers
  516. && numbersEnabled
  517. && phoneNumber);
  518. }
  519. _setCopyElement: () => void;
  520. /**
  521. * Sets the internal reference to the DOM/HTML element backing the React
  522. * {@code Component} input.
  523. *
  524. * @param {HTMLInputElement} element - The DOM/HTML element for this
  525. * {@code Component}'s input.
  526. * @private
  527. * @returns {void}
  528. */
  529. _setCopyElement(element: Object) {
  530. this._copyElement = element;
  531. }
  532. _setCopyUrlElement: () => void;
  533. /**
  534. * Sets the internal reference to the DOM/HTML element backing the React
  535. * {@code Component} input.
  536. *
  537. * @param {HTMLInputElement} element - The DOM/HTML element for this
  538. * {@code Component}'s input.
  539. * @private
  540. * @returns {void}
  541. */
  542. _setCopyUrlElement(element: Object) {
  543. this._copyUrlElement = element;
  544. }
  545. }
  546. /**
  547. * Maps (parts of) the Redux state to the associated props for the
  548. * {@code InfoDialog} component.
  549. *
  550. * @param {Object} state - The Redux state.
  551. * @private
  552. * @returns {{
  553. * _canEditPassword: boolean,
  554. * _conference: Object,
  555. * _conferenceName: string,
  556. * _inviteURL: string,
  557. * _locationURL: string,
  558. * _locked: string,
  559. * _password: string
  560. * }}
  561. */
  562. function _mapStateToProps(state) {
  563. const {
  564. conference,
  565. locked,
  566. password,
  567. room
  568. } = state['features/base/conference'];
  569. return {
  570. _canEditPassword: isLocalParticipantModerator(state, state['features/base/config'].lockRoomGuestEnabled),
  571. _conference: conference,
  572. _conferenceName: room,
  573. _passwordNumberOfDigits: state['features/base/config'].roomPasswordNumberOfDigits,
  574. _inviteURL: getInviteURL(state),
  575. _localParticipant: getLocalParticipant(state),
  576. _locationURL: state['features/base/connection'].locationURL,
  577. _locked: locked,
  578. _password: password
  579. };
  580. }
  581. export default translate(connect(_mapStateToProps)(InfoDialog));