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