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.web.js 16KB

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