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

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