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

InfoDialog.js 17KB

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