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

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