Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

InfoDialog.web.js 16KB

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