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

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