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

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