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

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