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.js 18KB

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