You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WelcomePage.web.tsx 19KB

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