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

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