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 17KB

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