您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

InfoDialog.js 17KB

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