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

InfoDialog.web.js 16KB

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