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

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