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

WelcomePage.web.tsx 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { isMobileBrowser } from '../../base/environment/utils';
  4. import { translate, translateToHTML } from '../../base/i18n/functions';
  5. import Icon from '../../base/icons/components/Icon';
  6. import { IconWarning } from '../../base/icons/svg';
  7. import Watermarks from '../../base/react/components/web/Watermarks';
  8. import getUnsafeRoomText from '../../base/util/getUnsafeRoomText.web';
  9. import CalendarList from '../../calendar-sync/components/CalendarList.web';
  10. import RecentList from '../../recent-list/components/RecentList.web';
  11. import SettingsButton from '../../settings/components/web/SettingsButton';
  12. import { SETTINGS_TABS } from '../../settings/constants';
  13. import { AbstractWelcomePage, IProps, _mapStateToProps } from './AbstractWelcomePage';
  14. import Tabs from './Tabs';
  15. /**
  16. * The pattern used to validate room name.
  17. *
  18. * @type {string}
  19. */
  20. export const ROOM_NAME_VALIDATE_PATTERN_STR = '^[^?&:\u0022\u0027%#]+$';
  21. /**
  22. * The Web container rendering the welcome page.
  23. *
  24. * @augments AbstractWelcomePage
  25. */
  26. class WelcomePage extends AbstractWelcomePage<IProps> {
  27. _additionalContentRef: HTMLDivElement | null;
  28. _additionalToolbarContentRef: HTMLDivElement | null;
  29. _additionalCardRef: HTMLDivElement | null;
  30. _roomInputRef: HTMLInputElement | null;
  31. _additionalCardTemplate: HTMLTemplateElement | null;
  32. _additionalContentTemplate: HTMLTemplateElement | null;
  33. _additionalToolbarContentTemplate: HTMLTemplateElement | null;
  34. /**
  35. * Default values for {@code WelcomePage} component's properties.
  36. *
  37. * @static
  38. */
  39. static defaultProps = {
  40. _room: ''
  41. };
  42. /**
  43. * Initializes a new WelcomePage instance.
  44. *
  45. * @param {Object} props - The read-only properties with which the new
  46. * instance is to be initialized.
  47. */
  48. constructor(props: IProps) {
  49. super(props);
  50. this.state = {
  51. ...this.state,
  52. generateRoomNames:
  53. interfaceConfig.GENERATE_ROOMNAMES_ON_WELCOME_PAGE
  54. };
  55. /**
  56. * The HTML Element used as the container for additional content. Used
  57. * for directly appending the additional content template to the dom.
  58. *
  59. * @private
  60. * @type {HTMLTemplateElement|null}
  61. */
  62. this._additionalContentRef = null;
  63. this._roomInputRef = null;
  64. /**
  65. * The HTML Element used as the container for additional toolbar content. Used
  66. * for directly appending the additional content template to the dom.
  67. *
  68. * @private
  69. * @type {HTMLTemplateElement|null}
  70. */
  71. this._additionalToolbarContentRef = null;
  72. this._additionalCardRef = null;
  73. /**
  74. * The template to use as the additional card displayed near the main one.
  75. *
  76. * @private
  77. * @type {HTMLTemplateElement|null}
  78. */
  79. this._additionalCardTemplate = document.getElementById(
  80. 'welcome-page-additional-card-template') as HTMLTemplateElement;
  81. /**
  82. * The template to use as the main content for the welcome page. If
  83. * not found then only the welcome page head will display.
  84. *
  85. * @private
  86. * @type {HTMLTemplateElement|null}
  87. */
  88. this._additionalContentTemplate = document.getElementById(
  89. 'welcome-page-additional-content-template') as HTMLTemplateElement;
  90. /**
  91. * The template to use as the additional content for the welcome page header toolbar.
  92. * If not found then only the settings icon will be displayed.
  93. *
  94. * @private
  95. * @type {HTMLTemplateElement|null}
  96. */
  97. this._additionalToolbarContentTemplate = document.getElementById(
  98. 'settings-toolbar-additional-content-template'
  99. ) as HTMLTemplateElement;
  100. // Bind event handlers so they are only bound once per instance.
  101. this._onFormSubmit = this._onFormSubmit.bind(this);
  102. this._onRoomChange = this._onRoomChange.bind(this);
  103. this._setAdditionalCardRef = this._setAdditionalCardRef.bind(this);
  104. this._setAdditionalContentRef
  105. = this._setAdditionalContentRef.bind(this);
  106. this._setRoomInputRef = this._setRoomInputRef.bind(this);
  107. this._setAdditionalToolbarContentRef
  108. = this._setAdditionalToolbarContentRef.bind(this);
  109. this._renderFooter = this._renderFooter.bind(this);
  110. }
  111. /**
  112. * Implements React's {@link Component#componentDidMount()}. Invoked
  113. * immediately after this component is mounted.
  114. *
  115. * @inheritdoc
  116. * @returns {void}
  117. */
  118. componentDidMount() {
  119. super.componentDidMount();
  120. document.body.classList.add('welcome-page');
  121. document.title = interfaceConfig.APP_NAME;
  122. if (this.state.generateRoomNames) {
  123. this._updateRoomName();
  124. }
  125. if (this._shouldShowAdditionalContent()) {
  126. this._additionalContentRef?.appendChild(
  127. this._additionalContentTemplate?.content.cloneNode(true) as Node);
  128. }
  129. if (this._shouldShowAdditionalToolbarContent()) {
  130. this._additionalToolbarContentRef?.appendChild(
  131. this._additionalToolbarContentTemplate?.content.cloneNode(true) as Node
  132. );
  133. }
  134. if (this._shouldShowAdditionalCard()) {
  135. this._additionalCardRef?.appendChild(
  136. this._additionalCardTemplate?.content.cloneNode(true) as Node
  137. );
  138. }
  139. }
  140. /**
  141. * Removes the classname used for custom styling of the welcome page.
  142. *
  143. * @inheritdoc
  144. * @returns {void}
  145. */
  146. componentWillUnmount() {
  147. super.componentWillUnmount();
  148. document.body.classList.remove('welcome-page');
  149. }
  150. /**
  151. * Implements React's {@link Component#render()}.
  152. *
  153. * @inheritdoc
  154. * @returns {ReactElement|null}
  155. */
  156. render() {
  157. const { _moderatedRoomServiceUrl, t } = this.props;
  158. const { DEFAULT_WELCOME_PAGE_LOGO_URL, DISPLAY_WELCOME_FOOTER } = interfaceConfig;
  159. const showAdditionalCard = this._shouldShowAdditionalCard();
  160. const showAdditionalContent = this._shouldShowAdditionalContent();
  161. const showAdditionalToolbarContent = this._shouldShowAdditionalToolbarContent();
  162. const contentClassName = showAdditionalContent ? 'with-content' : 'without-content';
  163. const footerClassName = DISPLAY_WELCOME_FOOTER ? 'with-footer' : 'without-footer';
  164. return (
  165. <div
  166. className = { `welcome ${contentClassName} ${footerClassName}` }
  167. id = 'welcome_page'>
  168. <div className = 'header'>
  169. <div className = 'header-image' />
  170. <div className = 'header-container'>
  171. <div className = 'header-watermark-container'>
  172. <div className = 'welcome-watermark'>
  173. <Watermarks
  174. defaultJitsiLogoURL = { DEFAULT_WELCOME_PAGE_LOGO_URL }
  175. noMargins = { true } />
  176. </div>
  177. </div>
  178. <div className = 'welcome-page-settings'>
  179. <SettingsButton
  180. defaultTab = { SETTINGS_TABS.CALENDAR }
  181. isDisplayedOnWelcomePage = { true } />
  182. { showAdditionalToolbarContent
  183. ? <div
  184. className = 'settings-toolbar-content'
  185. ref = { this._setAdditionalToolbarContentRef } />
  186. : null
  187. }
  188. </div>
  189. <h1 className = 'header-text-title'>
  190. { t('welcomepage.headerTitle') }
  191. </h1>
  192. <span className = 'header-text-subtitle'>
  193. { t('welcomepage.headerSubtitle')}
  194. </span>
  195. <div id = 'enter_room'>
  196. <div className = 'join-meeting-container'>
  197. <div className = 'enter-room-input-container'>
  198. <form onSubmit = { this._onFormSubmit }>
  199. <input
  200. aria-disabled = 'false'
  201. aria-label = 'Meeting name input'
  202. autoFocus = { true }
  203. className = 'enter-room-input'
  204. id = 'enter_room_field'
  205. onChange = { this._onRoomChange }
  206. pattern = { ROOM_NAME_VALIDATE_PATTERN_STR }
  207. placeholder = { this.state.roomPlaceholder }
  208. ref = { this._setRoomInputRef }
  209. title = { t('welcomepage.roomNameAllowedChars') }
  210. type = 'text'
  211. value = { this.state.room } />
  212. </form>
  213. </div>
  214. <button
  215. aria-disabled = 'false'
  216. aria-label = 'Start meeting'
  217. className = 'welcome-page-button'
  218. id = 'enter_room_button'
  219. onClick = { this._onFormSubmit }
  220. tabIndex = { 0 }
  221. type = 'button'>
  222. { t('welcomepage.startMeeting') }
  223. </button>
  224. </div>
  225. </div>
  226. { this._renderInsecureRoomNameWarning() }
  227. { _moderatedRoomServiceUrl && (
  228. <div id = 'moderated-meetings'>
  229. {
  230. translateToHTML(
  231. t, 'welcomepage.moderatedMessage', { url: _moderatedRoomServiceUrl })
  232. }
  233. </div>)}
  234. </div>
  235. </div>
  236. <div className = 'welcome-cards-container'>
  237. <div className = 'welcome-card-column'>
  238. <div className = 'welcome-tabs welcome-card welcome-card--blue'>
  239. { this._renderTabs() }
  240. </div>
  241. { showAdditionalCard
  242. ? <div
  243. className = 'welcome-card welcome-card--dark'
  244. ref = { this._setAdditionalCardRef } />
  245. : null }
  246. </div>
  247. { showAdditionalContent
  248. ? <div
  249. className = 'welcome-page-content'
  250. ref = { this._setAdditionalContentRef } />
  251. : null }
  252. </div>
  253. { DISPLAY_WELCOME_FOOTER && this._renderFooter()}
  254. </div>
  255. );
  256. }
  257. /**
  258. * Renders the insecure room name warning.
  259. *
  260. * @inheritdoc
  261. */
  262. _doRenderInsecureRoomNameWarning() {
  263. return (
  264. <div className = 'insecure-room-name-warning'>
  265. <Icon src = { IconWarning } />
  266. <span>
  267. { getUnsafeRoomText(this.props.t, 'welcome') }
  268. </span>
  269. </div>
  270. );
  271. }
  272. /**
  273. * Prevents submission of the form and delegates join logic.
  274. *
  275. * @param {Event} event - The HTML Event which details the form submission.
  276. * @private
  277. * @returns {void}
  278. */
  279. _onFormSubmit(event: React.FormEvent) {
  280. event.preventDefault();
  281. if (!this._roomInputRef || this._roomInputRef.reportValidity()) {
  282. this._onJoin();
  283. }
  284. }
  285. /**
  286. * Overrides the super to account for the differences in the argument types
  287. * provided by HTML and React Native text inputs.
  288. *
  289. * @inheritdoc
  290. * @override
  291. * @param {Event} event - The (HTML) Event which details the change such as
  292. * the EventTarget.
  293. * @protected
  294. */
  295. // @ts-ignore
  296. // eslint-disable-next-line require-jsdoc
  297. _onRoomChange(event: React.ChangeEvent<HTMLInputElement>) {
  298. super._onRoomChange(event.target.value);
  299. }
  300. /**
  301. * Renders the footer.
  302. *
  303. * @returns {ReactElement}
  304. */
  305. _renderFooter() {
  306. const {
  307. t,
  308. _deeplinkingCfg: {
  309. ios = { downloadLink: undefined },
  310. android = { fDroidUrl: undefined,
  311. downloadLink: undefined }
  312. }
  313. } = this.props;
  314. const { downloadLink: iosDownloadLink } = ios;
  315. const { fDroidUrl, downloadLink: androidDownloadLink } = android;
  316. return (<footer className = 'welcome-footer'>
  317. <div className = 'welcome-footer-centered'>
  318. <div className = 'welcome-footer-padded'>
  319. <div className = 'welcome-footer-row-block welcome-footer--row-1'>
  320. <div className = 'welcome-footer-row-1-text'>{t('welcomepage.jitsiOnMobile')}</div>
  321. <a
  322. className = 'welcome-badge'
  323. href = { iosDownloadLink }>
  324. <img
  325. alt = { t('welcomepage.mobileDownLoadLinkIos') }
  326. src = './images/app-store-badge.png' />
  327. </a>
  328. <a
  329. className = 'welcome-badge'
  330. href = { androidDownloadLink }>
  331. <img
  332. alt = { t('welcomepage.mobileDownLoadLinkAndroid') }
  333. src = './images/google-play-badge.png' />
  334. </a>
  335. <a
  336. className = 'welcome-badge'
  337. href = { fDroidUrl }>
  338. <img
  339. alt = { t('welcomepage.mobileDownLoadLinkFDroid') }
  340. src = './images/f-droid-badge.png' />
  341. </a>
  342. </div>
  343. </div>
  344. </div>
  345. </footer>);
  346. }
  347. /**
  348. * Renders tabs to show previous meetings and upcoming calendar events. The
  349. * tabs are purposefully hidden on mobile browsers.
  350. *
  351. * @returns {ReactElement|null}
  352. */
  353. _renderTabs() {
  354. if (isMobileBrowser()) {
  355. return null;
  356. }
  357. const { _calendarEnabled, _recentListEnabled, t } = this.props;
  358. const tabs = [];
  359. if (_calendarEnabled) {
  360. tabs.push({
  361. id: 'calendar',
  362. label: t('welcomepage.upcomingMeetings'),
  363. content: <CalendarList />
  364. });
  365. }
  366. if (_recentListEnabled) {
  367. tabs.push({
  368. id: 'recent',
  369. label: t('welcomepage.recentMeetings'),
  370. content: <RecentList />
  371. });
  372. }
  373. if (tabs.length === 0) {
  374. return null;
  375. }
  376. return (
  377. <Tabs
  378. accessibilityLabel = { t('welcomepage.meetingsAccessibilityLabel') }
  379. tabs = { tabs } />
  380. );
  381. }
  382. /**
  383. * Sets the internal reference to the HTMLDivElement used to hold the
  384. * additional card shown near the tabs card.
  385. *
  386. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  387. * of the welcome page content.
  388. * @private
  389. * @returns {void}
  390. */
  391. _setAdditionalCardRef(el: HTMLDivElement) {
  392. this._additionalCardRef = el;
  393. }
  394. /**
  395. * Sets the internal reference to the HTMLDivElement used to hold the
  396. * welcome page content.
  397. *
  398. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  399. * of the welcome page content.
  400. * @private
  401. * @returns {void}
  402. */
  403. _setAdditionalContentRef(el: HTMLDivElement) {
  404. this._additionalContentRef = el;
  405. }
  406. /**
  407. * Sets the internal reference to the HTMLDivElement used to hold the
  408. * toolbar additional content.
  409. *
  410. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  411. * of the additional toolbar content.
  412. * @private
  413. * @returns {void}
  414. */
  415. _setAdditionalToolbarContentRef(el: HTMLDivElement) {
  416. this._additionalToolbarContentRef = el;
  417. }
  418. /**
  419. * Sets the internal reference to the HTMLInputElement used to hold the
  420. * welcome page input room element.
  421. *
  422. * @param {HTMLInputElement} el - The HTMLElement for the input of the room name on the welcome page.
  423. * @private
  424. * @returns {void}
  425. */
  426. _setRoomInputRef(el: HTMLInputElement) {
  427. this._roomInputRef = el;
  428. }
  429. /**
  430. * Returns whether or not an additional card should be displayed near the tabs.
  431. *
  432. * @private
  433. * @returns {boolean}
  434. */
  435. _shouldShowAdditionalCard() {
  436. return interfaceConfig.DISPLAY_WELCOME_PAGE_ADDITIONAL_CARD
  437. && this._additionalCardTemplate
  438. && this._additionalCardTemplate.content
  439. && this._additionalCardTemplate.innerHTML.trim();
  440. }
  441. /**
  442. * Returns whether or not additional content should be displayed below
  443. * the welcome page's header for entering a room name.
  444. *
  445. * @private
  446. * @returns {boolean}
  447. */
  448. _shouldShowAdditionalContent() {
  449. return interfaceConfig.DISPLAY_WELCOME_PAGE_CONTENT
  450. && this._additionalContentTemplate
  451. && this._additionalContentTemplate.content
  452. && this._additionalContentTemplate.innerHTML.trim();
  453. }
  454. /**
  455. * Returns whether or not additional content should be displayed inside
  456. * the header toolbar.
  457. *
  458. * @private
  459. * @returns {boolean}
  460. */
  461. _shouldShowAdditionalToolbarContent() {
  462. return interfaceConfig.DISPLAY_WELCOME_PAGE_TOOLBAR_ADDITIONAL_CONTENT
  463. && this._additionalToolbarContentTemplate
  464. && this._additionalToolbarContentTemplate.content
  465. && this._additionalToolbarContentTemplate.innerHTML.trim();
  466. }
  467. }
  468. export default translate(connect(_mapStateToProps)(WelcomePage));